1#!/bin/sh
2#set -x
3# helps bootstrapping am-utils, when checked out from CVS
4# requires GNU autoconf and GNU automake
5# this is not meant to go into the distributions
6# Erez Zadok <ezk@cs.columbia.edu>
7
8# test cwd
9test -f ../amd/amd.c && cd ..
10if [ ! -f amd/amd.c ]; then
11    echo "Must run $0 from the top level source directory."
12    exit 1
13fi
14
15# validate macros directory and some macro files
16if [ ! -d m4/macros ]; then
17    echo No m4/macros directory found!
18    exit 1
19fi
20if [ ! -f m4/macros/HEADER ]; then
21    echo No m4/macros/HEADER file found!
22    exit 1
23fi
24
25# remove any remaining autom4te.cache directory
26rm -fr autom4te.cache autom4te-*.cache
27
28# generate acinclude.m4 file
29echo "AMU: prepare acinclude.m4..."
30test -f acinclude.m4 && mv -f acinclude.m4 acinclude.m4.old
31(cd m4/macros
32 for i in HEADER *.m4; do
33     cat $i
34     echo
35     echo
36 done
37 cat TRAILER
38) > acinclude.m4
39
40# generate aclocal.m4 file
41echo "AMU: aclocal..."
42test -f aclocal.m4 && mv -f aclocal.m4 aclocal.m4.old
43# show version
44aclocal --version 2>&1 | head -1
45if aclocal ; then
46    :
47else
48    echo "aclocal command failed.  fix errors and rerun $0."
49    exit 2
50fi
51
52# produce new configure.in (temp) script
53echo "AMU: autoconf..."
54# show version
55autoconf --version 2>&1 | head -1
56LOG=/tmp/amu-$$.log
57rm -f ${LOG}
58autoconf configure.in > configure.new 2> ${LOG}
59# until Automake requires Autoconf 2.50, manual says to ignore this
60CUTWARNMSG1="warning: AC_PROG_LEX invoked multiple times|do not use m4_(patsubst|regexp):"
61egrep -v "${CUTWARNMSG1}" ${LOG} > ${LOG}.new
62mv ${LOG}.new ${LOG}
63if test -s ${LOG}; then
64    echo "AUTOCONF ERRORS (MUST FIX):"
65    cat ${LOG}
66    rm -f ${LOG}
67    exit 2
68fi
69# now prepare the real configure script
70test -f configure && mv -f configure configure.old
71mv -f configure.new configure
72chmod a+rx configure
73rm -f configure.old
74
75# run autoheader to produce C header .in files
76echo "AMU: autoheader..."
77# show version
78autoheader --version 2>&1 | head -1
79autoheader configure.in > config.h.in 2> ${LOG}
80CUTWARNMSG2="autoheader: \`config.h.in' is updated"
81egrep -v "${CUTWARNMSG2}" ${LOG} > ${LOG}.new
82mv ${LOG}.new ${LOG}
83if test -s ${LOG}; then
84    echo "AUTOHEADER ERRORS (MUST FIX):"
85    cat ${LOG}
86    rm -f ${LOG}
87    exit 2
88fi
89rm -f ${LOG}
90
91# generate makefiles
92cmd="automake --add-missing --copy --ignore-deps"
93#cmd="automake --add-missing"
94echo "AMU: $cmd..."
95# show version
96automake --version 2>&1 | head -1
97if ${cmd} ; then
98    :
99else
100    echo "automake command failed.  fix errors and rerun $0."
101    exit 2
102fi
103
104# save timestamp
105echo "AMU: save timestamp..."
106echo timestamp > stamp-h.in
107
108exit 0
109