Makefile.in 5.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
# Makefile for the BIRD Internet Routing Daemon
# (c) 1999--2000 Martin Mares <mj@ucw.cz>
# (c) 2016       Jan Moskyto Matejka <mq@ucw.cz>

# Disable build-in rules
MAKEFLAGS += -r

# Variable definitions
CPPFLAGS=-I$(objdir) -I$(srcdir) @CPPFLAGS@
CFLAGS=$(CPPFLAGS) @CFLAGS@
LDFLAGS=@LDFLAGS@
12
M4FLAGS=@M4FLAGS@
13
BISONFLAGS=@BISONFLAGS@
14
LIBS=@LIBS@
15
DAEMON_LIBS=@DAEMON_LIBS@
16 17 18 19 20 21 22 23 24 25 26 27
CLIENT_LIBS=@CLIENT_LIBS@
CC=@CC@
M4=@M4@
BISON=@BISON@
FLEX=@FLEX@
RANLIB=@RANLIB@
INSTALL=@INSTALL@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
INSTALL_DATA=@INSTALL_DATA@

client=$(addprefix $(exedir)/,@CLIENT@)
daemon=$(exedir)/bird
28
protocols=@protocols@
29 30 31 32 33 34 35

prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
sbindir=@sbindir@
sysconfdir=@sysconfdir@
localstatedir=@localstatedir@
36
runstatedir=@runstatedir@
37 38 39 40 41 42
docdir=@prefix@/doc

srcdir := @srcdir@
objdir := @objdir@
exedir := @exedir@

43 44 45 46 47
git-label:=$(strip $(shell cd $(srcdir) && [ "$$(git rev-parse --show-toplevel)" = "$$(readlink -f .)" ] && git describe --always --dirty=-x 2>/dev/null))
ifneq ($(git-label),)
        CFLAGS += -DGIT_LABEL="$(git-label)"
endif

48 49 50 51 52
ifeq ($(objdir),.)
  objdir := $(realpath .)
endif

ifeq ($(VERBOSE),)
53
  E:=@
54 55
  Q:=@
else
56
  E:=@\#
57 58 59
  Q:=
endif

60 61 62 63
ifneq ($(COLOR),)
  CFLAGS += -fdiagnostics-color=always
endif

64 65
# Meta rules
docgoals := docs userdocs progdocs
66 67
testgoals := check test tests tests_run
cleangoals := clean distclean testsclean
68 69
.PHONY: all daemon cli $(docgoals) $(testgoals) $(cleangoals) tags cscope prepare

70 71 72 73 74
all: daemon cli

daemon: $(daemon)
cli: $(client)

75 76
$(daemon): LIBS += $(DAEMON_LIBS)

77
# Include directories
78
dirs := client conf doc filter lib nest test $(addprefix proto/,$(protocols)) @sysdep_dirs@
79 80 81 82 83

conf-y-targets := $(addprefix $(objdir)/conf/,cf-parse.y keywords.h commands.h)
cf-local = $(conf-y-targets): $(s)config.Y

src-o-files = $(patsubst %.c,$(o)%.o,$(src))
84
tests-target-files = $(patsubst %.c,$(o)%,$(tests_src))
85

86 87
all-daemon = $(daemon): $(obj)
all-client = $(client): $(obj)
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105

s = $(dir $(lastword $(MAKEFILE_LIST)))
ifeq ($(srcdir),.)
  o = $(objdir)/$(s)
else
  o = $(patsubst $(srcdir)%,$(objdir)%,$(s))
endif

define clean_in =
clean::
	rm -f $(addprefix $(o),$(1))
endef

clean = $(eval $(call clean_in,$(1)))

include $(addsuffix /Makefile,$(addprefix $(srcdir)/,$(dirs)))

# Generic rules
106
# Object file rules
107
$(objdir)/%.o: $(srcdir)/%.c | prepare
108
	$(E)echo CC -o $@ -c $<
109 110
	$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<

111
$(objdir)/%.o: $(objdir)/%.c | prepare
112
	$(E)echo CC -o $@ -c $<
113 114
	$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<

