From: Michael Stapelberg Date: Sat, 19 Dec 2009 21:33:50 +0000 (+0100) Subject: logging: new makefile target to generate loglevels at compile time X-Git-Tag: 3.e~6^2~200 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=5397e893b955eb1359cc306b014ef06cac71b8e8;p=i3%2Fi3 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. --- diff --git a/Makefile b/Makefile index 84f54cba..bfaff1ce 100644 --- a/Makefile +++ b/Makefile @@ -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" diff --git a/common.mk b/common.mk index 70305148..856f9a7b 100644 --- a/common.mk +++ b/common.mk @@ -74,5 +74,5 @@ endif .SILENT: # Always remake the following targets -.PHONY: install clean dist distclean +.PHONY: install clean dist distclean rm_loglevels