|
发表于 2004-7-20 11:02:05
|
显示全部楼层
给你个例子,自己看把,简单的说就是利用.d依赖文件.
### Customising
#
#
#Adjust the following if necessary; EXECUTABLE is the target
#executable's filename, and LIBS is a list of libraries to link in
#(e.g. alleg, stdcx, iostr, etc). You can override these on make's
#command line of course, if you prefer to do it that way.
#
CC := gcc
CLIBS :=
STDLIBS :=
STDLIBS := $(addprefix -l,$(STDLIBS))
RM-F := rm -f
EXECUTABLE := db
#Now alter any implicit rules' variables if you like
#
CFLAGS := -g -Wall -O3
TOPDIR := $(shell /bin/pwd)
INC = \
-I $(TOPDIR)/libnet
CFLAGS := $(CFLAGS) $(INC)
#You shouldn't need to change anything below this point.
#
SOURCE := $(wildcard *.c) $(wildcard *.cc)
OBJS := $(patsubst %.c,%.o,$(patsubst %.cc,%.o,$(SOURCE)))
DEPS := $(patsubst %.o,%.d,$(OBJS))
MISSING_DEPS := $(filter-out $(wildcard $(DEPS)),$(DEPS))
MISSING_DEPS_SOURCES := $(wildcard $(patsubst %.d,%.c,$(MISSING_DEPS)) $(patsubst %.d,%.cc,$(MISSING_DEPS)))
CPPFLAGS += -MD
.PHONY: everything deps objs clean veryclean rebuild
everything: $(EXECUTABLE)
deps: $(DEPS)
objs: $(OBJS)
clean: CMD := clean
clean: $(CLIBS)
@$(RM-F) *.o
@$(RM-F) *.d
veryclean: clean
@$(RM-F) $(EXECUTABLE)
rebuild: veryclean everything
force:
$(CLIBS): force
cd $(@D);$(MAKE) $(CMD)
ifneq ($(MISSING_DEPS),)
$(MISSING_DEPS) :
@$(RM-F) $(patsubst %.d,%.o,$@)
endif
-include $(DEPS)
$(EXECUTABLE) : $(OBJS) $(CLIBS)
$(CC) ${CFLAGS} $(OBJS) $(CLIBS) $(STDLIBS) -o $@ |
|