本文共 842 字,大约阅读时间需要 2 分钟。
## 一般通用Makefile模板
CC = gccCXX = g++CFLAGS = -Wall -g -O2TARGET = myTestSRCDIR = .SOURCES = $(wildcard $(SRCDIR)/*.c $(SRCDIR)/*.cpp $(SRCDIR)/*.s)OBJS = $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCES)))LDFLAG = -lstdc++ -lpthreadINCLUDE = -I. -I../incEXTLIBS = -L./../../../lib/LOCAL/ -ltinyxmlifeq ($(SERVER),KONTRON)CFLAGS += -DKONTRON=1endififeq ($(PROJECT),SHENHANG)CFLAGS += -DSHENHANG=1endif%.o: %.c $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@%.o:%.cpp $(CXX) $(CFLAGS) $(INCLUDE) -c $< -o $@all : $(TARGET)$(TARGET) : $(OBJS) $(CC) $(OBJS) -o $@ $(LDFLAG) $(EXTLIBS) $(INCLUDE)clean: rm -f *.o $(TARGET)## 语句说明
1、SOURCES = $(wildcard $(SRCDIR)/*.c $(SRCDIR)/*.cpp $(SRCDIR)/*.s) 获取当前目录下的c、cpp、s的代码2、OBJS = $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCES))) 将*.c替换为*.o ,*.cpp替换为*.o的文件
转载地址:http://vcvbi.baihongyu.com/