$(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)
$(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
##################
.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)
--- /dev/null
+
+# 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
+