logging: new makefile target to generate loglevels at compile time

Using shell commands, a bitmask is generated for each file. Additionally,
a C header containing an array of loglevels and their files is created in
include/loglevels.h.
This commit is contained in:
Michael Stapelberg 2009-12-19 22:33:50 +01:00
parent a61e34d277
commit 5397e893b9
2 changed files with 21 additions and 6 deletions

View File

@ -6,14 +6,14 @@ include $(TOPDIR)/common.mk
AUTOGENERATED:=src/cfgparse.tab.c src/cfgparse.yy.c
FILES:=$(filter-out $(AUTOGENERATED),$(wildcard src/*.c))
FILES:=$(FILES:.c=.o)
HEADERS=$(wildcard include/*.h)
HEADERS:=$(filter-out include/loglevels.h,$(wildcard include/*.h))
# Depend on the specific file (.c for each .o) and on all headers
src/%.o: src/%.c ${HEADERS}
echo "CC $<"
$(CC) $(CFLAGS) -c -o $@ $<
$(CC) $(CFLAGS) -DLOGLEVEL="(1 << $(shell awk '/$(shell basename $< .c)/ { print NR }' loglevels.tmp))" -c -o $@ $<
all: src/cfgparse.y.o src/cfgparse.yy.o ${FILES}
all: loglevels.h 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,15 +22,30 @@ all: 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
echo "LOGLEVELS"
for file in $$(ls src/*.c src/*.y src/*.l | grep -v 'cfgparse.\(tab\|yy\).c'); \
do \
echo $$(basename $$file .c); \
done > loglevels.tmp
(echo "char *loglevels[] = {"; for file in $$(cat loglevels.tmp); \
do \
echo -e "\t\"$$file\", "; \
done; \
echo "};") > include/loglevels.h
src/cfgparse.yy.o: src/cfgparse.l
echo "LEX $<"
flex -i -o$(@:.o=.c) $<
$(CC) $(CFLAGS) -c -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
echo "YACC $<"
bison --debug --verbose -b $(basename $< .y) -d $<
$(CC) $(CFLAGS) -c -o $@ $(<:.y=.tab.c)
$(CC) $(CFLAGS) -DLOGLEVEL="(1 << $(shell awk '/cfgparse.y/ { print NR }' loglevels.tmp))" -c -o $@ $(<:.y=.tab.c)
install: all
echo "INSTALL"

View File

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