]>
Commit | Line | Data |
---|---|---|
7152e5ef JMM |
1 | # Makefile for the BIRD Internet Routing Daemon |
2 | # (c) 1999--2000 Martin Mares <mj@ucw.cz> | |
3 | # (c) 2016 Jan Moskyto Matejka <mq@ucw.cz> | |
4 | ||
5 | # Disable build-in rules | |
6 | MAKEFLAGS += -r | |
7 | ||
8 | # Variable definitions | |
9 | CPPFLAGS=-I$(objdir) -I$(srcdir) @CPPFLAGS@ | |
10 | CFLAGS=$(CPPFLAGS) @CFLAGS@ | |
11 | LDFLAGS=@LDFLAGS@ | |
86b9e8e3 | 12 | M4FLAGS=@M4FLAGS@ |
7ffc0a65 | 13 | BISONFLAGS=@BISONFLAGS@ |
7152e5ef | 14 | LIBS=@LIBS@ |
65d2a88d | 15 | DAEMON_LIBS=@DAEMON_LIBS@ |
7152e5ef JMM |
16 | CLIENT_LIBS=@CLIENT_LIBS@ |
17 | CC=@CC@ | |
18 | M4=@M4@ | |
19 | BISON=@BISON@ | |
20 | FLEX=@FLEX@ | |
21 | RANLIB=@RANLIB@ | |
22 | INSTALL=@INSTALL@ | |
23 | INSTALL_PROGRAM=@INSTALL_PROGRAM@ | |
24 | INSTALL_DATA=@INSTALL_DATA@ | |
25 | ||
26 | client=$(addprefix $(exedir)/,@CLIENT@) | |
27 | daemon=$(exedir)/bird | |
9b0a0ba9 | 28 | protocols=@protocols@ |
dc28c6ed | 29 | PROTO_BUILD := $(protocols) dev kif krt |
7152e5ef JMM |
30 | |
31 | prefix=@prefix@ | |
32 | exec_prefix=@exec_prefix@ | |
33 | bindir=@bindir@ | |
34 | sbindir=@sbindir@ | |
35 | sysconfdir=@sysconfdir@ | |
36 | localstatedir=@localstatedir@ | |
d0b45978 | 37 | runstatedir=@runstatedir@ |
7152e5ef JMM |
38 | docdir=@prefix@/doc |
39 | ||
40 | srcdir := @srcdir@ | |
41 | objdir := @objdir@ | |
42 | exedir := @exedir@ | |
43 | ||
29958745 JMM |
44 | git-label:=$(strip $(shell cd $(srcdir) && [ "$$(git rev-parse --show-toplevel)" = "$$(readlink -f .)" ] && git describe --always --dirty=-x 2>/dev/null)) |
45 | ifneq ($(git-label),) | |
46 | CFLAGS += -DGIT_LABEL="$(git-label)" | |
47 | endif | |
48 | ||
7152e5ef JMM |
49 | ifeq ($(objdir),.) |
50 | objdir := $(realpath .) | |
51 | endif | |
52 | ||
53 | ifeq ($(VERBOSE),) | |
d6f027ef | 54 | E:=@ |
7152e5ef JMM |
55 | Q:=@ |
56 | else | |
d6f027ef | 57 | E:=@\# |
7152e5ef JMM |
58 | Q:= |
59 | endif | |
60 | ||
78ca6ea8 JMM |
61 | ifneq ($(COLOR),) |
62 | CFLAGS += -fdiagnostics-color=always | |
63 | endif | |
64 | ||
7152e5ef | 65 | # Meta rules |
7152e5ef | 66 | docgoals := docs userdocs progdocs |
9b0a0ba9 OZ |
67 | testgoals := check test tests tests_run |
68 | cleangoals := clean distclean testsclean | |
5d511948 MM |
69 | .PHONY: all daemon cli $(docgoals) $(testgoals) $(cleangoals) tags cscope prepare |
70 | ||
7152e5ef JMM |
71 | all: daemon cli |
72 | ||
73 | daemon: $(daemon) | |
74 | cli: $(client) | |
75 | ||
65d2a88d PT |
76 | $(daemon): LIBS += $(DAEMON_LIBS) |
77 | ||
7152e5ef | 78 | # Include directories |
9b0a0ba9 | 79 | dirs := client conf doc filter lib nest test $(addprefix proto/,$(protocols)) @sysdep_dirs@ |
7152e5ef | 80 | |
75206f26 MM |
81 | # conf/Makefile declarations needed for all other modules |
82 | conf-lex-targets := $(addprefix $(objdir)/conf/,cf-lex.o) | |
7152e5ef JMM |
83 | conf-y-targets := $(addprefix $(objdir)/conf/,cf-parse.y keywords.h commands.h) |
84 | cf-local = $(conf-y-targets): $(s)config.Y | |
85 | ||
86 | src-o-files = $(patsubst %.c,$(o)%.o,$(src)) | |
9b0a0ba9 | 87 | tests-target-files = $(patsubst %.c,$(o)%,$(tests_src)) |
7152e5ef | 88 | |
9b0a0ba9 OZ |
89 | all-daemon = $(daemon): $(obj) |
90 | all-client = $(client): $(obj) | |
7152e5ef JMM |
91 | |
92 | s = $(dir $(lastword $(MAKEFILE_LIST))) | |
93 | ifeq ($(srcdir),.) | |
94 | o = $(objdir)/$(s) | |
95 | else | |
96 | o = $(patsubst $(srcdir)%,$(objdir)%,$(s)) | |
97 | endif | |
98 | ||
99 | define clean_in = | |
100 | clean:: | |
101 | rm -f $(addprefix $(o),$(1)) | |
102 | endef | |
103 | ||
104 | clean = $(eval $(call clean_in,$(1))) | |
105 | ||
75206f26 | 106 | # Include main Makefiles of the directories |
7152e5ef JMM |
107 | include $(addsuffix /Makefile,$(addprefix $(srcdir)/,$(dirs))) |
108 | ||
109 | # Generic rules | |
90609253 | 110 | # Object file rules |
5d511948 | 111 | $(objdir)/%.o: $(srcdir)/%.c | prepare |
d6f027ef | 112 | $(E)echo CC -o $@ -c $< |
7152e5ef JMM |
113 | $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $< |
114 | ||
5d511948 | 115 | $(objdir)/%.o: $(objdir)/%.c | prepare |
d6f027ef | 116 | $(E)echo CC -o $@ -c $< |
7152e5ef JMM |
117 | $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $< |
118 | ||
90609253 | 119 | # Debug: Preprocessed source rules |
5d511948 | 120 | $(objdir)/%.E: $(srcdir)/%.c | prepare |
90609253 JMM |
121 | $(E)echo CC -o $@ -E $< |
122 | $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -E $< | |
123 | ||
5d511948 | 124 | $(objdir)/%.E: $(objdir)/%.c | prepare |
90609253 JMM |
125 | $(E)echo CC -o $@ -E $< |
126 | $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -E $< | |
a2fd34f8 | 127 | |
90609253 | 128 | # Debug: Assembler object rules |
5d511948 | 129 | $(objdir)/%.S: $(srcdir)/%.c | prepare |
a2fd34f8 JMM |
130 | $(E)echo CC -o $@ -S $< |
131 | $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -S $< | |
132 | ||
5d511948 | 133 | $(objdir)/%.S: $(objdir)/%.c | prepare |
a2fd34f8 JMM |
134 | $(E)echo CC -o $@ -S $< |
135 | $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -S $< | |
136 | ||
5d511948 MM |
137 | # Finally include the computed dependencies: |
138 | DEPS = $(shell find $(objdir) -name '*.d') | |
139 | ||
140 | # ## if there is at least one non-clean goal | |
141 | ifneq ($(filter-out $(cleangoals),$(MAKECMDGOALS)),) | |
142 | -include $(DEPS) | |
143 | endif | |
144 | ||
145 | # ## if the implicit goal is called | |
146 | ifeq ($(MAKECMDGOALS),) | |
147 | -include $(DEPS) | |
148 | endif | |
a2fd34f8 | 149 | |
5d511948 MM |
150 | # Rule for pre-generating all generated includables |
151 | # before compiling any C file | |
152 | prepare: $(objdir)/sysdep/paths.h | $(objdir)/.dir-stamp | |
a2fd34f8 | 153 | |
5d511948 | 154 | $(objdir)/.dir-stamp: Makefile |
d6f027ef | 155 | $(E)echo MKDIR -p $(addprefix $(objdir)/,$(dirs) doc) |
7152e5ef JMM |
156 | $(Q)mkdir -p $(addprefix $(objdir)/,$(dirs) doc) |
157 | $(Q)touch $@ | |
158 | ||
159 | $(client) $(daemon): | |
d6f027ef | 160 | $(E)echo LD $(LDFLAGS) -o $@ $^ $(LIBS) |
7152e5ef JMM |
161 | $(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LIBS) |
162 | ||
163 | $(objdir)/sysdep/paths.h: Makefile | |
ba348b20 OZ |
164 | $(E)echo GEN $@ |
165 | $(Q)echo >$@ "/* Generated by Makefile, don't edit manually! */" | |
166 | $(Q)echo >>$@ "#define PATH_CONFIG_FILE \"@CONFIG_FILE@\"" | |
167 | $(Q)echo >>$@ "#define PATH_CONTROL_SOCKET \"@CONTROL_SOCKET@\"" | |
168 | $(Q)if test -n "@iproutedir@" ; then echo >>$@ "#define PATH_IPROUTE_DIR \"@iproutedir@\"" ; fi | |
7152e5ef | 169 | |
9b0a0ba9 OZ |
170 | # Unit tests rules |
171 | ||
172 | tests_targets_ok = $(addsuffix .ok,$(tests_targets)) | |
173 | ||
5d511948 | 174 | $(tests_targets): %: %.o $(tests_objs) | prepare |
7d5e61a6 | 175 | $(E)echo LD $(LDFLAGS) -o $@ $< "..." $(LIBS) |
9b0a0ba9 OZ |
176 | $(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LIBS) |
177 | ||
7d5e61a6 OZ |
178 | # Hack to avoid problems with tests linking everything |
179 | $(tests_targets): LIBS += $(DAEMON_LIBS) | |
180 | ||
9b0a0ba9 OZ |
181 | $(tests_targets_ok): %.ok: % |
182 | $(Q)$* 2>/dev/null && touch $*.ok | |
183 | ||
184 | test: testsclean check | |
185 | check: tests tests_run | |
186 | tests: $(tests_targets) | |
187 | tests_run: $(tests_targets_ok) | |
188 | ||
b7482209 MM |
189 | STATIC_CHECKERS_ENABLE := nullability.NullableDereferenced nullability.NullablePassedToNonnull nullability.NullableReturnedFromNonnull optin.portability.UnixAPI valist.CopyToSelf valist.Uninitialized valist.Unterminated |
190 | STATIC_CHECKERS_DISABLE := deadcode.DeadStores | |
a08853a2 | 191 | STATIC_SCAN_FLAGS := -o $(objdir)/static-scan/ $(addprefix -enable-checker ,$(STATIC_CHECKERS_ENABLE)) $(addprefix -disable-checker ,$(STATIC_CHECKERS_DISABLE)) |
59a86cbc MM |
192 | |
193 | static-scan: | |
194 | $(E)echo Running static code analysis | |
195 | $(Q)$(MAKE) clean | |
196 | $(Q)scan-build $(STATIC_SCAN_FLAGS) $(MAKE) -$(MAKEFLAGS) | |
197 | ||
7152e5ef | 198 | tags: |
a40ddf5c | 199 | cd $(srcdir) ; etags -lc `find $(dirs) -name '*.[chY]'` |
7152e5ef | 200 | |
d5144ea9 | 201 | cscope: |
a40ddf5c | 202 | cd $(srcdir) ; find $(dirs) -name '*.[chY]' > cscope.files ; cscope -b |
d5144ea9 | 203 | |
7152e5ef JMM |
204 | # Install |
205 | ||
206 | install: all | |
d0b45978 | 207 | $(INSTALL) -d $(DESTDIR)/$(sbindir) $(DESTDIR)/$(sysconfdir) $(DESTDIR)/$(runstatedir) |
01dd78f9 OZ |
208 | for BIN in bird @CLIENT@ ; do \ |
209 | $(INSTALL_PROGRAM) $(exedir)/$$BIN $(DESTDIR)/$(sbindir)/$$BIN ; \ | |
210 | done | |
7152e5ef JMM |
211 | if ! test -f $(DESTDIR)/@CONFIG_FILE@ ; then \ |
212 | $(INSTALL_DATA) $(srcdir)/doc/bird.conf.example $(DESTDIR)/@CONFIG_FILE@ ; \ | |
213 | else \ | |
214 | echo "Not overwriting old bird.conf" ; \ | |
215 | fi | |
216 | ||
217 | install-docs: | |
218 | $(INSTALL) -d $(DESTDIR)/$(docdir) | |
219 | $(INSTALL_DATA) $(objdir)/doc/{bird,prog}{,-*}.html $(DESTDIR)/$(docdir)/ | |
220 | ||
221 | # Cleanup | |
222 | clean:: | |
54234c9e | 223 | rm -f $(objdir)/sysdep/paths.h $(objdir)/nest/proto-build.c |
7152e5ef JMM |
224 | rm -f $(addprefix $(exedir)/,bird birdc birdcl) |
225 | find $(objdir) -name "*.[od]" -exec rm -f '{}' '+' | |
226 | ||
9b0a0ba9 OZ |
227 | testsclean: |
228 | rm -f $(tests_targets_ok) | |
229 | ||
7152e5ef JMM |
230 | ifeq ($(objdir),obj) |
231 | distclean: clean | |
232 | rm -rf $(objdir) | |
233 | rm -f config.log config.status configure Makefile | |
234 | else | |
235 | distclean: clean | |
236 | rm -rf * .dir-stamp | |
237 | rm -f config.log config.status configure Makefile | |
238 | endif |