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