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:
parent
9df64a8d0a
commit
75ac464c0d
25
Makefile
25
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)
|
||||
|
|
Loading…
Reference in New Issue