Statistics
| Branch: | Revision:

iof-bird / bird-2.0.1 / Makefile @ 6b3f1a54

History | View | Annotate | Download (5.12 KB)

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) 
10
CFLAGS=$(CPPFLAGS) -g -O2 -pthread -Wall -Wextra -Wstrict-prototypes -Wno-parentheses -Wno-pointer-sign -Wno-missing-field-initializers -fno-strict-aliasing -fno-strict-overflow
11
LDFLAGS= -pthread
12
LIBS=
13
DAEMON_LIBS=
14
CLIENT_LIBS=-lreadline  -ltinfo 
15
CC=gcc
16
M4=m4
17
BISON=bison
18
FLEX=flex
19
RANLIB=ranlib
20
INSTALL=/usr/bin/install -c
21
INSTALL_PROGRAM=${INSTALL}
22
INSTALL_DATA=${INSTALL} -m 644
23

    
24
git-label:=$(strip $(shell git describe --always --dirty=-x 2>/dev/null))
25
ifneq ($(git-label),)
26
        CFLAGS += -DGIT_LABEL="$(git-label)"
27
endif
28

    
29
client=$(addprefix $(exedir)/,birdcl birdc)
30
daemon=$(exedir)/bird
31
protocols=bfd babel bgp ospf pipe radv rip static
32

    
33
prefix=/usr/local
34
exec_prefix=${prefix}
35
bindir=${exec_prefix}/bin
36
sbindir=${exec_prefix}/sbin
37
sysconfdir=${prefix}/etc
38
localstatedir=${prefix}/var
39
docdir=/usr/local/doc
40

    
41
srcdir := .
42
objdir := obj
43
exedir := .
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
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/linux sysdep/unix 
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

    
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

    
108
$(objdir)/%.S: $(srcdir)/%.c $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
109
	$(E)echo CC -o $@ -S $<
110
	$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -S $<
111

    
112
$(objdir)/%.S: $(objdir)/%.c $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
113
	$(E)echo CC -o $@ -S $<
114
	$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -S $<
115

    
116

    
117

    
118
$(objdir)/.dir-stamp:
119
	$(E)echo MKDIR -p $(addprefix $(objdir)/,$(dirs) doc)
120
	$(Q)mkdir -p $(addprefix $(objdir)/,$(dirs) doc)
121
	$(Q)touch $@
122

    
123
$(client) $(daemon):
124
	$(E)echo LD $(LDFLAGS) -o $@ $^ $(LIBS)
125
	$(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
126

    
127
$(objdir)/sysdep/paths.h: Makefile
128
	echo  >$@ "/* Generated by Makefile, don't edit manually! */"
129
	echo >>$@ "#define PATH_CONFIG_FILE \"$(sysconfdir)/bird.conf\""
130
	echo >>$@ "#define PATH_CONTROL_SOCKET \"$(localstatedir)/run/bird.ctl\""
131
	if test -n "/etc/iproute2" ; then echo >>$@ "#define PATH_IPROUTE_DIR \"/etc/iproute2\"" ; fi
132

    
133
# Unit tests rules
134

    
135
tests_targets_ok = $(addsuffix .ok,$(tests_targets))
136

    
137
$(tests_targets): %: %.o $(tests_objs)
138
	$(E)echo LD $(LDFLAGS) -o $@ $< "..." $(LIBS)
139
	$(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
140

    
141
# Hack to avoid problems with tests linking everything
142
$(tests_targets): LIBS += $(DAEMON_LIBS)
143

    
144
$(tests_targets_ok): %.ok: %
145
	$(Q)$* 2>/dev/null && touch $*.ok
146

    
147
test: testsclean check
148
check: tests tests_run
149
tests: $(tests_targets)
150
tests_run: $(tests_targets_ok)
151

    
152
# Finally include the computed dependencies
153

    
154
ifneq ($(filter-out $(cleangoals),$(MAKECMDGOALS)),)
155
-include $(shell find $(objdir) -name "*.d")
156
endif
157

    
158
ifeq ($(MAKECMDGOALS),)
159
-include $(shell find $(objdir) -name "*.d")
160
endif
161

    
162
tags:
163
	cd $(srcdir) ; etags -lc `find $(dirs) -name *.[chY]`
164

    
165
# Install
166

    
167
install: all
168
	$(INSTALL) -d $(DESTDIR)/$(sbindir) $(DESTDIR)/$(sysconfdir) $(DESTDIR)/$(localstatedir)/run
169
	$(INSTALL_PROGRAM) $(exedir)/bird $(DESTDIR)/$(sbindir)/bird
170
	$(INSTALL_PROGRAM) $(exedir)/birdcl $(DESTDIR)/$(sbindir)/birdcl
171
	if test -n "birdcl birdc" ; then								\
172
		$(INSTALL_PROGRAM) $(exedir)/birdc $(DESTDIR)/$(sbindir)/birdc ;		\
173
	fi
174
	if ! test -f $(DESTDIR)/$(sysconfdir)/bird.conf ; then						\
175
		$(INSTALL_DATA) $(srcdir)/doc/bird.conf.example $(DESTDIR)/$(sysconfdir)/bird.conf ;	\
176
	else											\
177
		echo "Not overwriting old bird.conf" ;						\
178
	fi
179

    
180
install-docs:
181
	$(INSTALL) -d $(DESTDIR)/$(docdir)
182
	$(INSTALL_DATA) $(objdir)/doc/{bird,prog}{,-*}.html $(DESTDIR)/$(docdir)/
183

    
184
# Cleanup
185
clean::
186
	rm -f $(objdir)/sysdep/paths.h
187
	rm -f $(addprefix $(exedir)/,bird birdc birdcl)
188
	find $(objdir) -name "*.[od]" -exec rm -f '{}' '+'
189

    
190
testsclean:
191
	rm -f $(tests_targets_ok)
192

    
193
ifeq ($(objdir),obj)
194
distclean: clean
195
	rm -rf $(objdir)
196
	rm -f config.log config.status configure Makefile
197
else
198
distclean: clean
199
	rm -rf * .dir-stamp
200
	rm -f config.log config.status configure Makefile
201
endif