]> git.sur5r.net Git - i3/i3/blob - src/i3.mk
Merge branch 'master' into next
[i3/i3] / src / i3.mk
1 ALL_TARGETS += i3
2 INSTALL_TARGETS += install-i3
3 CLEAN_TARGETS += clean-i3
4
5 i3_SOURCES           := $(filter-out $(i3_SOURCES_GENERATED),$(wildcard src/*.c))
6 i3_HEADERS_CMDPARSER := $(wildcard include/GENERATED_*.h)
7 i3_HEADERS           := $(filter-out $(i3_HEADERS_CMDPARSER),$(wildcard include/*.h))
8 i3_CFLAGS             = $(XCB_CFLAGS) $(XCB_KBD_CFLAGS) $(XCB_WM_CFLAGS) $(X11_CFLAGS) $(XCURSOR_CFLAGS) $(PANGO_CFLAGS) $(YAJL_CFLAGS) $(LIBEV_CFLAGS) $(PCRE_CFLAGS) $(LIBSN_CFLAGS)
9 i3_LIBS               = $(XCB_LIBS) $(XCB_KBD_LIBS) $(XCB_WM_LIBS) $(X11_LIBS) $(XCURSOR_LIBS) $(PANGO_LIBS) $(YAJL_LIBS) $(LIBEV_LIBS) $(PCRE_LIBS) $(LIBSN_LIBS) -lm -lpthread
10
11 # When using clang, we use pre-compiled headers to speed up the build. With
12 # gcc, this actually makes the build slower.
13 ifeq ($(CC),clang)
14 i3_HEADERS_DEP       := $(i3_HEADERS) include/all.h.pch
15 PCH_FLAGS            := -include include/all.h
16 else
17 i3_HEADERS_DEP       := $(i3_HEADERS)
18 PCH_FLAGS            :=
19 endif
20
21 i3_OBJECTS := $(i3_SOURCES_GENERATED:.c=.o) $(i3_SOURCES:.c=.o)
22
23 # The basename/pwd calls are for canonicalizing the path: Instead
24 # of src/main.c, we will see something like ../i3-4.2/src/main.c in
25 # debugger backtraces, making it clearer which code belongs to i3 and
26 # which code doesn’t.
27 # We only do this for src/ since all the other subdirectories contain i3 in
28 # their name already.
29 canonical_path := ../$(shell basename $(shell pwd -P))
30
31 include/all.h.pch: $(i3_HEADERS)
32         echo "[i3] PCH all.h"
33         $(CC) $(I3_CPPFLAGS) $(XCB_CPPFLAGS) $(CPPFLAGS) $(i3_CFLAGS) $(I3_CFLAGS) $(CFLAGS) -x c-header include/all.h -o include/all.h.pch
34
35 src/%.o: src/%.c $(i3_HEADERS_DEP)
36         echo "[i3] CC $<"
37         $(CC) $(I3_CPPFLAGS) $(XCB_CPPFLAGS) $(CPPFLAGS) $(i3_CFLAGS) $(I3_CFLAGS) $(CFLAGS) $(PCH_FLAGS) -c -o $@ ${canonical_path}/$<
38
39 # This target compiles the command parser twice:
40 # Once with -DTEST_PARSER, creating a stand-alone executable used for tests,
41 # and once as an object file for i3.
42 src/commands_parser.o: src/commands_parser.c $(i3_HEADERS_DEP) i3-command-parser.stamp
43         echo "[i3] CC $<"
44         $(CC) $(I3_CPPFLAGS) $(XCB_CPPFLAGS) $(CPPFLAGS) $(i3_CFLAGS) $(I3_CFLAGS) $(CFLAGS) $(I3_LDFLAGS) $(LDFLAGS) -DTEST_PARSER -g -o test.commands_parser $< $(LIBS) $(i3_LIBS)
45         $(CC) $(I3_CPPFLAGS) $(XCB_CPPFLAGS) $(CPPFLAGS) $(i3_CFLAGS) $(I3_CFLAGS) $(CFLAGS) -c -o $@ ${canonical_path}/$<
46
47 # This target compiles the command parser twice:
48 # Once with -DTEST_PARSER, creating a stand-alone executable used for tests,
49 # and once as an object file for i3.
50 src/config_parser.o: src/config_parser.c $(i3_HEADERS_DEP) i3-config-parser.stamp
51         echo "[i3] CC $<"
52         $(CC) $(I3_CPPFLAGS) $(XCB_CPPFLAGS) $(CPPFLAGS) $(i3_CFLAGS) $(I3_CFLAGS) $(CFLAGS) $(I3_LDFLAGS) $(LDFLAGS) -DTEST_PARSER -g -o test.config_parser $< $(LIBS) $(i3_LIBS)
53         $(CC) $(I3_CPPFLAGS) $(XCB_CPPFLAGS) $(CPPFLAGS) $(i3_CFLAGS) $(I3_CFLAGS) $(CFLAGS) -c -o $@ ${canonical_path}/$<
54
55 i3-command-parser.stamp: generate-command-parser.pl parser-specs/commands.spec
56         echo "[i3] Generating command parser"
57         (cd $(TOPDIR)/include; ../generate-command-parser.pl --input=../parser-specs/commands.spec --prefix=command)
58         touch $@
59
60 i3-config-parser.stamp: generate-command-parser.pl parser-specs/config.spec
61         echo "[i3] Generating config parser"
62         (cd $(TOPDIR)/include; ../generate-command-parser.pl --input=../parser-specs/config.spec --prefix=config)
63         touch $@
64
65 i3: libi3.a $(i3_OBJECTS)
66         echo "[i3] Link i3"
67         $(CC) $(I3_LDFLAGS) $(LDFLAGS) -o $@ $(filter-out libi3.a,$^) $(LIBS) $(i3_LIBS)
68
69 install-i3: i3
70         echo "[i3] Install"
71         $(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/bin
72         $(INSTALL) -d -m 0755 $(DESTDIR)$(SYSCONFDIR)/i3
73         $(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/include/i3
74         $(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/share/xsessions
75         $(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/share/applications
76         $(INSTALL) -m 0755 i3 $(DESTDIR)$(PREFIX)/bin/
77         $(LN) -sf i3 $(DESTDIR)$(PREFIX)/bin/i3-with-shmlog
78         $(INSTALL) -m 0755 i3-migrate-config-to-v4 $(DESTDIR)$(PREFIX)/bin/
79         $(INSTALL) -m 0755 i3-sensible-editor $(DESTDIR)$(PREFIX)/bin/
80         $(INSTALL) -m 0755 i3-sensible-pager $(DESTDIR)$(PREFIX)/bin/
81         $(INSTALL) -m 0755 i3-sensible-terminal $(DESTDIR)$(PREFIX)/bin/
82         $(INSTALL) -m 0755 i3-save-tree $(DESTDIR)$(PREFIX)/bin/
83         $(INSTALL) -m 0755 i3-dmenu-desktop $(DESTDIR)$(PREFIX)/bin/
84         test -e $(DESTDIR)$(SYSCONFDIR)/i3/config || $(INSTALL) -m 0644 i3.config $(DESTDIR)$(SYSCONFDIR)/i3/config
85         test -e $(DESTDIR)$(SYSCONFDIR)/i3/config.keycodes || $(INSTALL) -m 0644 i3.config.keycodes $(DESTDIR)$(SYSCONFDIR)/i3/config.keycodes
86         $(INSTALL) -m 0644 i3.xsession.desktop $(DESTDIR)$(PREFIX)/share/xsessions/i3.desktop
87         $(INSTALL) -m 0644 i3-with-shmlog.xsession.desktop $(DESTDIR)$(PREFIX)/share/xsessions/i3.desktop
88         $(INSTALL) -m 0644 i3.applications.desktop $(DESTDIR)$(PREFIX)/share/applications/i3.desktop
89         $(INSTALL) -m 0644 include/i3/ipc.h $(DESTDIR)$(PREFIX)/include/i3/
90
91 clean-i3:
92         echo "[i3] Clean"
93         rm -f $(i3_OBJECTS) $(i3_SOURCES_GENERATED) $(i3_HEADERS_CMDPARSER) include/loglevels.h loglevels.tmp include/all.h.pch i3-command-parser.stamp i3-config-parser.stamp i3 test.config_parser test.commands_parser src/*.gcno src/cfgparse.* src/cmdparse.*