From Electron Cloud
(generates build_host.h) |
|||
Line 37: | Line 37: | ||
test: | test: | ||
echo $(OBJECTS) | echo $(OBJECTS) | ||
+ | </pre> | ||
+ | |||
+ | How to use build_host.h and generate a version message: | ||
+ | |||
+ | <pre> | ||
+ | #include "build_host.h" // created by Makefile | ||
+ | |||
+ | void print_version() | ||
+ | { | ||
+ | printf("This is Thingamajig version " VERSION | ||
+ | " built " __DATE__ " " __TIME__ " on " BUILD_HOST); | ||
+ | } | ||
</pre> | </pre> |
Revision as of 13:20, 23 July 2008
This is just a basic starting point for compiling a C project.
TARGET = theapp SOURCES = $(wildcard *.c) OBJECTS = $(subst .c$,.o,$(SOURCES)) HEADERS = $(wildcard *.h) CC = gcc LINK = gcc STRIP = strip $(TARGET): .depend $(OBJECTS) echo "#define BUILD_HOST \"`hostname -f`\"" > build_host.h $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(LIBPATH) $(LIBS) $(STRIP) $(TARGET) .c.o: $*.h common.h $(CC) -c $(CFLAGS) $(DEBUGFLAGS) $(INCPATH) -o $@ $< -include .depend build_host.h: echo "#define BUILD_HOST \"`hostname -f`\"" > build_host.h clean: -rm -f .depend -rm -f $(OBJECTS) -rm -f *~ core *.core -rm -f version.h -rm -f $(TARGET) depend: .depend: Makefile $(SOURCES) $(HEADERS) @if [ ! -f .depend ]; then touch .depend; fi @makedepend -Y -f .depend $(SOURCES) 2>/dev/null test: echo $(OBJECTS)
How to use build_host.h and generate a version message:
#include "build_host.h" // created by Makefile void print_version() { printf("This is Thingamajig version " VERSION " built " __DATE__ " " __TIME__ " on " BUILD_HOST); }