]> 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
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 ${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 $< $(LIBS)
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
79 src/cfgparse.y.o: src/cfgparse.y ${HEADERS}
80         echo "[i3] YACC $<"
81         $(BISON) --debug --verbose -b $(basename $< .y) -d $<
82         $(CC) $(CPPFLAGS) $(CFLAGS) -DLOGLEVEL="(1 << $(shell awk '/cfgparse.y/ { print NR }' loglevels.tmp))" -c -o $@ $(<:.y=.tab.c)
83
84
85 install: all
86         echo "[i3] INSTALL"
87         $(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/bin
88         $(INSTALL) -d -m 0755 $(DESTDIR)$(SYSCONFDIR)/i3
89         $(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/include/i3
90         $(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/share/xsessions
91         $(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/share/applications
92         $(INSTALL) -m 0755 i3 $(DESTDIR)$(PREFIX)/bin/
93         $(INSTALL) -m 0755 i3-migrate-config-to-v4 $(DESTDIR)$(PREFIX)/bin/
94         $(INSTALL) -m 0755 i3-sensible-editor $(DESTDIR)$(PREFIX)/bin/
95         $(INSTALL) -m 0755 i3-sensible-pager $(DESTDIR)$(PREFIX)/bin/
96         $(INSTALL) -m 0755 i3-sensible-terminal $(DESTDIR)$(PREFIX)/bin/
97         test -e $(DESTDIR)$(SYSCONFDIR)/i3/config || $(INSTALL) -m 0644 i3.config $(DESTDIR)$(SYSCONFDIR)/i3/config
98         test -e $(DESTDIR)$(SYSCONFDIR)/i3/config.keycodes || $(INSTALL) -m 0644 i3.config.keycodes $(DESTDIR)$(SYSCONFDIR)/i3/config.keycodes
99         $(INSTALL) -m 0644 i3.welcome $(DESTDIR)$(SYSCONFDIR)/i3/welcome
100         $(INSTALL) -m 0644 i3.xsession.desktop $(DESTDIR)$(PREFIX)/share/xsessions/i3.desktop
101         $(INSTALL) -m 0644 i3.applications.desktop $(DESTDIR)$(PREFIX)/share/applications/i3.desktop
102         $(INSTALL) -m 0644 include/i3/ipc.h $(DESTDIR)$(PREFIX)/include/i3/
103         for dir in $(SUBDIRS); do \
104                 $(MAKE) -C $$dir install; \
105         done
106
107 dist: distclean
108         [ ! -d i3-${VERSION} ] || rm -rf i3-${VERSION}
109         [ ! -e i3-${VERSION}.tar.bz2 ] || rm i3-${VERSION}.tar.bz2
110         mkdir i3-${VERSION}
111         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.xsession.desktop i3.applications.desktop i3.welcome pseudo-doc.doxygen i3-wsbar Makefile i3-${VERSION}
112         cp -r src libi3 i3-msg i3-nagbar i3-config-wizard i3bar i3-dump-log yajl-fallback include man parser-specs i3-${VERSION}
113         # Only copy toplevel documentation (important stuff)
114         mkdir i3-${VERSION}/docs
115         # Pre-generate documentation
116         $(MAKE) -C docs
117         $(MAKE) -C i3bar/doc
118         # Cleanup τεχ output files
119         find docs -regex ".*\.\(aux\|out\|log\|toc\|bm\|dvi\|log\)" -exec rm '{}' \;
120         find docs -maxdepth 1 -type f ! \( -name "*.xcf" -or -name "*.svg" \) -exec cp '{}' i3-${VERSION}/docs \;
121         # Only copy source code from i3-input
122         mkdir i3-${VERSION}/i3-input
123         find i3-input -maxdepth 1 -type f \( -name "*.c" -or -name "*.h" -or -name "Makefile" \) -exec cp '{}' i3-${VERSION}/i3-input \;
124         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
125         # Pre-generate a manpage to allow distributors to skip this step and save some dependencies
126         $(MAKE) -C man
127         cp man/*.1 i3-${VERSION}/man/
128         cp i3bar/doc/*.1 i3-${VERSION}/i3bar/doc/
129         tar cfj i3-${VERSION}.tar.bz2 i3-${VERSION}
130         rm -rf i3-${VERSION}
131
132 clean:
133         rm -f src/*.o src/*.gcno src/cfgparse.tab.{c,h} src/cfgparse.yy.c src/cfgparse.{output,dot} loglevels.tmp include/loglevels.h include/GENERATED_*
134         (which lcov >/dev/null 2>&1 && lcov -d . --zerocounters) || true
135         $(MAKE) -C libi3 clean
136         $(MAKE) -C docs clean
137         $(MAKE) -C man clean
138         for dir in $(SUBDIRS); do \
139                 echo ""; \
140                 echo "CLEAN $$dir"; \
141                 $(MAKE) TOPDIR=$(TOPDIR) -C $$dir distclean; \
142         done
143
144 distclean: clean
145         rm -f i3
146         for dir in $(SUBDIRS); do \
147                 echo ""; \
148                 echo "DISTCLEAN $$dir"; \
149                 $(MAKE) TOPDIR=$(TOPDIR) -C $$dir distclean; \
150         done
151
152 coverage:
153         rm -f /tmp/i3-coverage.info
154         rm -rf /tmp/i3-coverage
155         lcov -d . -b . --capture -o /tmp/i3-coverage.info
156         genhtml -o /tmp/i3-coverage/ /tmp/i3-coverage.info