# Standard symbols CC = gcc CCFLAGS = -fPIC -ggdb -Wall #CCFLAGS += -Wno-unused-variable -Wno-unused-function LDFLAGS = -L ../../miniade/lib # Custom symbols PLB_MEMBERS = plb pthreadwrapper tsk_pulse tsk_sink tsk_relay utils \ tsk_dot tsk_quittee model_pulse2sink model_human2quittee model_pulse2human \ model_dot2human model_human2sink model_human2human # Standard recipes default: compile compile: plb clean: $(RM) *.o plb *.gch # Custom recipes plb: $(patsubst %, %.o, $(PLB_MEMBERS)) $(CC) $(LDFLAGS) -o $@ $^ -l:libminiade.so.0 %.o: %.c @# We don't compile $^, but rather $(patsubst %.o, %.c, $@), in order @# to avoid adding *all* dependencies, which includes all the headers @# to the command line. Adding the headers is fine, but it results @# in gcc generating .gch files (compiled headers!) for each header. $(CC) $(CCFLAGS) -c $(patsubst %.o, %.c, $@) # This is a make function (not itself a rule) to generate a rule that says that (in addition to the .o # depending on the .c, as stated above) each .o file depends on the headers that the .c file includes. # 'gcc -M' generates a very long list of headers and, in addition, writes the list as Makefile rule, # which I chose not to use as is, but to strip the target (so that I can then specify it myself :-), # arrange one header per line ('sed ... | sed ... | xargs ...') so that I can strip out the system # headers ('grep -v ^/usr/') and finally pack back into one line ('paste ...'). define generate_rule $(1).o: $(shell gcc -M $(1).c | sed -e 's/.*: //' | sed 's/ \\//' | xargs -n 1 echo | grep -v ^/usr/ | paste -s -d' ') endef # This line calls that function for each .c file. Note that if there are .c files that are # not required to compile plb, rules will nonetheless be generated for them, but they # won't be run, due to not being required to be run in order to compile plb. $(foreach CFILE, $(wildcard *.c), $(eval $(call generate_rule,$(patsubst %.c, %, $(CFILE)))))