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.
This commit is contained in:
Michael Stapelberg 2009-12-22 12:14:09 +01:00
parent 9df64a8d0a
commit 75ac464c0d
2 changed files with 17 additions and 10 deletions

View File

@ -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)

View File

@ -74,5 +74,5 @@ endif
.SILENT:
# Always remake the following targets
.PHONY: install clean dist distclean rm_loglevels
.PHONY: install clean dist distclean