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:
parent
a61e34d277
commit
5397e893b9
25
Makefile
25
Makefile
|
@ -6,14 +6,14 @@ include $(TOPDIR)/common.mk
|
||||||
AUTOGENERATED:=src/cfgparse.tab.c src/cfgparse.yy.c
|
AUTOGENERATED:=src/cfgparse.tab.c src/cfgparse.yy.c
|
||||||
FILES:=$(filter-out $(AUTOGENERATED),$(wildcard src/*.c))
|
FILES:=$(filter-out $(AUTOGENERATED),$(wildcard src/*.c))
|
||||||
FILES:=$(FILES:.c=.o)
|
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
|
# Depend on the specific file (.c for each .o) and on all headers
|
||||||
src/%.o: src/%.c ${HEADERS}
|
src/%.o: src/%.c ${HEADERS}
|
||||||
echo "CC $<"
|
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"
|
echo "LINK i3"
|
||||||
$(CC) -o i3 ${FILES} src/cfgparse.y.o src/cfgparse.yy.o $(LDFLAGS)
|
$(CC) -o i3 ${FILES} src/cfgparse.y.o src/cfgparse.yy.o $(LDFLAGS)
|
||||||
echo ""
|
echo ""
|
||||||
|
@ -22,15 +22,30 @@ all: src/cfgparse.y.o src/cfgparse.yy.o ${FILES}
|
||||||
echo "SUBDIR i3-input"
|
echo "SUBDIR i3-input"
|
||||||
$(MAKE) TOPDIR=$(TOPDIR) -C 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
|
src/cfgparse.yy.o: src/cfgparse.l
|
||||||
echo "LEX $<"
|
echo "LEX $<"
|
||||||
flex -i -o$(@:.o=.c) $<
|
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
|
src/cfgparse.y.o: src/cfgparse.y
|
||||||
echo "YACC $<"
|
echo "YACC $<"
|
||||||
bison --debug --verbose -b $(basename $< .y) -d $<
|
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
|
install: all
|
||||||
echo "INSTALL"
|
echo "INSTALL"
|
||||||
|
|
Loading…
Reference in New Issue