115
# Debug: Preprocessed source rules
116
$(objdir)/%.E: $(srcdir)/%.c | prepare
117 118 119
	$(E)echo CC -o $@ -E $<
	$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -E $<

120
$(objdir)/%.E: $(objdir)/%.c | prepare
121 122
	$(E)echo CC -o $@ -E $<
	$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -E $<
123

124
# Debug: Assembler object rules
125
$(objdir)/%.S: $(srcdir)/%.c | prepare
126 127 128
	$(E)echo CC -o $@ -S $<
	$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -S $<

129
$(objdir)/%.S: $(objdir)/%.c | prepare
130 131 132
	$(E)echo CC -o $@ -S $<
	$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -S $<

133 134 135 136 137 138 139 140 141 142 143 144
# Finally include the computed dependencies:
DEPS = $(shell find $(objdir) -name '*.d')

# ## if there is at least one non-clean goal
ifneq ($(filter-out $(cleangoals),$(MAKECMDGOALS)),)
-include $(DEPS)
endif

# ## if the implicit goal is called
ifeq ($(MAKECMDGOALS),)
-include $(DEPS)
endif
145

146 147 148
# Rule for pre-generating all generated includables
# before compiling any C file
prepare: $(objdir)/sysdep/paths.h | $(objdir)/.dir-stamp
149

150
$(objdir)/.dir-stamp: Makefile
151
	$(E)echo MKDIR -p $(addprefix $(objdir)/,$(dirs) doc)
152 153 154 155
	$(Q)mkdir -p $(addprefix $(objdir)/,$(dirs) doc)
	$(Q)touch $@

$(client) $(daemon):
156
	$(E)echo LD $(LDFLAGS) -o $@ $^ $(LIBS)
157 158 159 160 161 162 163 164
	$(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)

$(objdir)/sysdep/paths.h: Makefile
	echo  >$@ "/* Generated by Makefile, don't edit manually! */"
	echo >>$@ "#define PATH_CONFIG_FILE \"@CONFIG_FILE@\""
	echo >>$@ "#define PATH_CONTROL_SOCKET \"@CONTROL_SOCKET@\""
	if test -n "@iproutedir@" ; then echo >>$@ "#define PATH_IPROUTE_DIR \"@iproutedir@\"" ; fi

165 166 167 168
# Unit tests rules

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

169
$(tests_targets): %: %.o $(tests_objs) | prepare
170
	$(E)echo LD $(LDFLAGS) -o $@ $< "..." $(LIBS)
171 172
	$(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)

173 174 175
# Hack to avoid problems with tests linking everything
$(tests_targets): LIBS += $(DAEMON_LIBS)

176 177 178 179 180 181 182 183
$(tests_targets_ok): %.ok: %
	$(Q)$* 2>/dev/null && touch $*.ok

test: testsclean check
check: tests tests_run
tests: $(tests_targets)
tests_run: $(tests_targets_ok)

184 185 186
tags:
	cd $(srcdir) ; etags -lc `find $(dirs) -name *.[chY]`

187 188 189
cscope:
	cd $(srcdir) ; find $(dirs) -name *.[chY] > cscope.files ; cscope -b

190 191 192
# Install

install: all
193
	$(INSTALL) -d $(DESTDIR)/$(sbindir) $(DESTDIR)/$(sysconfdir) $(DESTDIR)/$(runstatedir)
194 195 196
	for BIN in bird @CLIENT@ ; do								\
		$(INSTALL_PROGRAM) $(exedir)/$$BIN $(DESTDIR)/$(sbindir)/$$BIN ;		\
	done
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
	if ! test -f $(DESTDIR)/@CONFIG_FILE@ ; then						\
		$(INSTALL_DATA) $(srcdir)/doc/bird.conf.example $(DESTDIR)/@CONFIG_FILE@ ;	\
	else											\
		echo "Not overwriting old bird.conf" ;						\
	fi

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

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

213 214 215
testsclean:
	rm -f $(tests_targets_ok)

216 217 218 219 220 221 222 223 224
ifeq ($(objdir),obj)
distclean: clean
	rm -rf $(objdir)
	rm -f config.log config.status configure Makefile
else
distclean: clean
	rm -rf * .dir-stamp
	rm -f config.log config.status configure Makefile
endif