From Electron Cloud
Jump to: navigation, search
 
 
(5 intermediate revisions by 2 users not shown)
Line 11: Line 11:
  
 
$(TARGET): .depend $(OBJECTS)
 
$(TARGET): .depend $(OBJECTS)
 +
        echo "#define BUILD_HOST \"`hostname -f`\"" > build_host.h
 
         $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(LIBPATH) $(LIBS)
 
         $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(LIBPATH) $(LIBS)
 
         $(STRIP) $(TARGET)
 
         $(STRIP) $(TARGET)
  
 
.c.o: $*.h common.h
 
.c.o: $*.h common.h
        echo ".h $*.h"
 
 
         $(CC) -c $(CFLAGS) $(DEBUGFLAGS) $(INCPATH) -o $@ $<
 
         $(CC) -c $(CFLAGS) $(DEBUGFLAGS) $(INCPATH) -o $@ $<
  
 
-include .depend
 
-include .depend
  
version.h:
+
build_host.h:
         echo "#define BUILD_DATE \"`/bin/date \"+%d %b %Y\"`\"" > version.h
+
         echo "#define BUILD_HOST \"`hostname -f`\"" > build_host.h
  
 
clean:
 
clean:
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>
 +
 +
How to do arbitrary conversions with implicit rules:
 +
<pre>
 +
LOGS = $(wildcard *.log)
 +
LOGPDFS = $(subst .log$,.pdf,$(LOGS))
 +
 +
all: $(LOGPDFS)
 +
 +
%.pdf : %.log
 +
        process-log $<
 +
        mv output.pdf $@
 
</pre>
 
</pre>

Latest revision as of 21:01, 21 April 2009

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);
}

How to do arbitrary conversions with implicit rules:

LOGS = $(wildcard *.log)
LOGPDFS = $(subst .log$,.pdf,$(LOGS))

all: $(LOGPDFS)

%.pdf : %.log
        process-log $<
        mv output.pdf $@