makefile - Generate debug versions of targets in a DRY method -


i using gnumake , have makefile targets defined , respective dependencies. create debug version of these targets, have this:

target := b c  all: $(target)  a: a.o e.o     $(cc) $(cflags) $(incdirs) -c $(^) -o $(@)  b: b.o g.o     $(cc) $(cflags) $(incdirs) -c $(^) -o $(@) -pthread  c: f.o c.o     $(cc) $(cflags) $(incdirs) -lm -c $(^) -o $(@)  %.o:    %.c     $(cc) $(cflags) $(incdirs) -c $(^) -o $(@) 

so good, create debug versions of these rules, don't want have rewrite rules. want add additional flags -g -ddebug cflags variable , change names of targets.

i tried static rule stuff

$(target:%=debug_%):    %: * #<--- not sure how specify dependencies # cflags += -g -ddebug <-- uncommenting line error 

this didn't work. wanted above rule match targets specified, add additional parameters cflags generate files debug_a, debug_b, debug_c etc. not sure if possible make way reasoning this.

any appreciated,

so found suitable solution:

debug_target := $(target:%=debug_%)  debug: $(debug_target)  $(debug_target): debug_%: cflags += -g -ddebug debug_%: %     @mv $* debug_$* 

this generate debug version of each target without having create separate rules.

the last line sweet spot me , accomplishes wanted without having repeat myself much


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -