2 # autoconf -- create `configure' using m4 macros
3 # Copyright (C) 1992, 93, 94, 96, 99, 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)
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
20 # If given no args, create `configure' from template file `configure.in'.
21 # With one arg, create a configure script on standard output from
22 # the given template file.
24 me
=`echo "$0" | sed -e 's,.*/,,'`
27 Usage: autoconf [OPTION] ... [TEMPLATE-FILE]
29 Generate a configuration script from a TEMPLATE-FILE if given, or
30 \`configure.in' by default. Output is sent to the standard output if
31 TEMPLATE-FILE is given, else into \`configure'.
33 If the option \`--trace' is used, no configuration script is created.
35 -h, --help print this help, then exit
36 -V, --version print version number, then exit
37 -v, --verbose verbosely report processing
38 -d, --debug don't remove temporary files
39 -m, --macrodir=DIR directory storing Autoconf's macro files
40 -l, --localdir=DIR directory storing the \`aclocal.m4' file
41 -t, --trace=MACRO report the list of calls to MACRO
42 -i, --initialization also trace Autoconf's initialization process
43 -o, --output=FILE save output in FILE (stdout is the default)
45 Report bugs to <bug-autoconf@gnu.org>."
48 autoconf (GNU @PACKAGE@) @VERSION@
49 Written by David J. MacKenzie.
51 Copyright (C) 1992, 93, 94, 96, 99, 2000 Free Software Foundation, Inc.
52 This is free software; see the source for copying conditions. There is NO
53 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
56 Try \`$me --help' for more information."
59 # Only set these to C if already set. These must not be set unconditionally
60 # because not all systems understand e.g. LANG=C (notably SCO).
61 # Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'!
62 # Non-C LC_CTYPE values break the ctype check.
63 if test "${LANG+set}" = set; then LANG
=C
; export LANG
; fi
64 if test "${LC_ALL+set}" = set; then LC_ALL
=C
; export LC_ALL
; fi
65 if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES
=C
; export LC_MESSAGES
; fi
66 if test "${LC_CTYPE+set}" = set; then LC_CTYPE
=C
; export LC_CTYPE
; fi
69 # We use echo to avoid assuming a particular line-breaking character.
70 # The extra dot is to prevent the shell from consuming trailing
71 # line-breaks from the sub-command output. A line-break within
72 # single-quotes doesn't work because, if this script is created in a
73 # platform that uses two characters for line-breaks (e.g., DOS), tr
75 ac_LF_and_DOT
=`echo; echo .`
78 # Handle the case that m4 has moved since we were configured.
79 # It may have been found originally in a build directory.
82 /*) test -f "$M4" || M4
=m4 ;;
84 # Some non-GNU m4's don't reject the --help option, so give them /dev/null.
85 case `$M4 --help </dev/null 2>&1` in
87 *) echo "$me: Autoconf requires GNU m4 1.4 or later" >&2; exit 1 ;;
91 : ${AC_MACRODIR=@datadir@}
92 : ${AC_ACLOCALDIR=`(aclocal --print-ac-dir) 2>/dev/null`}
95 # Trace Autoconf's initialization?
103 # Trace the first arguments of some macros
105 # Produce the configure script (default)
110 tmpout
=${tmpbase}.out
111 silent_m4
=${tmpbase}silent.
m4
112 trace_m4
=${tmpbase}trace.
m4
113 translate_awk
=${tmpbase}trans.
awk
117 while test $# -gt 0 ; do
119 --version |
--vers* |
-V )
120 echo "$version" ; exit 0 ;;
122 echo "$usage"; exit 0 ;;
124 --debug |
--d* |
-d )
126 --verbose |
--verb* |
-v )
130 --localdir=* |
--l*=* )
131 localdir
=`echo "$1" | sed -e 's/^[^=]*=//'`
133 --localdir |
--l* |
-l )
135 test $# = 0 && { echo "$help" >&2; exit 1; }
139 --macrodir=* |
--m*=* )
140 AC_MACRODIR
=`echo "$1" | sed -e 's/^[^=]*=//'`
142 --macrodir |
--m* |
-m )
144 test $# = 0 && { echo "$help" >&2; exit 1; }
155 test $# = 0 && { echo "$help" >&2; exit 1; }
156 traces
="$traces '$1'"
160 traces
="$traces '"`echo "$1" | sed -e 's/^[^=]*=//;s/:.*//'`"'"
162 --initialization |
-i )
168 test $# = 0 && { echo "$help" >&2; exit 1; }
172 outfile
=`echo "$1" | sed -e 's/^[^=]*=//'`
175 -- ) # Stop option processing
177 - ) # Use stdin as input.
181 echo "$me: invalid option $1"
190 test -n "$localdir" && use_localdir
="-I$localdir"
191 run_m4
="$M4 $use_localdir -I $AC_MACRODIR autoconf.m4"
192 run_m4f
="$M4 $use_localdir --reload $AC_MACRODIR/autoconf.m4f"
194 # Find the input file.
196 0) infile
=configure.
in
197 test $task = script && test "x$outfile" = x
&& outfile
=configure
;;
200 echo "$me: invalid number of arguments."
205 # Trap on 0 to stop playing with `rm'.
208 trap 'status=$?; rm -f $tmpbase* && exit $status' 0
209 trap 'exit $?' 1 2 13 15
212 if test z
$infile = z-
; then
215 elif test ! -r "$infile"; then
216 echo "$me: $infile: No such file or directory" >&2
220 # Output is produced into FD 4. Prepare it.
222 x- | x
) # Output to stdout
228 # Initializations are performed. Proceed to the main task.
231 ## --------------------- ##
232 ## Generate the script. ##
233 ## --------------------- ##
235 $run_m4f $infile >$tmpout ||
exit 2
237 # You could add your own prefixes to pattern if you wanted to check for
238 # them too, e.g. pattern='\(AC_\|ILT_\)', except that UNIX sed doesn't do
242 if grep "^[^#]*$pattern" $tmpout >/dev
/null
2>&1; then
243 echo "$me: undefined macros:" >&2
244 sed -n "s/^[^#]*\\($pattern[_A-Za-z0-9]*\\).*/\\1/p" $tmpout |
246 grep -n "^[^#]*$macro" $infile /dev
/null
247 test $?
= 1 && echo "***BUG in Autoconf--please report*** $macro"
252 if test -n "$outfile"; then
256 # Put the real line numbers into configure to make config.log more
257 # helpful. Because quoting can sometimes get really painful in m4,
258 # there are special @tokens@ to substitute.
271 while (sub(/__oline__/, oline))
273 while (sub(/@<:@/, "["))
275 while (sub(/@:>@/, "]"))
277 while (sub(/@S\|@/, "$"))
279 while (sub(/@%:@/, "#"))
283 ;; # End of the task script.
291 # `errprint' must be silent when we run `m4 --trace', otherwise there
292 # can be warnings mixed with traces in m4's stderr.
293 cat >$silent_m4 <<\EOF
294 define
(`errprint')dnl
296 # A program to trace m4 macros.
297 cat >$trace_m4 <<\EOF
301 [ifelse([$#], [1], [],
303 [[[$2]][$1]_at([$1], shift(shift($@)))])])
305 [ifelse([$#], [1], [],
306 [$#], [2], [smash([$2])],
307 [smash([$2])[$1]_star([$1], shift(shift($@)))])])
309 # Smash quotes its result.
311 [patsubst(patsubst(patsubst([[[$1]]],
317 [^ *\(.*\) *$], [[\1]])])
319 [shift(shift(shift(shift(shift($@)))))])
321 [_at([$1], args($@))])
323 [_star([$1], args($@))])
325 # A program to translate user tracing requests into m4 macros.
326 cat >$translate_awk <<\EOF
327 function trans (arg, sep)
338 # Name (also available as $0).
345 # $@, list of quoted effective arguments.
347 return "]at([" (separator ? separator : ",") "], $@)["
348 # $*, list of unquoted effective arguments.
350 return "]star([" (separator ? separator : ":") "], $@)["
353 function error (message)
355 print message >"/dev/stderr"
360 # Accumulate the whole input.
361 request = request $0 "\n"
367 for (cp = request; cp; cp = substr (cp, 2))
369 char = substr (cp, 1, 1)
372 if (match (cp, /^\$[0-9]+/))
375 res = res "$" (substr (cp, 2, RLENGTH - 1) + 4)
376 cp = substr (cp, RLENGTH)
378 else if (substr (cp, 2, 1) ~ /[fldn$@*]/)
380 # $x, no separator given.
381 res = res trans(substr (cp, 2, 1))
384 else if (substr (cp, 2, 1) == "{")
386 # ${sep}x, long separator.
387 end = index (cp, "}")
389 error("invalid escape: " cp)
390 separator = substr (cp, 3, end - 3)
391 if (substr (cp, end + 1, 1) ~ /[*@]/)
392 res = res trans(substr (cp, end + 1, 1), separator)
394 error("invalid escape: " cp)
395 cp = substr (cp, end + 1)
397 else if (substr (cp, 3, 1) ~ /[$@]/)
399 # $sx, short separator `s
'.
400 res = res trans(substr (cp, 3, 1), substr (cp, 2, 1))
405 error("invalid escape: " substr (cp, 1, 2))
414 # Extract both the m4 program and the m4 options from TRACES.
415 eval set dummy "$traces"
419 # The request may be several lines long, hence sed has to quit.
420 trace_opt="$trace_opt -t "`echo "$trace" | sed -e 's
/:.
*//;q
'`
423 # The `]])' are closing the
`define' which is started by sed.
424 # This is to cope with multiple line requests.
426 sed -e '1s/^\([^:]*\):\(.*\)$/define([AT_\1], [[\2/';;
429 echo "define([AT_$trace], [[\$f:\$l:\$n:\$*]])";;
431 $AWK -f $translate_awk >>$trace_m4 || exit 1
433 echo "divert(0)dnl" >>$trace_m4
435 # Do we trace the initialization?
436 if $initialization; then
437 run_m4_trace="$run_m4 $trace_opt -daflq $silent"
439 run_m4_trace="$run_m4f $trace_opt -daflq $silent"
442 # Run m4 on the input file to get traces.
443 $verbose "Running $run_m4_trace $infile" >&2
444 $run_m4_trace $infile 2>&1 >/dev/null |
445 sed -e 's/^m4trace:\([^:][^:]*\):\([0-9][0-9]*\): -\([0-9][0-9]*\)- \([^(][^(]*\)(\(.*\)$/AT_\4([\1], [\2], [\3], [\4], \5/' \
446 -e 's/^m4trace:\([^:][^:]*\):\([0-9][0-9]*\): -\([0-9][0-9]*\)- \(.*\)$/AT_\4([\1], [\2], [\3], [\4])/' >>$trace_m4
448 # Now we are ready to run m4 to process the trace file.
449 # It makes no sense to try to transform __oline__.
450 $verbose "Running $M4 $trace_m4" >&2
463 ## -------------------------------------------------------- ##
464 ## Task --install. Install links to the library m4 files. ##
465 ## -------------------------------------------------------- ##
467 # An m4 program that reports what macros are requested, and where
470 dnl Keep the definition of the old AC_DEFUN
471 define([AC_DEFUN_OLD], defn([AC_DEFUN]))
473 dnl Define the macro so that the first time it is expanded, it reports
474 dnl on stderr its name, and where it was defined.
477 [ifdef([AC_DECLARED{$1}],,
478 [define([AC_DECLARED{$1}])errprint(]]__file__:__line__:[[ [$1]
482 dnl All the includes must be disabled. If they are not, since people don't
483 dnl protect the first argument of AC_DEFUN, then, if read a second time
484 dnl this argument will be expanded, and we'll get pure junk out of m4.
487 # Run m4 with all the library files, discard stdout, save stderr.
488 $verbose Running $run_m4f -dipa -t m4_include -t m4_sinclude $tmpin $localdir/*.m4 $AC_ACLOCALDIR/*.m4 $infile >&2
489 $run_m4f -dipa -t m4_include -t m4_sinclude $tmpin $localdir/*.m4 $AC_ACLOCALDIR/*.m4 $infile >/dev/null 2>$tmpout
490 # Keep only the good lines, there may be other outputs
491 grep '^[^: ]*:[0-9][0-9]*:[^:]*$' $tmpout >$tmpin
492 # Extract the files that are not in the local dir, and install the links.
493 # Save in $tmpout the list of installed links.
495 $verbose "Required macros:" >&2
496 $verbose "`sed -e 's/^/| /' $tmpin`" >&2
500 file=`echo "$line" |
sed -e 's/:.*//'`
501 filename=`echo "$file" |
sed -e 's,.*/,,'`
502 macro=`echo "$line" |
sed -e 's/.*:[ ]*//'`
503 if test -f "$file" && test "x$file" != "x$infile"; then
504 if test -f $localdir/$filename; then
505 $verbose "$filename already installed" >&2
507 $verbose "installing $file which provides $macro" >&2
508 ln -s "$file" "$localdir/$filename" ||
509 cp "$file" "$localdir/$filename" ||
511 echo "$me: cannot link from $file to $localdir/$filename" >&2
515 echo "$localdir/$filename" >>$tmpout
518 # Now that we have installed the links, and that we know that the
519 # user needs the FILES, check that there is an exact correspondence.
520 # Use yourself to get the list of the included files.
523 # Not m4_s?include, because it would catch acsite and aclocal, which
524 # we don't care about.
525 $0 -l "$localdir" -t AC_INCLUDE $infile |
526 sed -e 's/^[^:]*:[^:]*:[^:]*://g' |
529 # All the included files are needed.
530 for file in `cat $tmpin`;
532 if fgrep "$file" $tmpout >/dev/null 2>&1; then :; else
533 echo "\`$file' is uselessly included" >&2
536 # All the needed files are included.
537 for file in `sort $tmpout | uniq`;
539 if fgrep "$file" $tmpin >/dev/null 2>&1; then :; else
540 echo "\`$file' is not included
" >&2
551 *)echo "$me: internal error
: unknown task
: $task" >&2