makefile - how to link the objects in all subdirectory togother? -
i'm writing makefile framework project. say, have main.c in top dir, , many subdirs each containing c file. link object files togoter, assign initial value in top makefile:
export target_list := main.o and in each subdirs, append them list:
# sub1/makefile target := a.o target_list += $(target) when return top dir, target_list still main.o. i'm sure subdirs entered. there way this?
the top makefile:
all: main export top_dir = $(shell pwd) export target_list := main.o subdirs := b c d cflags := -iinc all:main main:main.o subdirs cc $(target_list) -o $@ $(cflags) subdirs: $(patsubst %, _dir_%, $(subdirs)) $(patsubst %, _dir_%, $(subdirs)) : $(make) -c $(patsubst _dir_%, %, $@) $(tgt) the rules.make:
all:$(target) %.o:%.c @echo $(target_list) $(cc) -c $^ -o $@ $(cflags) $(ldflags) the subdir makefile:
target := a.o target_list += $(target) cflags := ldflags := include $(top_dir)/rules.make
do favour, , use high-level build system if can. better hand-written makefiles. e.g. cmake, scons or waf of more popular alternatives.
Comments
Post a Comment