From: Michael Stapelberg Date: Tue, 22 Dec 2009 11:14:09 +0000 (+0100) Subject: makefile: rather than a dependency for each source file, generate loglevels.h by... X-Git-Tag: 3.e~6^2~189 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=75ac464c0dc7758a0db7723da4bb9dcf061466eb;p=i3%2Fi3 makefile: rather than a dependency for each source file, generate loglevels.h by recursion This little hack runs make recursively to generate include/loglevels.h before running any other target but skip an explicit dependency on loglevels.h in each rule. Therefore, you do not need to rebuild every source file when compiling. --- diff --git a/Makefile b/Makefile index 4f921730..7245c5c4 100644 --- a/Makefile +++ b/Makefile @@ -8,12 +8,22 @@ FILES:=$(filter-out $(AUTOGENERATED),$(wildcard src/*.c)) FILES:=$(FILES:.c=.o) HEADERS:=$(filter-out include/loglevels.h,$(wildcard include/*.h)) +# Recursively generate loglevels.h by explicitly calling make +# We need this step because we need to ensure that loglevels.h will be +# updated if necessary, but we also want to save rebuilds of the object +# files, so we cannot let the object files depend on loglevels.h. +ifeq ($(MAKECMDGOALS),loglevels.h) +UNUSED:=$(warning Generating loglevels.h) +else +UNUSED:=$(shell $(MAKE) loglevels.h) +endif + # Depend on the specific file (.c for each .o) and on all headers -src/%.o: src/%.c ${HEADERS} loglevels.h +src/%.o: src/%.c ${HEADERS} echo "CC $<" $(CC) $(CFLAGS) -DLOGLEVEL="(1 << $(shell awk '/$(shell basename $< .c)/ { print NR }' loglevels.tmp))" -c -o $@ $< -all: loglevels.h src/cfgparse.y.o src/cfgparse.yy.o ${FILES} +all: src/cfgparse.y.o src/cfgparse.yy.o ${FILES} echo "LINK i3" $(CC) -o i3 ${FILES} src/cfgparse.y.o src/cfgparse.yy.o $(LDFLAGS) echo "" @@ -22,10 +32,7 @@ all: loglevels.h src/cfgparse.y.o src/cfgparse.yy.o ${FILES} echo "SUBDIR i3-input" $(MAKE) TOPDIR=$(TOPDIR) -C i3-input -rm_loglevels: - rm -f loglevels.h - -loglevels.h: rm_loglevels +loglevels.h: echo "LOGLEVELS" for file in $$(ls src/*.c src/*.y src/*.l | grep -v 'cfgparse.\(tab\|yy\).c'); \ do \ @@ -35,14 +42,14 @@ loglevels.h: rm_loglevels do \ echo "\"$$file\", "; \ done; \ - echo "};") > include/loglevels.h + echo "};") > include/loglevels.h; -src/cfgparse.yy.o: src/cfgparse.l loglevels.h +src/cfgparse.yy.o: src/cfgparse.l echo "LEX $<" flex -i -o$(@:.o=.c) $< $(CC) $(CFLAGS) -DLOGLEVEL="(1 << $(shell awk '/cfgparse.l/ { print NR }' loglevels.tmp))" -c -o $@ $(@:.o=.c) -src/cfgparse.y.o: src/cfgparse.y loglevels.h +src/cfgparse.y.o: src/cfgparse.y echo "YACC $<" bison --debug --verbose -b $(basename $< .y) -d $< $(CC) $(CFLAGS) -DLOGLEVEL="(1 << $(shell awk '/cfgparse.y/ { print NR }' loglevels.tmp))" -c -o $@ $(<:.y=.tab.c) diff --git a/common.mk b/common.mk index 856f9a7b..70305148 100644 --- a/common.mk +++ b/common.mk @@ -74,5 +74,5 @@ endif .SILENT: # Always remake the following targets -.PHONY: install clean dist distclean rm_loglevels +.PHONY: install clean dist distclean