]> git.ipfire.org Git - thirdparty/bird.git/blob - Makefile.in
Macro: Added a bunch of dirty C preprocessor tricks
[thirdparty/bird.git] / Makefile.in
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@
12 LIBS=@LIBS@
13 DAEMON_LIBS=@DAEMON_LIBS@
14 CLIENT_LIBS=@CLIENT_LIBS@
15 CC=@CC@
16 M4=@M4@
17 BISON=@BISON@
18 FLEX=@FLEX@
19 RANLIB=@RANLIB@
20 INSTALL=@INSTALL@
21 INSTALL_PROGRAM=@INSTALL_PROGRAM@
22 INSTALL_DATA=@INSTALL_DATA@
23
24 client=$(addprefix $(exedir)/,@CLIENT@)
25 daemon=$(exedir)/bird
26 protocols=@protocols@
27
28 prefix=@prefix@
29 exec_prefix=@exec_prefix@
30 bindir=@bindir@
31 sbindir=@sbindir@
32 sysconfdir=@sysconfdir@
33 localstatedir=@localstatedir@
34 docdir=@prefix@/doc
35
36 srcdir := @srcdir@
37 objdir := @objdir@
38 exedir := @exedir@
39
40 git-label:=$(strip $(shell cd $(srcdir) && [ "$$(git rev-parse --show-toplevel)" = "$$(readlink -f .)" ] && git describe --always --dirty=-x 2>/dev/null))
41 ifneq ($(git-label),)
42 CFLAGS += -DGIT_LABEL="$(git-label)"
43 endif
44
45 ifeq ($(objdir),.)
46 objdir := $(realpath .)
47 endif
48
49 ifeq ($(VERBOSE),)
50 E:=@
51 Q:=@
52 else
53 E:=@\#
54 Q:=
55 endif
56
57 # Meta rules
58 docgoals := docs userdocs progdocs
59 testgoals := check test tests tests_run
60 cleangoals := clean distclean testsclean
61 .PHONY: all daemon cli $(docgoals) $(testgoals) $(cleangoals) tags cscope
62 all: daemon cli
63
64 daemon: $(daemon)
65 cli: $(client)
66
67 $(daemon): LIBS += $(DAEMON_LIBS)
68
69 # Include directories
70 dirs := client conf doc filter lib nest test $(addprefix proto/,$(protocols)) @sysdep_dirs@
71
72 conf-y-targets := $(addprefix $(objdir)/conf/,cf-parse.y keywords.h commands.h)
73 cf-local = $(conf-y-targets): $(s)config.Y
74
75 src-o-files = $(patsubst %.c,$(o)%.o,$(src))
76 tests-target-files = $(patsubst %.c,$(o)%,$(tests_src))
77
78 all-daemon = $(daemon): $(obj)
79 all-client = $(client): $(obj)
80
81 s = $(dir $(lastword $(MAKEFILE_LIST)))
82 ifeq ($(srcdir),.)
83 o = $(objdir)/$(s)
84 else
85 o = $(patsubst $(srcdir)%,$(objdir)%,$(s))
86 endif
87
88 define clean_in =
89 clean::
90 rm -f $(addprefix $(o),$(1))
91 endef
92
93 clean = $(eval $(call clean_in,$(1)))
94
95 include $(addsuffix /Makefile,$(addprefix $(srcdir)/,$(dirs)))
96
97 # Generic rules
98 # Object file rules
99 $(objdir)/%.o: $(srcdir)/%.c $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
100 $(E)echo CC -o $@ -c $<
101 $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
102
103 $(objdir)/%.o: $(objdir)/%.c $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
104 $(E)echo CC -o $@ -c $<
105 $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
106
107 # Debug: Preprocessed source rules
108 $(objdir)/%.E: $(srcdir)/%.c $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
109 $(E)echo CC -o $@ -E $<
110 $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -E $<
111
112 $(objdir)/%.E: $(objdir)/%.c $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
113 $(E)echo CC -o $@ -E $<
114 $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -E $<
115
116 # Debug: Assembler object rules
117 $(objdir)/%.S: $(srcdir)/%.c $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
118 $(E)echo CC -o $@ -S $<
119 $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -S $<
120
121 $(objdir)/%.S: $(objdir)/%.c $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
122 $(E)echo CC -o $@ -S $<
123 $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -S $<
124
125
126
127 $(objdir)/.dir-stamp:
128 $(E)echo MKDIR -p $(addprefix $(objdir)/,$(dirs) doc)
129 $(Q)mkdir -p $(addprefix $(objdir)/,$(dirs) doc)
130 $(Q)touch $@
131
132 $(client) $(daemon):
133 $(E)echo LD $(LDFLAGS) -o $@ $^ $(LIBS)
134 $(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
135
136 $(objdir)/sysdep/paths.h: Makefile
137 echo >$@ "/* Generated by Makefile, don't edit manually! */"
138 echo >>$@ "#define PATH_CONFIG_FILE \"@CONFIG_FILE@\""
139 echo >>$@ "#define PATH_CONTROL_SOCKET \"@CONTROL_SOCKET@\""
140 if test -n "@iproutedir@" ; then echo >>$@ "#define PATH_IPROUTE_DIR \"@iproutedir@\"" ; fi
141
142 # Unit tests rules
143
144 tests_targets_ok = $(addsuffix .ok,$(tests_targets))
145
146 $(tests_targets): %: %.o $(tests_objs)
147 $(E)echo LD $(LDFLAGS) -o $@ $< "..." $(LIBS)
148 $(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
149
150 # Hack to avoid problems with tests linking everything
151 $(tests_targets): LIBS += $(DAEMON_LIBS)
152
153 $(tests_targets_ok): %.ok: %
154 $(Q)$* 2>/dev/null && touch $*.ok
155
156 test: testsclean check
157 check: tests tests_run
158 tests: $(tests_targets)
159 tests_run: $(tests_targets_ok)
160
161 # Finally include the computed dependencies
162
163 ifneq ($(filter-out $(cleangoals),$(MAKECMDGOALS)),)
164 -include $(shell find $(objdir) -name "*.d")
165 endif
166
167 ifeq ($(MAKECMDGOALS),)
168 -include $(shell find $(objdir) -name "*.d")
169 endif
170
171 tags:
172 cd $(srcdir) ; etags -lc `find $(dirs) -name *.[chY]`
173
174 cscope:
175 cd $(srcdir) ; find $(dirs) -name *.[chY] > cscope.files ; cscope -b
176
177 # Install
178
179 install: all
180 $(INSTALL) -d $(DESTDIR)/$(sbindir) $(DESTDIR)/$(sysconfdir) $(DESTDIR)/@runtimedir@
181 $(INSTALL_PROGRAM) $(exedir)/bird $(DESTDIR)/$(sbindir)/bird
182 $(INSTALL_PROGRAM) $(exedir)/birdcl $(DESTDIR)/$(sbindir)/birdcl
183 if test -n "@CLIENT@" ; then \
184 $(INSTALL_PROGRAM) $(exedir)/birdc $(DESTDIR)/$(sbindir)/birdc ; \
185 fi
186 if ! test -f $(DESTDIR)/@CONFIG_FILE@ ; then \
187 $(INSTALL_DATA) $(srcdir)/doc/bird.conf.example $(DESTDIR)/@CONFIG_FILE@ ; \
188 else \
189 echo "Not overwriting old bird.conf" ; \
190 fi
191
192 install-docs:
193 $(INSTALL) -d $(DESTDIR)/$(docdir)
194 $(INSTALL_DATA) $(objdir)/doc/{bird,prog}{,-*}.html $(DESTDIR)/$(docdir)/
195
196 # Cleanup
197 clean::
198 rm -f $(objdir)/sysdep/paths.h
199 rm -f $(addprefix $(exedir)/,bird birdc birdcl)
200 find $(objdir) -name "*.[od]" -exec rm -f '{}' '+'
201
202 testsclean:
203 rm -f $(tests_targets_ok)
204
205 ifeq ($(objdir),obj)
206 distclean: clean
207 rm -rf $(objdir)
208 rm -f config.log config.status configure Makefile
209 else
210 distclean: clean
211 rm -rf * .dir-stamp
212 rm -f config.log config.status configure Makefile
213 endif