scons虽然简单且跨平台,但内部隐藏了太多细节。Make相对清爽些。
然而每次都写makefile有点嫌麻烦,网络上也流传很多通用makefile。今天特找来一个,分享之
######################################
# Copyright (c) 1997 George Foot (george.foot@merton.ox.ac.uk)
# All rights reserved.
######################################
DESTINATION := # 可执行输出对象
LIBS :=
INCLUDES := .
RM := del
# GNU Make的隐含变量定义
CC = g++
CPPFLAGS = -g -Wall
CPPFLAGS += $(addprefix -I,$(INCLUDES))
CPPFLAGS += -MMD
# 带空格的包含目录
CPPFLAGS += #-Id:\Program\ Files\boost_1_40_0
#以下部分无需修改
SOURCE := $(wildcard *.c) $(wildcard *.cpp)
OBJS := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE)))
DEPS := $(patsubst %.o,%.d,$(OBJS))
MISSING_DEPS := $(filter-out $(wildcard $(DEPS)),$(DEPS))
MISSING_DEPS_SOURCES := $(wildcard $(patsubst %.d,%.$(PS),$(MISSING_DEPS)))
.PHONY : all deps objs clean rebuild
all : $(DESTINATION)
deps : $(DEPS)
$(CC) -MM -MMD $(SOURCE)
objs : $(OBJS)
clean :
@$(RM) *.o
@$(RM) *.d
@$(RM) $(DESTINATION)
rebuild: clean all
ifneq ($(MISSING_DEPS),)
$(MISSING_DEPS) :
@$(RM) $(patsubst %.d,%.o,$@)
endif
-include $(DEPS)
$(DESTINATION) : $(OBJS)
$(CC) -o $(DESTINATION) $(OBJS) $(addprefix -l,$(LIBS))
简单的Hello world之类的只需要填写DESTNATION即可。可应付大部分情况。