handling "multi-part" source files

Robert P. J. Day rpjday at mindspring.com
Wed May 10 13:03:21 PDT 2006


  a sample makefile you can drop into libbb and just run with

$ make -f <filename> allobjs

to see how it would handle compiling multi-part source files.

rday

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

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

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 the corresponding object files.
#

gen-objs = $(addsuffix .o, \
	$(shell grep -h "^\#ifdef L_" ${1} | sed -e "s/^\#ifdef L_//"))

#
#  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}


More information about the busybox mailing list