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: M4FLAGS=@M4FLAGS@
13: BISONFLAGS=@BISONFLAGS@
14: LIBS=@LIBS@
15: DAEMON_LIBS=@DAEMON_LIBS@
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
28: protocols=@protocols@
29:
30: prefix=@prefix@
31: exec_prefix=@exec_prefix@
32: bindir=@bindir@
33: sbindir=@sbindir@
34: sysconfdir=@sysconfdir@
35: localstatedir=@localstatedir@
36: runstatedir=@runstatedir@
37: docdir=@prefix@/doc
38:
39: srcdir := @srcdir@
40: objdir := @objdir@
41: exedir := @exedir@
42:
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:
48: ifeq ($(objdir),.)
49: objdir := $(realpath .)
50: endif
51:
52: ifeq ($(VERBOSE),)
53: E:=@
54: Q:=@
55: else
56: E:=@\#
57: Q:=
58: endif
59:
60: ifneq ($(COLOR),)
61: CFLAGS += -fdiagnostics-color=always
62: endif
63:
64: # Meta rules
65: docgoals := docs userdocs progdocs
66: testgoals := check test tests tests_run
67: cleangoals := clean distclean testsclean
68: .PHONY: all daemon cli $(docgoals) $(testgoals) $(cleangoals) tags cscope prepare
69:
70: all: daemon cli
71:
72: daemon: $(daemon)
73: cli: $(client)
74:
75: $(daemon): LIBS += $(DAEMON_LIBS)
76:
77: # Include directories
78: dirs := client conf doc filter lib nest test $(addprefix proto/,$(protocols)) @sysdep_dirs@
79:
80: # conf/Makefile declarations needed for all other modules
81: conf-lex-targets := $(addprefix $(objdir)/conf/,cf-lex.o)
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))
86: tests-target-files = $(patsubst %.c,$(o)%,$(tests_src))
87:
88: all-daemon = $(daemon): $(obj)
89: all-client = $(client): $(obj)
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:
105: # Include main Makefiles of the directories
106: include $(addsuffix /Makefile,$(addprefix $(srcdir)/,$(dirs)))
107:
108: # Generic rules
109: # Object file rules
110: $(objdir)/%.o: $(srcdir)/%.c | prepare
111: $(E)echo CC -o $@ -c $<
112: $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
113:
114: $(objdir)/%.o: $(objdir)/%.c | prepare
115: $(E)echo CC -o $@ -c $<
116: $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
117:
118: # Debug: Preprocessed source rules
119: $(objdir)/%.E: $(srcdir)/%.c | prepare
120: $(E)echo CC -o $@ -E $<
121: $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -E $<
122:
123: $(objdir)/%.E: $(objdir)/%.c | prepare
124: $(E)echo CC -o $@ -E $<
125: $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -E $<
126:
127: # Debug: Assembler object rules
128: $(objdir)/%.S: $(srcdir)/%.c | prepare
129: $(E)echo CC -o $@ -S $<
130: $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -S $<
131:
132: $(objdir)/%.S: $(objdir)/%.c | prepare
133: $(E)echo CC -o $@ -S $<
134: $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -S $<
135:
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
148:
149: # Rule for pre-generating all generated includables
150: # before compiling any C file
151: prepare: $(objdir)/sysdep/paths.h | $(objdir)/.dir-stamp
152:
153: $(objdir)/.dir-stamp: Makefile
154: $(E)echo MKDIR -p $(addprefix $(objdir)/,$(dirs) doc)
155: $(Q)mkdir -p $(addprefix $(objdir)/,$(dirs) doc)
156: $(Q)touch $@
157:
158: $(client) $(daemon):
159: $(E)echo LD $(LDFLAGS) -o $@ $^ $(LIBS)
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:
168: # Unit tests rules
169:
170: tests_targets_ok = $(addsuffix .ok,$(tests_targets))
171:
172: $(tests_targets): %: %.o $(tests_objs) | prepare
173: $(E)echo LD $(LDFLAGS) -o $@ $< "..." $(LIBS)
174: $(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
175:
176: # Hack to avoid problems with tests linking everything
177: $(tests_targets): LIBS += $(DAEMON_LIBS)
178:
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:
187: tags:
188: cd $(srcdir) ; etags -lc `find $(dirs) -name *.[chY]`
189:
190: cscope:
191: cd $(srcdir) ; find $(dirs) -name *.[chY] > cscope.files ; cscope -b
192:
193: # Install
194:
195: install: all
196: $(INSTALL) -d $(DESTDIR)/$(sbindir) $(DESTDIR)/$(sysconfdir) $(DESTDIR)/$(runstatedir)
197: for BIN in bird @CLIENT@ ; do \
198: $(INSTALL_PROGRAM) $(exedir)/$$BIN $(DESTDIR)/$(sbindir)/$$BIN ; \
199: done
200: $(INSTALL_DATA) $(srcdir)/doc/bird.conf.example $(DESTDIR)/@CONFIG_FILE@.sample ; \
201:
202: install-docs:
203: $(INSTALL) -d $(DESTDIR)/$(docdir)
204: $(INSTALL_DATA) $(objdir)/doc/{bird,prog}{,-*}.html $(DESTDIR)/$(docdir)/
205:
206: # Cleanup
207: clean::
208: rm -f $(objdir)/sysdep/paths.h
209: rm -f $(addprefix $(exedir)/,bird birdc birdcl)
210: find $(objdir) -name "*.[od]" -exec rm -f '{}' '+'
211:
212: testsclean:
213: rm -f $(tests_targets_ok)
214:
215: ifeq ($(objdir),obj)
216: distclean: clean
217: rm -rf $(objdir)
218: rm -f config.log config.status configure Makefile
219: else
220: distclean: clean
221: rm -rf * .dir-stamp
222: rm -f config.log config.status configure Makefile
223: endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>