除了列出的makefile的其他問題,該參數:.deps/../util/transfrom.Tpo
是不太可能是正確的。
它說:在子目錄.deps
(請注意.
) 升高一個目錄(即生成文件的位置)然後下降到util目錄。然後生成文件transfrom.Tpo
。
Hummm。也許這只是一個錯字,但我懷疑transform.Tpo
是錯誤的,因爲正在呈現的路徑。
但是,有趣的是(通常)每個源文件都有一個依賴文件,而不僅僅是一個依賴文件。通常最好將這些依賴文件命名爲與關聯源文件相同的根名稱,並使用唯一的擴展名,如.d
我建議在獨立的make文件規則中生成依賴文件,使用-M -MF <file name>.c
請勿使用-MP
,因爲這會導致gcc
爲每個文件創建一個目標並且不提供任何依賴關係。 http://tigcc.ticalc.org/doc/comopts.html#SEC3
以下是處理 生成依賴關係的補充文件(實際上是一個對生成文件的),編譯,在每個子目錄和主目錄鏈接:
gcc的參數細節,可以發現。他們使用sed
而不是gcc
來生成依賴文件,但上述信息將使您能夠調整該規則。
這是頂層makefile: 注:allDirectories
宏的子目錄, 這將必須調整你的子目錄
SHELL = /bin/sh
# note: this makefile.mak needs to be run from the ./src directory
# of the GOT4 directory tree
SRC := $(wildcard *.c)
OBJ := $(SRC:.c=.o)
DEP := $(SRC:.c=.d)
INC := $(SRC:.c=.h)
MAKE := /usr/bin/make
CC := /usr/bin/gcc
CP := cp
MV := mv
LDFLAGS := -L/usr/local/lib -L/usr/lib -L/lib
DEBUG := -ggdb3
CCFLAGS := $(DEBUG) -Wall -W
#CPPFLAGS += =MD
LIBS := -lssl -ldl -lrt -lz -lc -lm -lcrypto
.PHONY: AllDirectories
# the following statement needs to be edited as
# subdirectories are added/deleted/re-named
AllDirectories := \
CommandConfiguration \
Communication \
MainScheduler \
RetrieveCDSLog \
RetrieveEventRecorderLog \
RetrieveGPS \
QESRouter
.PHONY: all
#all: $(OBJ) $(AllDirectories)
# $(foreach d,$(AllDirectories), \
# (cd $d && $(MAKE) -f makefile.mak name=Tsk_$d all);)
all: $(OBJ) $(AllDirectories)
$(foreach d,$(AllDirectories), \
(cd $d && $(MAKE) -f ../makefile.bot name=Tsk_$d all);)
#
# create dependancy files
#
%.d: %.c
#
# ========= START $< TO [email protected] =========
$(CC) -M $(CPPFLAGS) $< > [email protected]$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o [email protected] : ,g' < [email protected]$$$$ > [email protected]; \
rm -f [email protected]$$$$
# ========= END $< TO [email protected] =========
#
# compile the .c file into .o files using the compiler flags
#
%.o: %.c %.d
#
# ========= START $< TO [email protected] =========
$(CC) $(CCFLAGS) -c $< -o [email protected] -I.
# ========= END $< TO [email protected] =========
#
.PHONY: clean
#clean: $(AllDirectories)
# # ========== start clean activities ==========
# rm -f *.o
# rm -f $(name).map
# rm -f $(name)
# rm -f *.d
# $(foreach d,$(AllDirectories), \
# (cd $d && $(MAKE) -f makefile.mak clean);)
# # ========== end clean activities ==========
clean: $(AllDirectories)
# ========== start clean activities ==========
rm -f *.o
rm -f $(name).map
rm -f $(name)
rm -f *.d
rm -f ../bin/Tsk_*
$(foreach d,$(AllDirectories), \
(cd $d && $(MAKE) -f ../makefile.bot name=Tsk_$d clean);)
# ========== end clean activities ==========
.PHONY: install
#install: $(AllDirectories)
# # ========== start install activities ==========
# $(foreach d,$(AllDirectories), \
# (cd $d && $(MAKE) -f makefile.mak clean);)
# # ========== end install activities ==========
install: $(AllDirectories)
# ========== start install activities ==========
$(foreach d,$(AllDirectories), \
(cd $d && $(MAKE) -f ../makefile.bot name=Tsk_$d install);)
# ========== end install activities ==========
# include the contents of all the .d files
# note: the .d files contain:
# <filename>.o:<filename>.c plus all the dependancies for that file
# I.E. the #include'd header files
# wrap with ifneg... so will not rebuild *.d files when goal is 'clean'
#
ifneq "$(MAKECMDGOALS)" "clean"
-include $(DEP)
endif
這個名單列表是生成文件進入每個子目錄。
SHELL = /bin/sh
BINDIR := /home/user/bin
.PHONY: all
all : $(BINDIR)/$(name) ../makefile.mak ../makefile.bot
#
# macro of all *.c files
# (NOTE:
# (the following 'wildcard' will pick up ALL .c files
# (like FileHeader.c and FunctionHeader.c
# (which should not be part of the build
# (so be sure no unwanted .c files in directory
# (or change the extension
#
SRC := $(wildcard *.c)
OBJ := $(SRC:.c=.o)
DEP := $(SRC:.c=.d)
INC := $(SRC:.c=.h)
COMMON_OBJ := $(wildcard ../*.o)
#COMMON_SRC := $(wildcard ../*.c)
#COMMON_OBJ := $(COMMON_SRC:.c=.o)
#COMMON_DEP := $(COMMON_SRC:.c=.d)
#COMMON_INC := $(COMMON_SRC:.c=.h)
MAKE := /usr/bin/make
CC := /usr/bin/gcc
CP := cp -f
MV := mv
LDFLAGS := -L/usr/local/lib
DEBUG := -ggdb3
CCFLAGS := $(DEBUG) -Wall -W
#CPPFLAGS += =MD
#LIBS := -lidn -lssl -ldl -lrt -lz -lc -lm
LIBS := -lssl -ldl -lrt -lz -lc -lm -lcrypto
#
# link the .o files into the executable
# using the linker flags
# -- explicit rule
#
$(name): $(OBJ) $(COMMON_OBJ) ../makefile.mak ../makefile.bot
#
# ======= $(name) Link Start =========
$(CC) $(LDFLAGS) -o [email protected] $(OBJ) $(COMMON_OBJ) $(LIBS)
# ======= $(name) Link Done ==========
#
# note:
# using MV rather than CP results in all executables being re-made everytime
$(BINDIR)/$(name): $(name)
#
# ======= $(name) Copy Start =========
$(CP) $(name) $(BINDIR)/
# ======= $(name) Copy Done ==========
#
#
#create dependancy files -- inference rule
# list makefile.mak as dependancy so changing makfile forces rebuild
#
%.d: %.c
#
# ========= START $< TO [email protected] =========
$(CC) -M $(CPPFLAGS) $< > [email protected]$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o [email protected] : ,g' < [email protected]$$$$ > [email protected]; \
rm -f [email protected]$$$$
# ========= END $< TO [email protected] =========
#
# compile the .c file into .o files using the compiler flags
# -- inference rule
#
%.o: %.c %.d
#
# ========= START $< TO [email protected] =========
$(CC) $(CCFLAGS) -c $< -o [email protected] -I.
# ========= END $< TO [email protected] =========
#
.PHONY: clean
clean:
# ========== CLEANING UP ==========
rm -f *.o
rm -f $(name).map
rm -f $(name)
rm -f *.d
# ========== DONE ==========
.PHONY: install
install: all
# include the contents of all the .d files
# note: the .d files contain:
# <filename>.o:<filename>.c plus all the dependencies for that .c file
# I.E. the #include'd header files
# wrap with ifneg... so will not rebuild *.d files when goal is 'clean'
#
ifneq "$(MAKECMDGOALS)" "clean"
-include $(DEP)
endif