]> git.sur5r.net Git - i3/i3/blob - Makefile
Merge branch 'nagbar-wrap' 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
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 i3bar
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         $(INSTALL) -m 0755 i3-sensible-editor $(DESTDIR)$(PREFIX)/bin/
84         $(INSTALL) -m 0755 i3-sensible-pager $(DESTDIR)$(PREFIX)/bin/
85         $(INSTALL) -m 0755 i3-sensible-terminal $(DESTDIR)$(PREFIX)/bin/
86         test -e $(DESTDIR)$(SYSCONFDIR)/i3/config || $(INSTALL) -m 0644 i3.config $(DESTDIR)$(SYSCONFDIR)/i3/config
87         test -e $(DESTDIR)$(SYSCONFDIR)/i3/config.keycodes || $(INSTALL) -m 0644 i3.config.keycodes $(DESTDIR)$(SYSCONFDIR)/i3/config.keycodes
88         $(INSTALL) -m 0644 i3.welcome $(DESTDIR)$(SYSCONFDIR)/i3/welcome
89         $(INSTALL) -m 0644 i3.desktop $(DESTDIR)$(PREFIX)/share/xsessions/
90         $(INSTALL) -m 0644 include/i3/ipc.h $(DESTDIR)$(PREFIX)/include/i3/
91         for dir in $(SUBDIRS); do \
92                 $(MAKE) -C $$dir install; \
93         done
94
95 dist: distclean
96         [ ! -d i3-${VERSION} ] || rm -rf i3-${VERSION}
97         [ ! -e i3-${VERSION}.tar.bz2 ] || rm i3-${VERSION}.tar.bz2
98         mkdir i3-${VERSION}
99         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}
100         cp -r src i3-msg i3-nagbar i3-config-wizard i3bar yajl-fallback include man i3-${VERSION}
101         # Only copy toplevel documentation (important stuff)
102         mkdir i3-${VERSION}/docs
103         # Pre-generate documentation
104         make -C docs
105         make -C i3bar/doc
106         # Cleanup τεχ output files
107         find docs -regex ".*\.\(aux\|out\|log\|toc\|bm\|dvi\|log\)" -exec rm '{}' \;
108         find docs -maxdepth 1 -type f ! \( -name "*.xcf" -or -name "*.svg" \) -exec cp '{}' i3-${VERSION}/docs \;
109         # Only copy source code from i3-input
110         mkdir i3-${VERSION}/i3-input
111         find i3-input -maxdepth 1 -type f \( -name "*.c" -or -name "*.h" -or -name "Makefile" \) -exec cp '{}' i3-${VERSION}/i3-input \;
112         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
113         # Pre-generate a manpage to allow distributors to skip this step and save some dependencies
114         $(MAKE) -C man
115         cp man/*.1 i3-${VERSION}/man/
116         cp i3bar/doc/*.1 i3-${VERSION}/i3bar/doc/
117         tar cfj i3-${VERSION}.tar.bz2 i3-${VERSION}
118         rm -rf i3-${VERSION}
119
120 clean:
121         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
122         (which lcov >/dev/null 2>&1 && lcov -d . --zerocounters) || true
123         $(MAKE) -C docs clean
124         $(MAKE) -C man clean
125         for dir in $(SUBDIRS); do \
126                 echo ""; \
127                 echo "CLEAN $$dir"; \
128                 $(MAKE) TOPDIR=$(TOPDIR) -C $$dir distclean; \
129         done
130
131 distclean: clean
132         rm -f i3
133         for dir in $(SUBDIRS); do \
134                 echo ""; \
135                 echo "DISTCLEAN $$dir"; \
136                 $(MAKE) TOPDIR=$(TOPDIR) -C $$dir distclean; \
137         done
138
139 coverage:
140         rm -f /tmp/i3-coverage.info
141         rm -rf /tmp/i3-coverage
142         lcov -d . -b . --capture -o /tmp/i3-coverage.info
143         genhtml -o /tmp/i3-coverage/ /tmp/i3-coverage.info