New makefiles. Includes support for out-of-source-tree builds.

This commit is contained in:
Martin Mares 1999-01-10 00:18:32 +00:00
parent 2f9bcf9713
commit 49e7e5ee0b
16 changed files with 211 additions and 140 deletions

View file

@ -1,44 +0,0 @@
# Makefile for the BIRD Internet Routing Daemon
# (c) 1998 Martin Mares <mj@ucw.cz>
TOPDIR=$(shell pwd)
OBJDIR=obj
CPPFLAGS=-I$(TOPDIR)/$(OBJDIR) -I$(TOPDIR)
OPT=-O2
DEBUG=-g#gdb
CFLAGS=$(OPT) $(DEBUG) -Wall -W -Wstrict-prototypes -Wno-unused -Wno-parentheses
PROTOCOLS=rip static
LIBDIRS=sysdep/linux sysdep/unix lib
BASEDIRS=nest $(addprefix proto/,$(PROTOCOLS))
STDDIRS=$(BASEDIRS) $(OBJDIR)/conf
DIRS=$(STDDIRS) $(OBJDIR)/lib
PARTOBJS=$(join $(addsuffix /,$(STDDIRS)),$(subst /,_,$(addsuffix .o,$(STDDIRS))))
LIBS=$(OBJDIR)/lib/birdlib.a
export
all: .dep all-dirs bird
all-dirs:
set -e ; for a in $(DIRS) ; do $(MAKE) -C $$a this ; done
bird: $(PARTOBJS) $(LIBS)
$(CC) $(LDFLAGS) -o $@ $^
.dep:
$(MAKE) dep
dep:
mkdir -p $(OBJDIR)
tools/mergedirs $(OBJDIR) $(LIBDIRS)
# for a in $(STDDIRS) ; do mkdir -p $(OBJDIR)/$$a ; done
set -e ; for a in $(DIRS) ; do $(MAKE) -C $$a dep ; done
touch .dep
clean:
rm -rf obj
rm -f `find . -name "*~" -or -name "*.[oa]" -or -name "\#*\#" -or -name TAGS -or -name core -or -name .depend -or -name .#*`
rm -f bird .dep
rm -f config.log config.cache config.status configure sysdep/autoconf.h

50
Rules
View file

@ -1,50 +0,0 @@
# Makefile for the BIRD Internet Routing Daemon
# (c) 1998 Martin Mares <mj@ucw.cz>
THISDIR=$(shell pwd)
RELDIR=$(subst $(TOPDIR)/,,$(THISDIR))
ONAME=$(subst /,_,$(RELDIR)).o
ifndef SRCS
SRCS=$(subst .o,.c,$(OBJS))
endif
.PHONY: all this dep
all:
@echo "Please run the top-level Makefile instead."
@exit 1
ifdef OBJS
ifdef LIB
this: $(LIB)
$(LIB): $(OBJS)
rm -f $(LIB)
ar rcs $(LIB) $(OBJS)
ranlib $(LIB)
else
this: $(ONAME)
$(ONAME): $(OBJS)
$(LD) -r -o $(ONAME) $(OBJS)
endif
dep: $(SRCS)
rm -f .depend
for a in $(SRCS) ; do gcc $(CPPFLAGS) -MM $$a >>.depend ; done
else
dep:
endif
ifneq ($(wildcard .depend),)
include .depend
endif

1
TODO
View file

@ -1,5 +1,6 @@
Core Core
~~~~ ~~~~
* right usage of DBG vs. debug * right usage of DBG vs. debug
* cleanup debugging calls * cleanup debugging calls
* logging and tracing; use appropriate log levels * logging and tracing; use appropriate log levels

View file

