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