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 ""
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 \
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)