@ -1,24 +1,26 @@
CONFS=$(TOPDIR)/conf/confbase.Y @CONFS@$(addprefix $(TOPDIR)/,$(addsuffix /config.Y,$(BASEDIRS))) source=cf-parse.tab.c cf-lex.c
OBJS=cf-parse.tab.o cf-lex.o root-rel=../
CONF=$(TOPDIR)/conf
include ../Rules
conf-src=$(srcdir)/conf
conf-fragments=$(conf-src)/confbase.Y @CONFS@ $(addsuffix /config.Y,$(static-dir-paths))
ifdef DEBUG ifdef DEBUG
BISON_DEBUG=-t BISON_DEBUG=-t
#FLEX_DEBUG=-d #FLEX_DEBUG=-d
endif endif
include $(TOPDIR)/Rules
cf-parse.tab.c cf-parse-tab.h: cf-parse.y cf-parse.tab.c cf-parse-tab.h: cf-parse.y
bison -bcf-parse -dv -pcf_ $(BISON_DEBUG) cf-parse.y $(BISON) -bcf-parse -dv -pcf_ $(BISON_DEBUG) cf-parse.y
cf-parse.y: $(CONFS) $(CONF)/gen_parser.m4 cf-parse.y: $(conf-fragments) $(conf-src)/gen_parser.m4
m4 -P $(CONF)/gen_parser.m4 $(CONFS) >cf-parse.y $(M4) -P $(conf-src)/gen_parser.m4 $(conf-fragments) >cf-parse.y
keywords.h: $(CONFS) $(CONF)/gen_keywords.m4 keywords.h: $(conf-fragments) $(conf-src)/gen_keywords.m4
m4 -P $(CONF)/gen_keywords.m4 $(CONFS) >keywords.h $(M4) -P $(conf-src)/gen_keywords.m4 $(conf-fragments) >keywords.h
cf-lex.c: cf-lex.l cf-lex.c: cf-lex.l
flex $(FLEX_DEBUG) -sB8 -ocf-lex.c -Pcf_ cf-lex.l $(FLEX) $(FLEX_DEBUG) -sB8 -ocf-lex.c -Pcf_ cf-lex.l
dep: keywords.h depend: keywords.h cf-parse.tab.c cf-lex.c

View file

@ -24,7 +24,7 @@ static struct keyword {
int value; int value;
struct keyword *next; struct keyword *next;
} keyword_list[] = { } keyword_list[] = {
#include "keywords.h" #include "conf/keywords.h"
{ NULL, -1 } }; { NULL, -1 } };
#define KW_HASH_SIZE 64 #define KW_HASH_SIZE 64

View file

