.
[autoconf.git] / autoreconf.sh
blob78e1c232182044f4a336b86aef4c7387020a11bf
1 #! @SHELL@
2 # autoreconf - remake all Autoconf configure scripts in a directory tree
3 # Copyright 1994, 1999, 2000 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 # 02111-1307, USA.
20 me=`echo "$0" | sed -e 's,.*[\\/],,'`
22 usage="\
23 Usage: $0 [OPTION] ... [TEMPLATE-FILE]
25 Run \`autoconf' (and \`autoheader', \`aclocal' and \`automake', where
26 appropriate) repeatedly to remake the Autoconf \`configure' scripts
27 and configuration header templates in the directory tree rooted at the
28 current directory. By default, it only remakes those files that are
29 older than their predecessors. If you install a new version of
30 Autoconf, running \`autoreconf' remakes all of the files by giving it
31 the \`--force' option.
33 Operation modes:
34 -h, --help print this help, then exit
35 -V, --version print version number, then exit
36 -v, --verbose verbosely report processing
37 -d, --debug don't remove temporary files
38 -f, --force consider every files are obsolete
39 -i, --install copy missing auxiliary files
40 -s, --symlink instead of copying, install symbolic links
42 The option \`--install' is similar to the option \`--add-missing' in
43 other tools.
45 Library directories:
46 -A, --autoconf-dir=ACDIR Autoconf's macro files location (rarely needed)
47 -l, --localdir=DIR location of \`aclocal.m4' and \`acconfig.h'
48 -M, --m4dir=M4DIR this package's Autoconf extensions
50 Unless specified, heuristics try to compute \`M4DIR' from the \`Makefile.am',
51 or defaults to \`m4' if it exists.
53 The following options are passed to \`automake':
54 --cygnus assume program is part of Cygnus-style tree
55 --foreign set strictness to foreign
56 --gnits set strictness to gnits
57 --gnu set strictness to gnu
58 --include-deps include generated dependencies in Makefile.in
60 The environment variables AUTOCONF, AUTOHEADER, AUTOMAKE, and ACLOCAL
61 are honored.
63 Report bugs to <bug-autoconf@gnu.org>."
65 version="\
66 autoreconf (@PACKAGE_NAME@) @VERSION@
67 Written by David J. MacKenzie.
69 Copyright 1994, 1999, 2000 Free Software Foundation, Inc.
70 This is free software; see the source for copying conditions. There is NO
71 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
73 help="\
74 Try \`$me --help' for more information."
76 exit_missing_arg="\
77 echo \"$me: option \\\`\$1' requires an argument\" >&2
78 echo \"\$help\" >&2
79 exit 1"
81 # NLS nuisances.
82 # Only set these to C if already set. These must not be set unconditionally
83 # because not all systems understand e.g. LANG=C (notably SCO).
84 # Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'!
85 # Non-C LC_CTYPE values break the ctype check.
86 if test "${LANG+set}" = set; then LANG=C; export LANG; fi
87 if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
88 if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
89 if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi
91 # Variables.
92 : ${autoconf_dir=${AC_MACRODIR=@datadir@}}
93 debug=false
94 dir=`echo "$0" | sed -e 's,[^\\/]*$,,'`
95 force=false
96 # --install -- as --add-missing in other tools.
97 install=false
98 localdir=.
99 # m4dir -- local Autoconf extensions. Typically `m4'.
100 m4dir=
101 status=0
102 # symlink -- when --install, use symlinks instead.
103 symlink=false
104 verbose=:
106 # Looking for autoconf.
107 # We test "$dir/autoconf" in case we are in the build tree, in which case
108 # the names are not transformed yet.
109 for autoconf in "$AUTOCONF" \
110 "$dir/@autoconf-name@" \
111 "$dir/autoconf" \
112 "@bindir@/@autoconf-name@"; do
113 test -f "$autoconf" && break
114 done
116 # Looking for autoheader.
117 for autoheader in "$AUTOHEADER" \
118 "$dir/@autoheader-name@" \
119 "$dir/autoheader" \
120 "@bindir@/@autoheader-name@"; do
121 test -f "$autoheader" && break
122 done
123 # Looking for automake.
124 : ${automake=${AUTOMAKE=automake}}
125 # Looking for aclocal.
126 : ${aclocal=${ACLOCAL=aclocal}}
128 # Parse command line.
129 while test $# -gt 0; do
130 optarg=`expr "x$1" : 'x--[^=]*=\(.*\)' \| \
131 "x$1" : 'x-.\(.*\)'`
132 case "$1" in
133 --version | -V )
134 echo "$version" ; exit 0 ;;
135 --help | -h )
136 echo "$usage"; exit 0 ;;
138 --verbose | -v )
139 verbose=echo
140 shift;;
141 --debug | -d )
142 debug=:; shift ;;
144 --localdir=* | -l?* )
145 localdir=$optarg
146 shift ;;
147 --localdir | -l )
148 test $# = 1 && eval "$exit_missing_arg"
149 shift
150 localdir=$1
151 shift ;;
153 --autoconf-dir=* | -A?* )
154 autoconf_dir=$optarg
155 shift ;;
156 --autoconf-dir | -A )
157 test $# = 1 && eval "$exit_missing_arg"
158 shift
159 autoconf_dir=$1
160 shift ;;
161 --macrodir=* | -m?* )
162 echo "$me: warning: --macrodir is obsolete, use --autoconf-dir" >&2
163 autoconf_dir=$optarg
164 shift ;;
165 --macrodir | -m )
166 echo "$me: warning: --macrodir is obsolete, use --autoconf-dir" >&2
167 test $# = 1 && eval "$exit_missing_arg"
168 shift
169 autoconf_dir=$1
170 shift ;;
172 --m4dir=* | -M?* )
173 m4dir=$optarg
174 shift ;;
175 --m4dir | -M )
176 test $# = 1 && eval "$exit_missing_arg"
177 shift
178 m4dir=$1
179 shift ;;
181 --force | -f )
182 force=:; shift ;;
184 --install | -i )
185 install=:; shift ;;
186 --symlink | -s )
187 symlink=:; shift ;;
189 # Options of Automake.
190 --cygnus | --foreign | --gnits | --gnu | --include-deps | -i )
191 automake="$automake $1"; shift ;;
193 -- ) # Stop option processing.
194 shift; break ;;
195 -* )
196 exec >&2
197 echo "$me: invalid option $1"
198 echo "$help"
199 exit 1 ;;
201 break ;;
202 esac
203 done
205 # Find the input file.
206 if test $# -ne 0; then
207 exec >&2
208 echo "$me: invalid number of arguments"
209 echo "$help"
210 exit 1
213 # If verbose, say what you are going to use.
214 if test $verbose = echo; then
215 $autoconf --version |
216 sed "s,.*)\(.*\)$,$me: using autoconf\1: $autoconf,;1q" >&2
217 $autoheader --version |
218 sed "s,.*)\(.*\)$,$me: using autoheader\1: $autoheader,;1q" >&2
219 $automake --version |
220 sed "s,.*)\(.*\)$,$me: using automake\1: $automake,;1q" >&2
221 $aclocal --version |
222 sed "s,.*)\(.*\)$,$me: using aclocal\1: $aclocal,;1q" >&2
225 # Dispatch autoreconf's option to the tools.
226 # --localdir
227 autoconf="$autoconf -l $localdir"
228 autoheader="$autoheader -l $localdir"
229 # --force
230 $force || automake="$automake --no-force"
231 # --verbose
232 autoconf="$autoconf `$verbose --verbose`"
233 autoheader="$autoheader `$verbose --verbose`"
234 automake="$automake `$verbose --verbose`"
235 aclocal="$aclocal `$verbose --verbose`"
236 # --debug
237 $debug &&
239 autoconf="$autoconf --debug"
240 autoheader="$autoheader --debug"
242 # --macrodir
243 export autoconf_dir
244 # --install and --symlink
245 if $install; then
246 automake="$automake --add-missing `$symlink || echo --copy`"
249 # Trap on 0 to stop playing with `rm'.
250 $debug ||
252 trap 'status=$?; rm -rf $tmp && exit $status' 0
253 trap '(exit $?); exit' 1 2 13 15
256 # Create a (secure) tmp directory for tmp files.
257 : ${TMPDIR=/tmp}
259 tmp=`(umask 077 && mktemp -d -q "$TMPDIR/arXXXXXX") 2>/dev/null` &&
260 test -n "$tmp" && test -d "$tmp"
261 } ||
263 tmp=$TMPDIR/ar$$
264 (umask 077 && mkdir $tmp)
265 } ||
267 echo "$me: cannot create a temporary directory in $TMPDIR" >&2
268 (exit 1); exit
271 # When debugging, it is convenient that all the related temporary
272 # files be at the same place.
273 TMPDIR=$tmp
274 export TMPDIR
276 # alflags.sed -- Fetch the aclocal flags.
277 cat >$tmp/alflags.sed <<EOF
279 /^ACLOCAL_[A-Z_]*FLAGS/{
280 s/.*=//
286 # update.sh --
287 # Exit 0 if the first argument is not the most recent of all or is missing.
288 cat >$tmp/update.sh <<\EOF
289 test -f "$1" || { :; exit; }
290 test x`ls -1dt "$@" 2>/dev/null | sed 1q` != x"$1"
292 update="@SHELL@ $tmp/update.sh"
295 # ----------------------- #
296 # Real work starts here. #
297 # ----------------------- #
299 # Make a list of directories to process.
300 # The xargs grep filters out Cygnus configure.in files.
301 find . '(' -name configure.ac -o -name configure.in ')' -print |
302 xargs grep -l AC_INIT |
303 sed 's,/configure\.ac$,,;s,/configure\.in$,,;s,^./,,' |
304 while read dir; do
306 cd $dir || continue
309 # ----------------- #
310 # Running aclocal. #
311 # ----------------- #
313 # uses_aclocal -- is this package using aclocal?
314 uses_aclocal=false
315 grep 'generated .* by aclocal' $localdir/aclocal.m4 >/dev/null 2>&1 &&
316 uses_aclocal=:
317 test -f "$localdir/aclocal.m4" ||
318 uses_aclocal=:
319 if $uses_aclocal &&
320 { $force ||
321 $update $localdir/aclocal.m4 $localdir/acinclude.m4; } then
322 # If there are flags for aclocal in Makefile.am, use them.
323 aclocal_flags=`sed -f $tmp/alflags.sed Makefile.am 2>/dev/null`
325 # If m4dir no specified and these flags do not specify the
326 # location of the local Autoconf extensions, default to `m4'.
327 case $m4dir,$aclocal_flags in
328 ,*"-I "* ) ;; # Not overriden and specified.
329 ,*) # Not specified at all.
330 test -d "m4" && aclocal_flags="$aclocal_flags -I m4";;
331 * ) # Specified by the user.
332 aclocal_flags="$aclocal_flags -I $m4dir";;
333 esac
335 $verbose $me: running $aclocal $aclocal_flags --output=$localdir/aclocal.m4 in $dir >&2
336 $aclocal $aclocal_flags --output=$localdir/aclocal.m4
340 # ------------------ #
341 # Running automake. #
342 # ------------------ #
344 # Assumes that there is a Makefile.am in the topmost directory.
345 uses_automake=false
346 test -f "Makefile.am" &&
347 uses_automake=:
348 # We should always run automake, and let it decide whether it shall
349 # update the file or not. In fact, the effect of `$force' is already
350 # included in `$automake' via `--no-force'.
351 if $uses_automake; then
352 $verbose $me: running $automake in $dir >&2
353 $automake
357 # ------------------ #
358 # Running autoconf. #
359 # ------------------ #
361 if $force ||
362 $update configure configure.ac $localdir/aclocal.m4 ||
363 $update configure configure.in $localdir/aclocal.m4; then
364 $verbose $me: running $autoconf in $dir >&2
365 $autoconf
369 # -------------------- #
370 # Running autoheader. #
371 # -------------------- #
373 # templates -- arguments of AC_CONFIG_HEADERS.
374 $verbose $me: running $autoconf -t 'AC_CONFIG_HEADERS:$1' >&2
375 templates=`$autoconf -t 'AC_CONFIG_HEADERS:$1'`
376 if test -n "$templates"; then
377 tcount=`set -- $templates; echo $#`
378 template=`set -- $templates; echo $1 | sed '
379 s/.*://
380 t colon
381 s/$/.in/
382 : colon
383 s/:.*//
385 template_dir=`echo $template | sed -e 's,[\\/]*[^\\/]*$,,;s,^$,.,'`
386 stamp_num=`test "$tcount" -gt 1 && echo "$tcount"`
387 stamp=$template_dir/stamp-h$stamp_num.in
388 # If config.hin exists, don't override it unless it was really
389 # created by autoheader (users are allowed to write them by hand!).
390 uses_autoheader=false
391 grep autoheader "$template" >/dev/null 2>&1 &&
392 uses_autoheader=:
393 test -f "$template" ||
394 uses_autoheader=:
395 if $uses_autoheader &&
396 { $force ||
397 $update $template \
398 configure.ac $localdir/aclocal.m4 $localdir/acconfig.h ||
399 $update $template \
400 configure.in $localdir/aclocal.m4 $localdir/acconfig.h ||
401 $update $stamp \
402 configure.ac $localdir/aclocal.m4 $localdir/acconfig.h ||
403 $update $stamp \
404 configure.in $localdir/aclocal.m4 $localdir/acconfig.h; } then
405 $verbose $me: running $autoheader in $dir >&2
406 $autoheader &&
407 $verbose "touching $stamp" >&2 &&
408 touch $stamp
412 done
414 # Local Variables:
415 # mode: shell-script
416 # sh-indentation: 2
417 # End: