From: Leandro Lucarella Date: Mon, 21 Sep 2009 16:34:37 +0000 (-0300) Subject: Add a function to include sub-directory's Build.mak X-Git-Url: https://git.llucax.com/software/makeit.git/commitdiff_plain/9296c29f3d6486381d7df1fc5bcac8da21cc7b0d?ds=inline;hp=bd1e098b0726f0ffdca3bea2937fada9dbabd9b4 Add a function to include sub-directory's Build.mak Including a Build.mak in a sub-directory can be very error prone, since the $S variable should be set to the relative path from $T before including the Build.mak and restored afterwards. The function include_subdirs is added to simplify this task, freeing the user from doing all the dirty work and avoiding bugs. The "otherproj" pkg-config file generation is moved to a subdirectory to test how the new function works with deeply nested Build.mak. --- diff --git a/Build.mak b/Build.mak index a0a4458..96bbecb 100644 --- a/Build.mak +++ b/Build.mak @@ -7,16 +7,5 @@ $I/include/makeit/%.h: $T/%.h $(call install_file) # Include sub-directories makefiles - -S := subproj -include $T/$S/Build.mak - -S := lib1 -include $T/$S/Build.mak - -S := lib2 -include $T/$S/Build.mak - -S := prog -include $T/$S/Build.mak +$(call include_subdirs,subproj lib1 lib2 prog) diff --git a/Lib.mak b/Lib.mak index db8ffd5..bddc5e1 100644 --- a/Lib.mak +++ b/Lib.mak @@ -211,6 +211,18 @@ gen_rebuild_flags = $(shell if test x"$2" != x"`cat $1 2>/dev/null`"; then \ $(if $3,test -f $1 && echo "$3";) \ echo "$2" > $1 ; fi) +# Include sub-directory's Build.mak. The only argument is a list of +# subdirectories for which Build.mak should be included. The $S directory is +# set properly before including each sub-directory's Build.mak and restored +# afterwards. +define build_subdir_code +_parent__$d__dir_ := $$S +S := $$(if $$(_parent__$d__dir_),$$(_parent__$d__dir_)/$d,$d) +include $$T/$$S/Build.mak +S := $$(_parent__$d__dir_) +endef +include_subdirs = $(foreach d,$1,$(eval $(build_subdir_code))) + # Overridden flags ################## diff --git a/subproj/Build.mak b/subproj/Build.mak index b76101c..12ef4d7 100644 --- a/subproj/Build.mak +++ b/subproj/Build.mak @@ -3,24 +3,10 @@ .PHONY: otherproj all += otherproj -# pkg-config specification file -otherproj-PC-PREFIX := $(prefix) -otherproj-PC-NAME := otherproj -otherproj-PC-DESC := Some other project -otherproj-PC-URL := http://www.otherproj.example.com/ -otherproj-PC-VERSION := 1.0 -otherproj-PC-LIBS := -lotherproject -otherproj-PC-CFLAGS := -DOTHERPROJ_DEFINE -otherproj-PC-VARS := PREFIX NAME DESC URL VERSION LIBS CFLAGS -$L/otherproj.pc: PC_VARS := $(otherproj-PC-VARS) -$L/otherproj.pc: $C/otherproj.pc.in $L/otherproj.pc-flags -# trigger a rebuild when flags change -setup_flags_files__ := $(call gen_rebuild_flags,$L/otherproj.pc-flags,\ - $(call varcat,$(otherproj-PC-VARS),otherproj-PC-)) -# install -$I/lib/pkgconfig/otherproj.pc: $L/otherproj.pc -install += $I/lib/pkgconfig/otherproj.pc -otherproj: $L/otherproj.pc +# Include subdirectory to make the pkg-config stuff (it doesn't make much sense +# to have this in a separated directory, it's just to test very nested +# subdirectories :) +$(call include_subdirs,pkg-config) # Shared library $L/libotherproj.so: LINKER := $(CC) diff --git a/subproj/pkg-config/Build.mak b/subproj/pkg-config/Build.mak new file mode 100644 index 0000000..be1b4df --- /dev/null +++ b/subproj/pkg-config/Build.mak @@ -0,0 +1,24 @@ + +# Symbolic target to add to all +.PHONY: otherproj-pc +all += otherproj-pc + +# pkg-config specification file +otherproj-PC-PREFIX := $(prefix) +otherproj-PC-NAME := otherproj +otherproj-PC-DESC := Some other project +otherproj-PC-URL := http://www.otherproj.example.com/ +otherproj-PC-VERSION := 1.0 +otherproj-PC-LIBS := -lotherproject +otherproj-PC-CFLAGS := -DOTHERPROJ_DEFINE +otherproj-PC-VARS := PREFIX NAME DESC URL VERSION LIBS CFLAGS +$L/otherproj.pc: PC_VARS := $(otherproj-PC-VARS) +$L/otherproj.pc: $C/otherproj.pc.in $L/otherproj.pc-flags +# trigger a rebuild when flags change +setup_flags_files__ := $(call gen_rebuild_flags,$L/otherproj.pc-flags,\ + $(call varcat,$(otherproj-PC-VARS),otherproj-PC-)) +# install +$I/lib/pkgconfig/otherproj.pc: $L/otherproj.pc +install += $I/lib/pkgconfig/otherproj.pc +otherproj: $L/otherproj.pc + diff --git a/subproj/otherproj.pc.in b/subproj/pkg-config/otherproj.pc.in similarity index 100% rename from subproj/otherproj.pc.in rename to subproj/pkg-config/otherproj.pc.in