REVISED makefile structure for multi-part source files

Robert P. J. Day rpjday at mindspring.com
Thu May 11 16:25:02 UTC 2006


#
#  Macro to extract the "subparts" of a given multi-part source file.
#

get-file-subparts = $(shell sed -n -e "s/^\#ifdef L_//p" ${1})

#
#  Lists of the multi-part source files and the corresponding "sub-parts."
# Note that the last two of the variables below are superfluous for the
# normal build -- I just threw them in so I could define the phony
# "allobjs" target for testing.
#

MULTISRCS := $(shell grep -l "^\#ifdef L_" $(wildcard *.c))
MULTISUBPARTS := $(foreach msrc,${MULTISRCS},$(call get-file-subparts,${msrc}))
MULTIOBJS := $(addsuffix .o,${MULTISUBPARTS})

#
#  For a given source file, generate a list of the corresponding
# object files.
#

gen-objs = $(addsuffix .o, $(call get-file-subparts,${1}))

#
#  Define the rule that rebuilds a set of object files from a
# multi-part source file.
#

define objrule
$(call gen-objs, ${1}): ${1}
	@echo CC $$< -DL_$$* -o $$@	# replace with real command
endef

$(foreach src,${MULTISRCS},$(eval $(call objrule,${src})))

.PHONY: allobjs
allobjs: ${MULTIOBJS}




rday

P.S.  as with the previous submission, you can just dump this makefile
into libbb, and invoke it with the "allobjs" target to see what would
happen.



More information about the busybox mailing list