Makefile.in 4.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
# 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@
LIBS=@LIBS@
13
DAEMON_LIBS=@DAEMON_LIBS@
14 15 16 17 18 19 20 21 22 23
CLIENT_LIBS=@CLIENT_LIBS@
CC=@CC@
M4=@M4@
BISON=@BISON@
FLEX=@FLEX@
RANLIB=@RANLIB@
INSTALL=@INSTALL@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
INSTALL_DATA=@INSTALL_DATA@

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

29 30
client=$(addprefix $(exedir)/,@CLIENT@)
daemon=$(exedir)/bird
31
protocols=@protocols@
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
sbindir=@sbindir@
sysconfdir=@sysconfdir@
localstatedir=@localstatedir@
docdir=@prefix@/doc

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

ifeq ($(objdir),.)
  objdir := $(realpath .)
endif

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

# Meta rules
docgoals := docs userdocs progdocs
59 60 61
testgoals := check test tests tests_run
cleangoals := clean distclean testsclean
.PHONY: all daemon cli $(docgoals) $(testgoals) $(cleangoals) tags
62 63 64 65 66
all: daemon cli

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

67 68
$(daemon): LIBS += $(DAEMON_LIBS)

69
# Include directories
70
dirs := client conf doc filter lib nest test $(addprefix proto/,$(protocols)) @sysdep_dirs@
71 72 73 74 75

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))
76
tests-target-files = $(patsubst %.c,$(o)%,$(tests_src))
77

78 79
all-daemon = $(daemon): $(obj)
all-client = $(client): $(obj)
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

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

$(objdir)/%.o: $(srcdir)/%.c $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
100
	$(E)echo CC -o $@ -c $<
101 102 103
	$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<

$(objdir)/%.o: $(objdir)/%.c $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
104
	$(E)echo CC -o $@ -c $<
105 106
	$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<

107 108 109 110 111 112 113 114 115 116 117

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

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



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

$(client) $(daemon):
124
	$(E)echo LD $(LDFLAGS) -o $@ $^ $(LIBS)
125 126 127 128 129 130 131 132
	$(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

133 134 135 136 137
# Unit tests rules

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

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

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

144 145 146 147 148 149 150 151
$(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)

152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
# Finally include the computed dependencies

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

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

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

# Install

install: all
	$(INSTALL) -d $(DESTDIR)/$(sbindir) $(DESTDIR)/$(sysconfdir) $(DESTDIR)/@runtimedir@
	$(INSTALL_PROGRAM) $(exedir)/bird $(DESTDIR)/$(sbindir)/bird
	$(INSTALL_PROGRAM) $(exedir)/birdcl $(DESTDIR)/$(sbindir)/birdcl
	if test -n "@CLIENT@" ; then								\
		$(INSTALL_PROGRAM) $(exedir)/birdc $(DESTDIR)/$(sbindir)/birdc ;		\
	fi
	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 '{}' '+'

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

193 194 195 196 197 198 199 200 201
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