]> git.ipfire.org Git - thirdparty/bird.git/blobdiff - Makefile.in
Filter: Some people can't pronounce "postfixify" correctly. Let's try "linearize...
[thirdparty/bird.git] / Makefile.in
index cee217be9480ae5c34239b13f19b760a48747c8c..e6dbd572fb53a0f854f2e43b084406fecdc2c8d1 100644 (file)
@@ -9,7 +9,10 @@ MAKEFLAGS += -r
 CPPFLAGS=-I$(objdir) -I$(srcdir) @CPPFLAGS@
 CFLAGS=$(CPPFLAGS) @CFLAGS@
 LDFLAGS=@LDFLAGS@
+M4FLAGS=@M4FLAGS@
+BISONFLAGS=@BISONFLAGS@
 LIBS=@LIBS@
+DAEMON_LIBS=@DAEMON_LIBS@
 CLIENT_LIBS=@CLIENT_LIBS@
 CC=@CC@
 M4=@M4@
@@ -22,7 +25,7 @@ INSTALL_DATA=@INSTALL_DATA@
 
 client=$(addprefix $(exedir)/,@CLIENT@)
 daemon=$(exedir)/bird
-protocols  = @protocols@
+protocols=@protocols@
 
 prefix=@prefix@
 exec_prefix=@exec_prefix@
@@ -30,12 +33,18 @@ bindir=@bindir@
 sbindir=@sbindir@
 sysconfdir=@sysconfdir@
 localstatedir=@localstatedir@
+runstatedir=@runstatedir@
 docdir=@prefix@/doc
 
 srcdir := @srcdir@
 objdir := @objdir@
 exedir := @exedir@
 
+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
+
 ifeq ($(objdir),.)
   objdir := $(realpath .)
 endif
@@ -48,25 +57,36 @@ else
   Q:=
 endif
 
+ifneq ($(COLOR),)
+  CFLAGS += -fdiagnostics-color=always
+endif
+
 # Meta rules
-cleangoals := clean distclean
 docgoals := docs userdocs progdocs
-.PHONY: all daemon cli $(cleangoals) $(docgoals) tags
+testgoals := check test tests tests_run
+cleangoals := clean distclean testsclean
+.PHONY: all daemon cli $(docgoals) $(testgoals) $(cleangoals) tags cscope prepare
+
 all: daemon cli
 
 daemon: $(daemon)
 cli: $(client)
 
+$(daemon): LIBS += $(DAEMON_LIBS)
+
 # Include directories
-dirs := client conf doc filter lib nest $(addprefix proto/,$(protocols)) @sysdep_dirs@
+dirs := client conf doc filter lib nest test $(addprefix proto/,$(protocols)) @sysdep_dirs@
 
+# conf/Makefile declarations needed for all other modules
+conf-lex-targets := $(addprefix $(objdir)/conf/,cf-lex.o)
 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))
+tests-target-files = $(patsubst %.c,$(o)%,$(tests_src))
 
-all-daemon = $(exedir)/bird: $(obj)
-all-client = $(exedir)/birdc $(exedir)/birdcl: $(obj)
+all-daemon = $(daemon): $(obj)
+all-client = $(client): $(obj)
 
 s = $(dir $(lastword $(MAKEFILE_LIST)))
 ifeq ($(srcdir),.)
@@ -82,19 +102,55 @@ endef
 
 clean = $(eval $(call clean_in,$(1)))
 
+# Include main Makefiles of the directories
 include $(addsuffix /Makefile,$(addprefix $(srcdir)/,$(dirs)))
 
 # Generic rules
-
-$(objdir)/%.o: $(srcdir)/%.c $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
+# Object file rules
+$(objdir)/%.o: $(srcdir)/%.c | prepare
        $(E)echo CC -o $@ -c $<
        $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
 
-$(objdir)/%.o: $(objdir)/%.c $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
+$(objdir)/%.o: $(objdir)/%.c | prepare
        $(E)echo CC -o $@ -c $<
        $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
 
-$(objdir)/.dir-stamp:
+# Debug: Preprocessed source rules
+$(objdir)/%.E: $(srcdir)/%.c | prepare
+       $(E)echo CC -o $@ -E $<
+       $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -E $<
+
+$(objdir)/%.E: $(objdir)/%.c | prepare
+       $(E)echo CC -o $@ -E $<
+       $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -E $<
+
+# Debug: Assembler object rules
+$(objdir)/%.S: $(srcdir)/%.c | prepare
+       $(E)echo CC -o $@ -S $<
+       $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -S $<
+
+$(objdir)/%.S: $(objdir)/%.c | prepare
+       $(E)echo CC -o $@ -S $<
+       $(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -S $<
+
+# 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
+
+# Rule for pre-generating all generated includables
+# before compiling any C file
+prepare: $(objdir)/sysdep/paths.h | $(objdir)/.dir-stamp
+
+$(objdir)/.dir-stamp: Makefile
        $(E)echo MKDIR -p $(addprefix $(objdir)/,$(dirs) doc)
        $(Q)mkdir -p $(addprefix $(objdir)/,$(dirs) doc)
        $(Q)touch $@
@@ -109,28 +165,38 @@ $(objdir)/sysdep/paths.h: Makefile
        echo >>$@ "#define PATH_CONTROL_SOCKET \"@CONTROL_SOCKET@\""
        if test -n "@iproutedir@" ; then echo >>$@ "#define PATH_IPROUTE_DIR \"@iproutedir@\"" ; fi
 
-# Finally include the computed dependencies
+# Unit tests rules
 
-ifneq ($(filter-out $(cleangoals),$(MAKECMDGOALS)),)
--include $(shell find $(objdir) -name "*.d")
-endif
+tests_targets_ok = $(addsuffix .ok,$(tests_targets))
 
-ifeq ($(MAKECMDGOALS),)
--include $(shell find $(objdir) -name "*.d")
-endif
+$(tests_targets): %: %.o $(tests_objs) | prepare
+       $(E)echo LD $(LDFLAGS) -o $@ $< "..." $(LIBS)
+       $(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
+
+# Hack to avoid problems with tests linking everything
+$(tests_targets): LIBS += $(DAEMON_LIBS)
+
+$(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)
 
 tags:
        cd $(srcdir) ; etags -lc `find $(dirs) -name *.[chY]`
 
+cscope:
+       cd $(srcdir) ; find $(dirs) -name *.[chY] > cscope.files ; cscope -b
+
 # 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
+       $(INSTALL) -d $(DESTDIR)/$(sbindir) $(DESTDIR)/$(sysconfdir) $(DESTDIR)/$(runstatedir)
+       for BIN in bird @CLIENT@ ; do                                                           \
+               $(INSTALL_PROGRAM) $(exedir)/$$BIN $(DESTDIR)/$(sbindir)/$$BIN ;                \
+       done
        if ! test -f $(DESTDIR)/@CONFIG_FILE@ ; then                                            \
                $(INSTALL_DATA) $(srcdir)/doc/bird.conf.example $(DESTDIR)/@CONFIG_FILE@ ;      \
        else                                                                                    \
@@ -147,6 +213,9 @@ clean::
        rm -f $(addprefix $(exedir)/,bird birdc birdcl)
        find $(objdir) -name "*.[od]" -exec rm -f '{}' '+'
 
+testsclean:
+       rm -f $(tests_targets_ok)
+
 ifeq ($(objdir),obj)
 distclean: clean
        rm -rf $(objdir)