#! /bin/sh
# $Id: distrib,v 8.24 2001/06/25 11:20:24 skimo Exp $ (Berkeley) $Date: 2001/06/25 11:20:24 $

echo "Running libtoolize"
libtoolize -c --force

echo "Building aclocal.m4"
rm -f aclocal.m4
aclocal -I m4

# Build autoconf structure.
echo "Running autoheader"
autoheader 2>&1 | sed '/warning: AC_TRY_RUN called without default/d'
chmod 444 config.h.in
echo "Running automake"
automake -a -c --foreign $@
rm -f configure
echo "Running autoconf"
autoconf 2>&1 | sed '/warning: AC_TRY_RUN called without default/d'
chmod 555 configure config.guess config.sub install-sh

msg="/* Do not edit: automatically built by build/distrib. */"
# Build automatically generated header files.
f=../ipc/ipc_def.h
echo "Building $f"
rm -f $f
(echo "$msg" && \
    awk -f ../ipc/ipc.awk ../ipc/ipc_cmd.c &&
    awk -f ../ipc/vipc.awk ../ip/ip_read.c) > $f
chmod 444 $f

f=../ipc/ipc_gen.c
echo "Building $f"
rm -f $f
(echo "$msg" && \
    perl -n ../ip/vipc.pl ../ip/ip_read.c) > $f
chmod 444 $f

f=../ex/ex_def.h
echo "Building $f"
rm -f $f
(echo "$msg" && \
    awk -f ../ex/ex.awk ../ex/ex_cmd.c) > $f
chmod 444 $f

f=../common/options_def.h
echo "Building $f"
rm -f $f
(echo "$msg" && \
    awk -f ../common/options.awk ../common/options.c) > $f
chmod 444 $f

# Build the automatically generated function prototype files.
for i in cl common ex gtk ip ipc motif motif_l tcl_api vi; do
	f=../$i/extern.h
	rm -f $f
	echo "Building $f"
	(echo "$msg" && \
	    sed -n "s/^ \* PUBLIC: \(.*\)/\1/p" ../$i/*.c) > $f
	chmod 444 $f
done

# Build the automatically generated function prototype files.
for i in perl_api ; do
	f=../$i/extern.h
	rm -f $f
	echo "Building $f"
	(echo "$msg" && \
	    sed -n "s/^ \* PUBLIC: \(.*\)/\1/p" ../$i/*.c ../$i/*.xs) > $f
	chmod 444 $f
done

# Build tags files.
echo "Building tags files"
f=tags
rm -f $f
if test $USER = 'bostic'; then ctagsopt = '-d'; fi
ctags $ctagsopt -w \
	../cl/*.[ch] ../common/*.[ch] ../ex/*.[ch] ../gtk/*.[ch] ../ip/*.[ch] \
	../ipc/*.[ch] ../motif/*.[ch] ../motif_l/*.[ch] ../perl_api/*.[ch] \
	../tcl_api/*.[ch] ../vi/*.[ch]
chmod 444 $f

date=`date +%Y-%m-%d`
echo "Building ../ex/version.h"
echo '#define VI_VERSION "'`git-describe` '('$date')"' > ../ex/version.h

touch stamp-h.in
