1 IDIR =../include 2 CC=gcc 3 CFLAGS=-I$(IDIR) 4 5 ODIR=obj 6 LDIR =../lib 7 8 LIBS=-lm 9 10 _DEPS = hellomake.h 11 DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS)) 12 13 _OBJ = hellomake.o hellofunc.o 14 OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ)) 15 16 17 $(ODIR)/%.o: %.c $(DEPS) 18 $(CC) -c -o $@ $< $(CFLAGS) 19 20 hellomake: $(OBJ) 21 gcc -o $@ $^ $(CFLAGS) $(LIBS) 22 23 .PHONY: clean 24 25 clean: 26 rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~
参考:http://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
再来一个简单的模板
1 CC?=gcc 2 CFLAGS+= -g -Wall 3 LDFLAGS= 4 LIBS=-lpthread 5 6 test: bootstrap.o object.o test.o 7 $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) 8 9 %.o: %.c 10 $(CC) $(CFLAGS) -c -o $@ $^ 11 12 clean: 13 rm *.o test