* bootstrap: Allow user overriding of gnulib-tool location, and
[m4/ericb.git] / bootstrap
blob7ecf0b2d2889e42fe9187b09a4797379c84dc2b7
1 #! /bin/sh
3 # helps bootstrapping M4, when checked out from CVS
4 # requires GNU Gettext and bleeding edge GNU Autoconf, Automake & Libtool
6 : ${AUTORECONF=autoreconf}
7 : ${AWK=awk}
8 : ${GNULIB_TOOL=gnulib-tool}
9 : ${LIBTOOLIZE=libtoolize}
10 : ${RM=rm -f}
11 : ${SED=sed}
13 ltdldir=ltdl
14 config_aux_dir=$ltdldir/config
15 config_macro_dir=$ltdldir/m4
16 bailout_cb=:
18 # List dependencies here too; we don't extract them, otherwise dependent
19 # modules could end up being imported to src/ *and* gnu/!
20 src_modules='getopt version-etc-fsf version-etc'
22 dirname="s,/[^/]*$,,"
23 basename="s,^.*/,,g"
25 # Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
26 # is ksh but when the shell is invoked as "sh" and the current value of
27 # the _XPG environment variable is not equal to 1 (one), the special
28 # positional parameter $0, within a function call, is the name of the
29 # function.
30 progpath="$0"
32 # The name of this program:
33 progname=`echo "$progpath" | $SED "$basename"`
35 # func_echo arg...
36 # Echo program name prefixed message.
37 func_echo ()
39 echo $progname: ${1+"$@"}
42 # func_error arg...
43 # Echo program name prefixed message to standard error.
44 func_error ()
46 echo $progname: ${1+"$@"} >&2
50 ## ---------------------------- ##
51 ## Find the gnulib module tree. ##
52 ## ---------------------------- ##
54 case $GNULIB_TOOL in
55 /* ) gnulibdir=$GNULIB_TOOL ;; # absolute
56 */* ) gnulibdir=`pwd`/$GNULIB_TOOL ;; # relative
57 * ) gnulibdir=`which "$GNULIB_TOOL"` ;; # PATH search
58 esac
60 # Follow symlinks
61 while test -h "$gnulibdir"; do
63 # Resolve symbolic link.
64 sedexpr1='s, -> ,#%%#,'
65 sedexpr2='s,^.*#%%#\(.*\)$,\1,p'
66 linkval=`LC_ALL=C ls -l "$gnulibdir" | $SED "$sedexpr1" | $SED -n "$sedexpr2"`
67 test -n "$linkval" || break
69 case "$linkval" in
70 /* ) gnulibdir="$linkval" ;;
71 * ) gnulibdir=`echo "$gnulibdir" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
72 esac
74 done
76 gnulibdir=`echo "$gnulibdir" | $SED "$dirname"`
79 ## ---------------------- ##
80 ## Import Gnulib modules. ##
81 ## ---------------------- ##
83 func_echo "running: ${GNULIB_TOOL} --import"
84 ${GNULIB_TOOL} --import
86 func_echo "patching include directories in gnulib regex module"
87 mv $config_macro_dir/regex.m4 $config_macro_dir/regex-m4.old
88 sed 's,lib/regex.c,gnu/regex.c,g' $config_macro_dir/regex-m4.old > $config_macro_dir/regex.m4 && \
89 $RM $config_macro_dir/regex-m4.old
91 func_echo "hiding gnulib jm_\* macros"
92 cat >> $config_macro_dir/gnulib.m4 <<\EOF
93 AC_DEFUN([gl_AC_HEADER_INTTYPES_H], [jm_AC_HEADER_INTTYPES_H])
94 AC_DEFUN([gl_AC_HEADER_STDINT_H], [jm_AC_HEADER_STDINT_H])
95 AC_DEFUN([gl_AC_TYPE_UINTMAX_T], [jm_AC_TYPE_UINTMAX_T])
96 EOF
99 ## --------------------------------- ##
100 ## Copy additional src only modules. ##
101 ## --------------------------------- ##
103 func_echo "fetching modules for src directory"
105 for file in `${GNULIB_TOOL} --extract-filelist $src_modules`; do
107 dest=`echo $file | $SED "$basename"`
108 case $file in
109 lib/*) dest=src/$dest ;;
110 m4/*) dest=$config_macro_dir/$dest ;;
111 *) func_echo "Unknown file: $file"
112 exit 1
114 esac
116 # Be sure to show all copying errors before bailing out
117 if test -f $gnulibdir/$file; then
118 func_echo "copying file \`$dest'"
119 cp $gnulibdir/$file $dest
120 else
121 func_error "$gnulibdir/$file does not exist"
122 bailout_cb="exit 1"
124 done
125 $bailout_cb
128 ## ----------- ##
129 ## Libtoolize. ##
130 ## ----------- ##
132 func_echo "running: $LIBTOOLIZE --ltdl=\"$ltdldir\" --force --copy"
133 $LIBTOOLIZE --ltdl="$ltdldir" --force --copy
136 ## ----------- ##
137 ## Autoreconf. ##
138 ## ----------- ##
140 func_echo "running: $AUTORECONF --force --verbose --install"
141 $AUTORECONF --force --verbose --install
144 ## ---------- ##
145 ## testsuite. ##
146 ## ---------- ##
149 func_echo "generating testsuite"
150 cd tests
151 $AWK -f ./generate.awk ../doc/m4.texinfo > generated.at
154 exit 0