简单实例:
CC = gcc
CXX = g++
CFLAGS = -O -DDBG -D_REENTRANT -Wall -DUSE_PTHREAD -pthread
LDFLAGS = -ldl -lnsl -lm -lpthread
SRCS = $(wildcard *.cpp)
OBJS = $(patsubst %cpp, %o, $(SRCS)) //利用模式匹配生成.o文件
DATALIBS = dblib/lib.a
ZIPLIBS = ZipCoder/ZipCoder.a
TARGET = ../bin/excute test
all: $(TARGET)
../bin/excute : excute.o $(filter-out test.o,$(OBJS)) //消除生成多个可执行文件的影响,如果有更多个:$(filter-out $(test1.o,test2.o..),$(OBJS))
$(CXX) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(ZIPLIBS) $(DATALIBS)
test : test.o $(filter-out excute.o,$(OBJS))
$(CXX) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(ZIPLIBS) $(DATALIBS)
#$(ZIPLIBS): ZipCoder/Makefile ZipCoder/zlib/Makefile
#cd ZipCoder/zlib/; make; cd ..; make; cd ..;
%.o : %.c
$(CC) $(CFLAGS) -c $^ -o $@
%.o : %.cpp
$(CXX) $(CFLAGS) -c $^ -o $@
.PHONY : clean
clean :
rm -f *.o
rm -f ../bin/excute
# install:
# mv Excute excute; cp -f ordermisd ../bin/;
一个makefile学习地址:
http://www.cnblogs.com/wang_yb/p/3990952.html