* modules/gnu.c (m4_regexp_search, regsub, substitute)
[m4/ericb.git] / bootstrap
blob77ce631c9125bd6bd855e139b5fd63d3c67a89c3
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 : ${RM=rm -f}
10 : ${SED=sed}
11 : ${WGET=wget}
13 : ${DOWNLOAD_PO=yes}
15 ltdldir=ltdl
16 config_aux_dir=$ltdldir/config
17 config_macro_dir=$ltdldir/m4
18 bailout_cb=:
20 # List dependencies here too; we don't extract them, otherwise dependent
21 # modules could end up being imported to src/ *and* gnu/!
22 src_modules='getopt version-etc-fsf version-etc'
24 dirname="s,/[^/]*$,,"
25 basename="s,^.*/,,g"
27 # Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
28 # is ksh but when the shell is invoked as "sh" and the current value of
29 # the _XPG environment variable is not equal to 1 (one), the special
30 # positional parameter $0, within a function call, is the name of the
31 # function.
32 progpath="$0"
34 # The name of this program:
35 progname=`echo "$progpath" | $SED "$basename"`
37 # func_echo arg...
38 # Echo program name prefixed message.
39 func_echo ()
41 echo $progname: ${1+"$@"}
44 # func_error arg...
45 # Echo program name prefixed message to standard error.
46 func_error ()
48 echo $progname: ${1+"$@"} >&2
52 ## ------------------------------ ##
53 ## Fetch translations. ##
54 ## (taken from GNU tar bootstrap) ##
55 ## ------------------------------ ##
57 TP_URL="http://www.iro.umontreal.ca/translation/maint/m4/"
59 func_update_po ()
61 if test $# = 1; then
62 case $1 in
63 *.po) POFILE=$1 ;;
64 *) POFILE=$1.po ;;
65 esac
66 func_echo "getting translation for $1..."
67 $WGET -r --cache=off $TP_URL/$POFILE
68 else
69 func_echo "getting translations into po..."
70 (cd po &&
71 rm -f dummy `ls | sed -n '/\.gmo$/p; /\.po/p'` &&
72 $WGET -nv -nd -r -l 1 -A .po --cache=off $TP_URL &&
73 rm -f index.html index.html.[0-9]*
74 ls *.po | sed 's/\.po$//' > LINGUAS
75 ) || exit
79 case $DOWNLOAD_PO in
80 no) ;;
81 only) func_update_po; exit 0 ;;
82 yes) func_update_po ;;
83 *) func_update_po $DOWNLOAD_PO ;;
84 esac
86 ## ---------------------------- ##
87 ## Find the gnulib module tree. ##
88 ## ---------------------------- ##
90 case $GNULIB_TOOL in
91 /* ) gnulibdir=$GNULIB_TOOL ;; # absolute
92 */* ) gnulibdir=`pwd`/$GNULIB_TOOL ;; # relative
93 * ) gnulibdir=`which "$GNULIB_TOOL"` ;; # PATH search
94 esac
96 # Follow symlinks
97 while test -h "$gnulibdir"; do
99 # Resolve symbolic link.
100 sedexpr1='s, -> ,#%%#,'
101 sedexpr2='s,^.*#%%#\(.*\)$,\1,p'
102 linkval=`LC_ALL=C ls -l "$gnulibdir" | $SED "$sedexpr1" | $SED -n "$sedexpr2"`
103 test -n "$linkval" || break
105 case "$linkval" in
106 /* ) gnulibdir="$linkval" ;;
107 * ) gnulibdir=`echo "$gnulibdir" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
108 esac
110 done
112 gnulibdir=`echo "$gnulibdir" | $SED "$dirname"`
115 ## ---------------------- ##
116 ## Import Gnulib modules. ##
117 ## ---------------------- ##
119 func_echo "running: ${GNULIB_TOOL} --update"
120 ${GNULIB_TOOL} --update
122 func_echo "patching include directories in gnulib regex module"
123 mv $config_macro_dir/regex.m4 $config_macro_dir/regex-m4.old
124 sed 's,lib/regex.c,gnu/regex.c,g' $config_macro_dir/regex-m4.old > $config_macro_dir/regex.m4 && \
125 $RM $config_macro_dir/regex-m4.old
127 func_echo "hiding gnulib jm_\* macros"
128 cat >> $config_macro_dir/gnulib.m4 <<\EOF
129 AC_DEFUN([gl_AC_HEADER_INTTYPES_H], [jm_AC_HEADER_INTTYPES_H])
130 AC_DEFUN([gl_AC_HEADER_STDINT_H], [jm_AC_HEADER_STDINT_H])
131 AC_DEFUN([gl_AC_TYPE_UINTMAX_T], [jm_AC_TYPE_UINTMAX_T])
135 ## --------------------------------- ##
136 ## Copy additional src only modules. ##
137 ## --------------------------------- ##
139 func_echo "fetching modules for src directory"
141 for file in `${GNULIB_TOOL} --extract-filelist $src_modules`; do
143 dest=`echo $file | $SED "$basename"`
144 case $file in
145 lib/*) dest=src/$dest ;;
146 m4/*) dest=$config_macro_dir/$dest ;;
147 *) func_echo "Unknown file: $file"
148 exit 1
150 esac
152 # Be sure to show all copying errors before bailing out
153 if test -f $gnulibdir/$file; then
154 func_echo "copying file \`$dest'"
155 cp $gnulibdir/$file $dest
156 else
157 func_error "$gnulibdir/$file does not exist"
158 bailout_cb="exit 1"
160 done
161 $bailout_cb
164 ## ----------- ##
165 ## Autoreconf. ##
166 ## ----------- ##
168 func_echo "running: $AUTORECONF --force --verbose --install --no-recursive"
169 $AUTORECONF --force --verbose --install --no-recursive
172 ## ---------- ##
173 ## testsuite. ##
174 ## ---------- ##
177 func_echo "generating testsuite"
178 cd tests
179 $AWK -f ./generate.awk ../doc/m4.texinfo > generated.at
182 if test x"$DOWNLOAD_PO" != xno; then
183 func_echo "If your pofiles are uptodate, you can rerun bootstrap"
184 func_echo "as \`DOWNLOAD_PO=no $progname' to avoid redownloading."
187 exit 0