mergedirs 1.17 KB
Newer Older
1 2
#!/bin/sh

3 4
if [ -z "$4" ] ; then
	echo "Usage: mergedirs <src-dir> <src-dir-rel> <obj-dir> <list-of-dirs>"
5 6
	exit 1
	fi
7
cpp=${CPP:-cc -E}
8 9 10 11 12 13 14 15
SRCDIR=$1
shift
SRCREL=$1
case $SRCDIR in
	/*) ;;
	*) SRCREL="../$SRCREL" ;;
	esac
shift
16 17
OBJDIR=$1
LIBDIR=$OBJDIR/lib
18
CONFDIR=$OBJDIR/conf
19
shift
20

21
echo "Merging system-dependent modules ($@)"
22
MODULES=`for a in $@ ; do
23
		cat $SRCDIR/sysdep/config.h $SRCDIR/$a/Modules |
24
		$cpp -U unix -D MACROS_ONLY -I $OBJDIR - |
25
		sed "/^[ ]*\$/d;/^#/d;s@\\(.*\\)@\\1 $a/\\1@"
26
		done |
27
	sort -k1,1 -u |
28
	cut -d ' ' -f 2`
29 30
rm -rf $LIBDIR $CONFDIR
mkdir -p $LIBDIR $CONFDIR
31 32
for a in $MODULES ; do
	b=`basename $a`
33
	case $b in
34
		*.h)	ln -s $SRCREL/$a $LIBDIR/$b
35 36 37 38
			;;
		*.c)	OBJ=`echo $b | sed 's/\.c$/\.o/'`
			OBJS="$OBJS $OBJ"
			SRCS="$SRCS \\
39 40
	$b"
			ln -s $SRCREL/$a $LIBDIR/$b
41
			;;
42 43
		*.Y)	CONFS="$CONFS\$(srcdir)/$a "
			ln -s $SRCREL/$a $CONFDIR/$b
44 45 46 47 48
			;;
		*)	echo "$b: Unknown file type"
			exit 1
			;;
		esac
49
	done
50

51
cat >$LIBDIR/Makefile <<EOF
52 53 54
source=$SRCS
lib-dest=birdlib.a
root-rel=../
55

56
include ../Rules
57
EOF
58

59 60 61 62 63
sed <$SRCDIR/conf/Makefile >$CONFDIR/Makefile "s|@CONFS@|$CONFS|"
CONFS=`cd $SRCDIR ; ls conf/*.[chl]`
for a in $CONFS ; do
	ln -s $SRCREL/$a $CONFDIR/
done