@ -10,31 +10,61 @@ AC_ARG_ENABLE(debug,[ --enable-debug enable internal debugging routine
AC_ARG_WITH(sysconfig,[ --with-sysconfig=FILE use specified BIRD system configuration file]) AC_ARG_WITH(sysconfig,[ --with-sysconfig=FILE use specified BIRD system configuration file])
AC_ARG_WITH(protocols,[ --with-protocols=LIST include specified routing protocols (default: rip,static)],,[with_protocols="rip,static"]) AC_ARG_WITH(protocols,[ --with-protocols=LIST include specified routing protocols (default: rip,static)],,[with_protocols="rip,static"])
if test "$srcdir" = . ; then
# Building in current directory => create obj directory holding all objects
objdir=obj
mkdir -p obj
srcdir_rel=..
makefiles="Makefile:tools/Makefile-top.in obj/Makefile:tools/Makefile.in obj/Rules:tools/Rules.in"
exedir=..
else
# Building in separate directory
objdir=.
srcdir_rel=$srcdir
makefiles="Makefile:tools/Makefile.in Rules:tools/Rules.in"
exedir=.
fi
case $srcdir_rel in
/*) srcdir_rel_mf=$srcdir_rel ;;
*) srcdir_rel_mf="\$(root-rel)$srcdir_rel" ;;
esac
AC_SUBST(objdir)
AC_SUBST(exedir)
AC_SUBST(srcdir_rel_mf)
AC_CANONICAL_HOST AC_CANONICAL_HOST
AC_MSG_CHECKING([which OS configuration should we use]) AC_MSG_CHECKING([which OS configuration should we use])
if test -n "$with_sysconfig" -a "$with_sysconfig" != no ; then if test -n "$with_sysconfig" -a "$with_sysconfig" != no ; then
case "$with_sysconfig" in *.h) ;; *) with_sysconfig="$with_sysconfig.h" ;; esac
if test -f $with_sysconfig ; then if test -f $with_sysconfig ; then
SYSDESC=$with_sysconfig sysdesc=$with_sysconfig
else else
SYSDESC=sysdep/cf/$with_sysconfig sysdesc=$srcdir/sysdep/cf/$with_sysconfig
if ! test -f $sysdesc ; then
sysdesc=$sysdesc.h
fi
fi fi
elif test -f sysconfig.h ; then elif test -f sysconfig.h ; then
SYSDESC=sysconfig sysdesc=sysconfig
else else
case "$host_os" in case "$host_os" in
linux*) SYSDESC=linux-20 ;; linux*) sysdesc=linux-20 ;;
*) AC_MSG_RESULT(unknown) *) AC_MSG_RESULT(unknown)
AC_MSG_ERROR([Cannot determine correct system configuration.]) AC_MSG_ERROR([Cannot determine correct system configuration.])
;; ;;
esac esac
SYSDESC=sysdep/cf/$SYSDESC.h sysdesc=$srcdir/sysdep/cf/$sysdesc.h
fi fi
AC_MSG_RESULT($SYSDESC) AC_MSG_RESULT($sysdesc)
if ! test -f $SYSDESC ; then if ! test -f $sysdesc ; then
AC_MSG_ERROR([The system configuration file is missing.]) AC_MSG_ERROR([The system configuration file is missing.])
fi fi
AC_DEFINE_UNQUOTED(SYSCONF_INCLUDE, "$SYSDESC") sysname=`echo $sysdesc | sed 's/\.h$//'`
AC_DEFINE_UNQUOTED(SYSCONF_INCLUDE, "$sysdesc")
AC_MSG_CHECKING([system-dependent directories])
sysdep_dirs="`sed <$sysdesc '/^Link: /!d;s/^Link: \(.*\)$/\1/' | tr '\012' ' '` lib"
AC_MSG_RESULT($sysdep_dirs)
AC_SUBST(sysdep_dirs)
AC_MSG_CHECKING([protocols]) AC_MSG_CHECKING([protocols])
protocols=`echo "$with_protocols" | sed 's/,/ /g'` protocols=`echo "$with_protocols" | sed 's/,/ /g'`
@ -46,6 +76,7 @@ for a in $protocols ; do
AC_DEFINE_UNQUOTED(CONFIG_`echo $a | tr 'a-z' 'A-Z'`) AC_DEFINE_UNQUOTED(CONFIG_`echo $a | tr 'a-z' 'A-Z'`)
done done
AC_MSG_RESULT(ok) AC_MSG_RESULT(ok)
AC_SUBST(protocols)
AC_PROG_CC AC_PROG_CC
if test -z "$GCC" ; then if test -z "$GCC" ; then
@ -82,12 +113,13 @@ else
fi fi
AC_CONFIG_HEADER(sysdep/autoconf.h) AC_CONFIG_HEADER(sysdep/autoconf.h)
AC_OUTPUT AC_OUTPUT_COMMANDS(,[$srcdir/tools/mergedirs $srcdir $srcdir_rel $objdir $sysdep_dirs])
AC_OUTPUT($makefiles)
cat >&AC_FD_MSG <<EOF cat >&AC_FD_MSG <<EOF
BIRD was configured with the following options: BIRD was configured with the following options:
System configuration: $SYSDESC System configuration: $sysdesc
Debugging: $enable_debug Debugging: $enable_debug
Routing protocols: $protocols Routing protocols: $protocols
EOF EOF

View file

@ -1,4 +1,5 @@
THISDIR=nest source=rt-table.c rt-fib.c rt-attr.c proto.c iface.c rt-dev.c
OBJS=rt-table.o rt-fib.o rt-attr.o proto.o iface.o rt-dev.o root-rel=../
dir-name=nest
include ../Rules include ../Rules

View file

@ -1,4 +1,5 @@
THISDIR=proto/rip source=rip.c
OBJS=rip.o root-rel=../../
dir-name=proto/rip
include ../../Rules include ../../Rules

View file

@ -1,4 +1,6 @@
THISDIR=proto/static source=static.c
OBJS=static.o root-rel=../../
dir-name=proto/static
include ../../Rules include ../../Rules

View file

@ -14,4 +14,5 @@
/* /*
Link: sysdep/linux Link: sysdep/linux
Link: sysdep/unix
*/ */

View file

@ -14,4 +14,5 @@
/* /*
Link: sysdep/linux Link: sysdep/linux
Link: sysdep/unix
*/ */

View file

@ -16,4 +16,5 @@
/* /*
Link: sysdep/linux Link: sysdep/linux
Link: sysdep/unix
*/ */

15
tools/Makefile-top.in Normal file
View file

@ -0,0 +1,15 @@
# Makefile for in place build of BIRD
# (c) 1999 Martin Mares <mj@ucw.cz>
objdir=@objdir@
all:
$(MAKE) -C $(objdir) $@
clean:
$(MAKE) -C $(objdir) clean
rm -f `find . -name "*~" -or -name "*.[oa]" -or -name "\#*\#" -or -name TAGS -or -name core -or -name depend -or -name .#*`
distclean: clean
rm -rf $(objdir)
rm -f config.* configure sysdep/autoconf.h Makefile

33
tools/Makefile.in Normal file
View file

@ -0,0 +1,33 @@
# Makefile for the BIRD Internet Routing Daemon
# (c) 1999 Martin Mares <mj@ucw.cz>
include Rules
srcdir_abs := $(shell cd $(srcdir) ; pwd)
.PHONY: all subdir depend clean distclean
all: .dir-stamp .dep-stamp subdir $(exedir)/bird
subdir depend:
set -e ; for a in $(dynamic-dirs) ; do $(MAKE) -C $$a $@ ; done
set -e ; for a in $(static-dirs) ; do $(MAKE) -C $$a -f $(srcdir_abs)/$$a/Makefile $@ ; done
$(exedir)/bird: $(addsuffix /all.o, $(static-dirs)) conf/all.o lib/birdlib.a
$(CC) $(LDFLAGS) -o $@ $^
.dir-stamp:
mkdir -p $(static-dirs)
touch .dir-stamp
.dep-stamp:
$(MAKE) depend
touch .dep-stamp
clean:
rm -f `find . -name "*.[oa]" -or -name core -or -name depend`
rm -f $(exedir)/bird .dep-stamp
distclean: clean
rm -f config.* configure sysdep/autoconf.h Makefile Rules
rm -rf .dir-stamp $(clean-dirs)

66
tools/Rules.in Normal file
View file

@ -0,0 +1,66 @@
# Makefile fragments for the BIRD Internet Routing Daemon
# (c) 1999 Martin Mares <mj@ucw.cz>
srcdir=@srcdir_rel_mf@
objdir=@objdir@
exedir=@exedir@
protocols=@protocols@
static-dirs := nest $(addprefix proto/,$(protocols))
static-dir-paths := $(addprefix $(srcdir)/,$(static-dirs))
dynamic-dirs := lib conf
dynamic-dir-paths := $(dynamic-dirs)
dir-makefiles := $(addsuffix /Makefile,$(static-dir-paths) $(dynamic-dir-paths))
all-dirs:=$(static-dirs) $(dynamic-dirs)
clean-dirs:=$(all-dirs) proto sysdep
dir-objs:=$(addprefix $(objdir)/,$(all-dirs))
CPPFLAGS=-I$(root-rel) -I$(srcdir)
CFLAGS=$(CPPFLAGS) @CFLAGS@
CC=@CC@
M4=@M4@
BISON=@BISON@
FLEX=@FLEX@
RANLIB=@RANLIB@
ifdef source
objs := $(subst .c,.o,$(source))
ifdef dir-name
src-path := $(srcdir)/$(dir-name)/
endif
all:
cd $(root-rel) && make
ifdef lib-dest
subdir: $(lib-dest)
$(lib-dest): $(objs)
rm -f $@
ar rcs $@ $^
$(RANLIB) $@
else
subdir: all.o
all.o: $(objs)
$(LD) -r -o $@ $^
endif
%.o: $(src-path)%.c
$(CC) $(CFLAGS) -o $@ -c $^
depend:
gcc $(CPPFLAGS) -MM $(addprefix $(src-path),$(source)) >depend
ifneq ($(wildcard .depend),)
include .depend
endif
endif

View file

@ -1,10 +1,17 @@
#!/bin/sh #!/bin/sh
if [ -z "$2" ] ; then if [ -z "$4" ] ; then
echo "Usage: mergedirs <obj-dir> <list-of-dirs>" echo "Usage: mergedirs <src-dir> <src-dir-rel> <obj-dir> <list-of-dirs>"
exit 1 exit 1
fi fi
TOPDIR=`pwd` SRCDIR=$1
shift
SRCREL=$1
case $SRCDIR in
/*) ;;
*) SRCREL="../$SRCREL" ;;
esac
shift
OBJDIR=$1 OBJDIR=$1
LIBDIR=$OBJDIR/lib LIBDIR=$OBJDIR/lib
CONFDIR=$OBJDIR/conf CONFDIR=$OBJDIR/conf
@ -12,26 +19,25 @@ shift
echo "Merging system-dependent modules" echo "Merging system-dependent modules"
MODULES=`for a in $@ ; do MODULES=`for a in $@ ; do
sed <$a/Modules "s@\\(.*\\)@\\1 $a/\\1@" sed <$SRCDIR/$a/Modules "s@\\(.*\\)@\\1 $a/\\1@"
done | done |
sort +0 -1 -u | sort +0 -1 -u |
cut -d ' ' -f 2` cut -d ' ' -f 2`
rm -rf $LIBDIR $CONFDIR rm -rf $LIBDIR $CONFDIR
mkdir -p $LIBDIR $CONFDIR mkdir -p $LIBDIR $CONFDIR
for a in $MODULES ; do for a in $MODULES ; do
echo $a
b=`basename $a` b=`basename $a`
case $b in case $b in
*.h) ln -s $TOPDIR/$a $LIBDIR/$b *.h) ln -s $SRCREL/$a $LIBDIR/$b
;; ;;
*.c) OBJ=`echo $b | sed 's/\.c$/\.o/'` *.c) OBJ=`echo $b | sed 's/\.c$/\.o/'`
OBJS="$OBJS $OBJ" OBJS="$OBJS $OBJ"
SRCS="$SRCS \\ SRCS="$SRCS \\
\$(TOPDIR)/$a" $b"
ln -s $TOPDIR/$a $LIBDIR/$b ln -s $SRCREL/$a $LIBDIR/$b
;; ;;
*.Y) CONFS="$CONFS\$(TOPDIR)/$a " *.Y) CONFS="$CONFS\$(srcdir)/$a "
ln -s $TOPDIR/$a $CONFDIR/$b ln -s $SRCREL/$a $CONFDIR/$b
;; ;;
*) echo "$b: Unknown file type" *) echo "$b: Unknown file type"
exit 1 exit 1
@ -40,12 +46,15 @@ for a in $MODULES ; do
done done
cat >$LIBDIR/Makefile <<EOF cat >$LIBDIR/Makefile <<EOF
OBJS=$OBJS source=$SRCS
SRCS=$SRCS lib-dest=birdlib.a
LIB=birdlib.a root-rel=../
include \$(TOPDIR)/Rules include ../Rules
EOF EOF
sed <$TOPDIR/conf/Makefile >$CONFDIR/Makefile "s|@CONFS@|$CONFS|" sed <$SRCDIR/conf/Makefile >$CONFDIR/Makefile "s|@CONFS@|$CONFS|"
ln -s $TOPDIR/conf/*.[chl] $CONFDIR/ CONFS=`cd $SRCDIR ; ls conf/*.[chl]`
for a in $CONFS ; do
ln -s $SRCREL/$a $CONFDIR/
done