]> git.sur5r.net Git - i3/i3/blob - Makefile
Merge branch 'master' into next
[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 CMDPARSE_HEADERS:=include/GENERATED_call.h include/GENERATED_enums.h include/GENERATED_tokens.h
11
12 # Recursively generate loglevels.h by explicitly calling make
13 # We need this step because we need to ensure that loglevels.h will be
14 # updated if necessary, but we also want to save rebuilds of the object
15 # files, so we cannot let the object files depend on loglevels.h.
16 ifeq ($(MAKECMDGOALS),loglevels.h)
17 #UNUSED:=$(warning Generating loglevels.h)
18 else
19 UNUSED:=$(shell $(MAKE) loglevels.h)
20 endif
21
22 SUBDIRS:=i3-msg i3-input i3-nagbar i3-config-wizard i3bar i3-dump-log
23
24 # Depend on the specific file (.c for each .o) and on all headers
25 src/%.o: src/%.c ${HEADERS}
26         echo "[i3] CC $<"
27         $(CC) $(CPPFLAGS) $(CFLAGS) -DLOGLEVEL="((uint64_t)1 << $(shell awk '/$(shell basename $< .c)/ { print NR; exit 0; }' loglevels.tmp))" -c -o $@ $<
28
29 all: i3 subdirs
30
31 i3: libi3/libi3.a src/cfgparse.y.o src/cfgparse.yy.o src/cmdparse.y.o src/cmdparse.yy.o ${FILES}
32         echo "[i3] LINK i3"
33         $(CC) $(LDFLAGS) -o $@ $(filter-out libi3/libi3.a,$^) $(LIBS)
34
35 libi3/%.a: libi3/*.c
36         $(MAKE) -C libi3
37
38 subdirs:
39         for dir in $(SUBDIRS); do \
40                 echo ""; \
41                 echo "MAKE $$dir"; \
42                 $(MAKE) -C $$dir; \
43         done
44
45 loglevels.h:
46         echo "[i3] LOGLEVELS"
47         for file in $$(ls src/*.c src/*.y src/*.l | grep -v 'cfgparse.\(tab\|yy\).c'); \
48         do \
49                 echo $$(basename $$file .c); \
50         done > loglevels.tmp
51         (echo "char *loglevels[] = {"; for file in $$(cat loglevels.tmp); \
52         do \
53                 echo "\"$$file\", "; \
54         done; \
55         echo "};") > include/loglevels.h;
56
57 # The GENERATED_* files are actually all created from a single pass, so all
58 # files just depend on the first one.
59 include/GENERATED_call.h: generate-command-parser.pl parser-specs/commands.spec
60         echo "[i3] Generating command parser"
61         (cd include; ../generate-command-parser.pl)
62 include/GENERATED_enums.h: include/GENERATED_call.h
63 include/GENERATED_tokens.h: include/GENERATED_call.h
64
65 # This target compiles the command parser twice:
66 # Once with -DTEST_PARSER, creating a stand-alone executable used for tests,
67 # and once as an object file for i3.
68 src/commands_parser.o: src/commands_parser.c ${HEADERS} ${CMDPARSE_HEADERS}
69         echo "[i3] CC $<"
70         $(CC) $(CPPFLAGS) $(CFLAGS) -DTEST_PARSER -DLOGLEVEL="((uint64_t)1 << $(shell awk '/$(shell basename $< .c)/ { print NR; exit 0; }' loglevels.tmp))" -o test.commands_parser $<
71         $(CC) $(CPPFLAGS) $(CFLAGS) -DLOGLEVEL="((uint64_t)1 << $(shell awk '/$(shell basename $< .c)/ { print NR; exit 0; }' loglevels.tmp))" -c -o $@ $<
72
73 src/cfgparse.yy.o: src/cfgparse.l src/cfgparse.y.o ${HEADERS}
74         echo "[i3] LEX $<"
75         $(FLEX) -i -o$(@:.o=.c) $<
76         $(CC) $(CPPFLAGS) $(CFLAGS) -DLOGLEVEL="(1 << $(shell awk '/cfgparse.l/ { print NR }' loglevels.tmp))" -c -o $@ $(@:.o=.c)
77
78 src/cmdparse.yy.o: src/cmdparse.l src/cmdparse.y.o ${HEADERS}
79         echo "[i3] LEX $<"
80         $(FLEX) -Pcmdyy -i -o$(@:.o=.c) $<
81         $(CC) $(CPPFLAGS) $(CFLAGS) -DLOGLEVEL="(1 << $(shell awk '/cmdparse.l/ { print NR }' loglevels.tmp))" -c -o $@ $(@:.o=.c)
82
83
84 src/cfgparse.y.o: src/cfgparse.y ${HEADERS}
85         echo "[i3] YACC $<"
86         $(BISON) --debug --verbose -b $(basename $< .y) -d $<
87         $(CC) $(CPPFLAGS) $(CFLAGS) -DLOGLEVEL="(1 << $(shell awk '/cfgparse.y/ { print NR }' loglevels.tmp))" -c -o $@ $(<:.y=.tab.c)
88
89 src/cmdparse.y.o: src/cmdparse.y ${HEADERS}
90         echo "[i3] YACC $<"
91         $(BISON) -p cmdyy --debug --verbose -b $(basename $< .y) -d $<
92         $(CC) $(CPPFLAGS) $(CFLAGS) -DLOGLEVEL="(1 << $(shell awk '/cmdparse.y/ { print NR }' loglevels.tmp))" -c -o $@ $(<:.y=.tab.c)
93
94
95 install: all
96         echo "[i3] INSTALL"
97         $(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/bin
98         $(INSTALL) -d -m 0755 $(DESTDIR)$(SYSCONFDIR)/i3
99         $(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/include/i3
100         $(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/share/xsessions
101         $(INSTALL) -m 0755 i3 $(DESTDIR)$(PREFIX)/bin/
102         $(INSTALL) -m 0755 i3-migrate-config-to-v4 $(DESTDIR)$(PREFIX)/bin/
103         $(INSTALL) -m 0755 i3-sensible-editor $(DESTDIR)$(PREFIX)/bin/
104         $(INSTALL) -m 0755 i3-sensible-pager $(DESTDIR)$(PREFIX)/bin/
105         $(INSTALL) -m 0755 i3-sensible-terminal $(DESTDIR)$(PREFIX)/bin/
106         test -e $(DESTDIR)$(SYSCONFDIR)/i3/config || $(INSTALL) -m 0644 i3.config $(DESTDIR)$(SYSCONFDIR)/i3/config
107         test -e $(DESTDIR)$(SYSCONFDIR)/i3/config.keycodes || $(INSTALL) -m 0644 i3.config.keycodes $(DESTDIR)$(SYSCONFDIR)/i3/config.keycodes
108         $(INSTALL) -m 0644 i3.welcome $(DESTDIR)$(SYSCONFDIR)/i3/welcome
109         $(INSTALL) -m 0644 i3.desktop $(DESTDIR)$(PREFIX)/share/xsessions/
110         $(INSTALL) -m 0644 include/i3/ipc.h $(DESTDIR)$(PREFIX)/include/i3/
111         for dir in $(SUBDIRS); do \
112                 $(MAKE) -C $$dir install; \
113         done
114
115 dist: distclean
116         [ ! -d i3-${VERSION} ] || rm -rf i3-${VERSION}
117         [ ! -e i3-${VERSION}.tar.bz2 ] || rm i3-${VERSION}.tar.bz2
118         mkdir i3-${VERSION}
119         cp i3-migrate-config-to-v4 generate-command-parser.pl i3-sensible-* i3.config.keycodes DEPENDS GOALS LICENSE PACKAGE-MAINTAINER RELEASE-NOTES-${VERSION} i3.config i3.desktop i3.welcome pseudo-doc.doxygen i3-wsbar Makefile i3-${VERSION}
120         cp -r src libi3 i3-msg i3-nagbar i3-config-wizard i3bar i3-dump-log yajl-fallback include man parser-specs i3-${VERSION}
121         # Only copy toplevel documentation (important stuff)
122         mkdir i3-${VERSION}/docs
123         # Pre-generate documentation
124         $(MAKE) -C docs
125         $(MAKE) -C i3bar/doc
126         # Cleanup τεχ output files
127         find docs -regex ".*\.\(aux\|out\|log\|toc\|bm\|dvi\|log\)" -exec rm '{}' \;
128         find docs -maxdepth 1 -type f ! \( -name "*.xcf" -or -name "*.svg" \) -exec cp '{}' i3-${VERSION}/docs \;
129         # Only copy source code from i3-input
130         mkdir i3-${VERSION}/i3-input
131         find i3-input -maxdepth 1 -type f \( -name "*.c" -or -name "*.h" -or -name "Makefile" \) -exec cp '{}' i3-${VERSION}/i3-input \;
132         sed -e 's/^GIT_VERSION:=\(.*\)/GIT_VERSION:=$(shell /bin/echo '${GIT_VERSION}' | sed 's/\\/\\\\/g')/g;s/^VERSION:=\(.*\)/VERSION:=${VERSION}/g' common.mk > i3-${VERSION}/common.mk
133         # Pre-generate a manpage to allow distributors to skip this step and save some dependencies
134         $(MAKE) -C man
135         cp man/*.1 i3-${VERSION}/man/
136         cp i3bar/doc/*.1 i3-${VERSION}/i3bar/doc/
137         tar cfj i3-${VERSION}.tar.bz2 i3-${VERSION}
138         rm -rf i3-${VERSION}
139
140 clean:
141         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 include/GENERATED_*
142         (which lcov >/dev/null 2>&1 && lcov -d . --zerocounters) || true
143         $(MAKE) -C libi3 clean
144         $(MAKE) -C docs clean
145         $(MAKE) -C man clean
146         for dir in $(SUBDIRS); do \
147                 echo ""; \
148                 echo "CLEAN $$dir"; \
149                 $(MAKE) TOPDIR=$(TOPDIR) -C $$dir distclean; \
150         done
151
152 distclean: clean
153         rm -f i3
154         for dir in $(SUBDIRS); do \
155                 echo ""; \
156                 echo "DISTCLEAN $$dir"; \
157                 $(MAKE) TOPDIR=$(TOPDIR) -C $$dir distclean; \
158         done
159
160 coverage:
161         rm -f /tmp/i3-coverage.info
162         rm -rf /tmp/i3-coverage
163         lcov -d . -b . --capture -o /tmp/i3-coverage.info
164         genhtml -o /tmp/i3-coverage/ /tmp/i3-coverage.info