]> git.sur5r.net Git - i3/i3/blob - Makefile
3bdffbb49bfddad0c09995c29b20d0d08673ef85
[i3/i3] / Makefile
1 TOPDIR=$(shell pwd)
2
3 include $(TOPDIR)/common.mk
4
5 # Depend on the object files of all source-files in src/*.c and on all header files
6 AUTOGENERATED:=src/cfgparse.tab.c src/cfgparse.yy.c src/cmdparse.tab.c src/cmdparse.yy.c
7 FILES:=$(filter-out $(AUTOGENERATED),$(wildcard src/*.c))
8 FILES:=$(FILES:.c=.o)
9 HEADERS:=$(filter-out include/loglevels.h,$(wildcard include/*.h))
10
11 # Recursively generate loglevels.h by explicitly calling make
12 # We need this step because we need to ensure that loglevels.h will be
13 # updated if necessary, but we also want to save rebuilds of the object
14 # files, so we cannot let the object files depend on loglevels.h.
15 ifeq ($(MAKECMDGOALS),loglevels.h)
16 #UNUSED:=$(warning Generating loglevels.h)
17 else
18 UNUSED:=$(shell $(MAKE) loglevels.h)
19 endif
20
21 SUBDIRS=i3-msg i3-input i3-nagbar i3-config-wizard
22
23 # Depend on the specific file (.c for each .o) and on all headers
24 src/%.o: src/%.c ${HEADERS}
25         echo "CC $<"
26         $(CC) $(CPPFLAGS) $(CFLAGS) -DLOGLEVEL="((uint64_t)1 << $(shell awk '/$(shell basename $< .c)/ { print NR; exit 0; }' loglevels.tmp))" -c -o $@ $<
27
28 all: i3 subdirs
29
30 i3: src/cfgparse.y.o src/cfgparse.yy.o src/cmdparse.y.o src/cmdparse.yy.o ${FILES}
31         echo "LINK i3"
32         $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
33
34 subdirs:
35         for dir in $(SUBDIRS); do \
36                 echo ""; \
37                 echo "MAKE $$dir"; \
38                 $(MAKE) -C $$dir; \
39         done
40
41 loglevels.h:
42         echo "LOGLEVELS"
43         for file in $$(ls src/*.c src/*.y src/*.l | grep -v 'cfgparse.\(tab\|yy\).c'); \
44         do \
45                 echo $$(basename $$file .c); \
46         done > loglevels.tmp
47         (echo "char *loglevels[] = {"; for file in $$(cat loglevels.tmp); \
48         do \
49                 echo "\"$$file\", "; \
50         done; \
51         echo "};") > include/loglevels.h;
52
53 src/cfgparse.yy.o: src/cfgparse.l src/cfgparse.y.o ${HEADERS}
54         echo "LEX $<"
55         flex -i -o$(@:.o=.c) $<
56         $(CC) $(CPPFLAGS) $(CFLAGS) -DLOGLEVEL="(1 << $(shell awk '/cfgparse.l/ { print NR }' loglevels.tmp))" -c -o $@ $(@:.o=.c)
57
58 src/cmdparse.yy.o: src/cmdparse.l src/cmdparse.y.o ${HEADERS}
59         echo "LEX $<"
60         flex -Pcmdyy -i -o$(@:.o=.c) $<
61         $(CC) $(CPPFLAGS) $(CFLAGS) -DLOGLEVEL="(1 << $(shell awk '/cmdparse.l/ { print NR }' loglevels.tmp))" -c -o $@ $(@:.o=.c)
62
63
64 src/cfgparse.y.o: src/cfgparse.y ${HEADERS}
65         echo "YACC $<"
66         bison --debug --verbose -b $(basename $< .y) -d $<
67         $(CC) $(CPPFLAGS) $(CFLAGS) -DLOGLEVEL="(1 << $(shell awk '/cfgparse.y/ { print NR }' loglevels.tmp))" -c -o $@ $(<:.y=.tab.c)
68
69 src/cmdparse.y.o: src/cmdparse.y ${HEADERS}
70         echo "YACC $<"
71         bison -p cmdyy --debug --verbose -b $(basename $< .y) -d $<
72         $(CC) $(CPPFLAGS) $(CFLAGS) -DLOGLEVEL="(1 << $(shell awk '/cmdparse.y/ { print NR }' loglevels.tmp))" -c -o $@ $(<:.y=.tab.c)
73
74
75 install: all
76         echo "INSTALL"
77         $(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/bin
78         $(INSTALL) -d -m 0755 $(DESTDIR)$(SYSCONFDIR)/i3
79         $(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/include/i3
80         $(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/share/xsessions
81         $(INSTALL) -m 0755 i3 $(DESTDIR)$(PREFIX)/bin/
82         $(INSTALL) -m 0755 i3-migrate-config-to-v4 $(DESTDIR)$(PREFIX)/bin/
83         test -e $(DESTDIR)$(SYSCONFDIR)/i3/config || $(INSTALL) -m 0644 i3.config $(DESTDIR)$(SYSCONFDIR)/i3/config
84         test -e $(DESTDIR)$(SYSCONFDIR)/i3/config.keycodes || $(INSTALL) -m 0644 i3.config.keycodes $(DESTDIR)$(SYSCONFDIR)/i3/config.keycodes
85         $(INSTALL) -m 0644 i3.welcome $(DESTDIR)$(SYSCONFDIR)/i3/welcome
86         $(INSTALL) -m 0644 i3.desktop $(DESTDIR)$(PREFIX)/share/xsessions/
87         $(INSTALL) -m 0644 include/i3/ipc.h $(DESTDIR)$(PREFIX)/include/i3/
88         for dir in $(SUBDIRS); do \
89                 $(MAKE) -C $$dir install; \
90         done
91
92 dist: distclean
93         [ ! -d i3-${VERSION} ] || rm -rf i3-${VERSION}
94         [ ! -e i3-${VERSION}.tar.bz2 ] || rm i3-${VERSION}.tar.bz2
95         mkdir i3-${VERSION}
96         cp i3-migrate-config-to-v4 i3.config.keycodes DEPENDS GOALS LICENSE PACKAGE-MAINTAINER TODO RELEASE-NOTES-${VERSION} i3.config i3.desktop i3.welcome pseudo-doc.doxygen i3-wsbar Makefile i3-${VERSION}
97         cp -r src i3-msg i3-nagbar i3-config-wizard yajl-fallback include man i3-${VERSION}
98         # Only copy toplevel documentation (important stuff)
99         mkdir i3-${VERSION}/docs
100         # Pre-generate documentation
101         make -C docs
102         # Cleanup τεχ output files
103         find docs -regex ".*\.\(aux\|out\|log\|toc\|bm\|dvi\|log\)" -exec rm '{}' \;
104         find docs -maxdepth 1 -type f ! \( -name "*.xcf" -or -name "*.svg" \) -exec cp '{}' i3-${VERSION}/docs \;
105         # Only copy source code from i3-input
106         mkdir i3-${VERSION}/i3-input
107         find i3-input -maxdepth 1 -type f \( -name "*.c" -or -name "*.h" -or -name "Makefile" \) -exec cp '{}' i3-${VERSION}/i3-input \;
108         sed -e 's/^GIT_VERSION:=\(.*\)/GIT_VERSION:=$(shell echo '${GIT_VERSION}' | sed 's/\\/\\\\/g')/g;s/^VERSION:=\(.*\)/VERSION:=${VERSION}/g' common.mk > i3-${VERSION}/common.mk
109         # Pre-generate a manpage to allow distributors to skip this step and save some dependencies
110         $(MAKE) -C man
111         cp man/*.1 i3-${VERSION}/man/
112         tar cfj i3-${VERSION}.tar.bz2 i3-${VERSION}
113         rm -rf i3-${VERSION}
114
115 clean:
116         rm -f src/*.o src/*.gcno src/cfgparse.tab.{c,h} src/cfgparse.yy.c src/cfgparse.{output,dot} src/cmdparse.tab.{c,h} src/cmdparse.yy.c src/cmdparse.{output,dot} loglevels.tmp include/loglevels.h
117         (which lcov >/dev/null && lcov -d . --zerocounters) || true
118         $(MAKE) -C docs clean
119         $(MAKE) -C man clean
120         for dir in $(SUBDIRS); do \
121                 echo ""; \
122                 echo "CLEAN $$dir"; \
123                 $(MAKE) TOPDIR=$(TOPDIR) -C $$dir distclean; \
124         done
125
126 distclean: clean
127         rm -f i3
128         for dir in $(SUBDIRS); do \
129                 echo ""; \
130                 echo "DISTCLEAN $$dir"; \
131                 $(MAKE) TOPDIR=$(TOPDIR) -C $$dir distclean; \
132         done
133
134 coverage:
135         rm -f /tmp/i3-coverage.info
136         rm -rf /tmp/i3-coverage
137         lcov -d . -b . --capture -o /tmp/i3-coverage.info
138         genhtml -o /tmp/i3-coverage/ /tmp/i3-coverage.info