makefile - Generic make rules using define -


i'm trying create common template generate rules build set of test cases , place them in unique target locations have hit bit of snag define directive. following relevant section of makefile:

root=../.. platform=akyboard_gcc  # include test cases current platform # add test_cases variable test_cases=a b a_files = a1.c a2.c b_files = b1.c b2.c  check: $(test_cases:%=check_%)  define check_template  # build artifact directories $(1)_blddir=$(root)/build/$(platform)/$(1) $(1)_objdir=$$($(1)_blddir)/obj $(1)_exedir=$$($(1)_blddir)/exe  # prepend src/ files part of test case $(1)_files := $($(1:%=%_files):%=src/%)  # add test runner 1 of files compiled $(1)_files += test_runner/$(platform)/main.c  # construct list of objects generated sources $(1)_obj = $($(1)_files:%.c=$$($(1)_objdir)/%.o)  # creates rule such check_{test_case}: check_$(1): $$($(1)_obj)     @echo 1 $(1)     @echo 2 $$($(1)_files)     @echo 3 $$($(1)_obj)     @echo 5 $$($(1)_objdir)     @echo 4 $$($(1)_blddir)     @echo 6 $$($(1)_exedir)  $$($(1)_objdir)/%.o: $(root)/%.c     @echo coconut  endef  $(foreach testcase, $(test_cases),              \     $(eval $(call check_template,$(testcase)))  \ ) 

issuing "make check" gives following error

*** no rule make target `../../build/akyboard_gcc/a/obj/a1.o', needed `check_a'.  stop. 

if manually create target rules below builds without errors

../../build/akyboard_gcc/a/obj/a1.o: ../../build/akyboard_gcc/a/obj/a2.o: ../../build/akyboard_gcc/b/obj/b1.o: ../../build/akyboard_gcc/b/obj/b2.o: 

but changing rules below causes build error:

../../build/akyboard_gcc/a/obj/%.o: 

would grateful help.

you can find wrong template replacing eval info call.

$(foreach testcase, $(test_cases), $(info $(call check_template,$(testcase)))) 

and your template fine. you have problem pattern rules.
gnu make manual:

a pattern rule can used build given file if there target pattern matches file name, , prerequisites in rule either exist or can built.

perhaps don't have required sources in $(root) directory. , make can't create rule object file pattern.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -