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: $0 [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'.
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 -m, --macrodir=DIR directory storing Autoconf's macro files
39 -l, --localdir=DIR directory storing the \`aclocal.m4' file
40 -o, --output=FILE save output in FILE (stdout is the default)
41 -W, --warnings=CATEGORY report the warnings falling in CATEGORY
43 Warning categories include:
44 \`cross' cross compilation issues
45 \`obsolete' obsolete constructs
46 \`syntax' dubious syntactic constructs
47 \`all' all the warnings
48 \`error' warnings are error
51 -t, --trace=MACRO report the list of calls to MACRO
52 -i, --initialization also trace Autoconf's initialization process
54 In tracing mode, no configuration script is created.
56 Report bugs to <bug-autoconf@gnu.org>."
59 autoconf (GNU @PACKAGE@) @VERSION@
60 Written by David J. MacKenzie.
62 Copyright (C) 1992, 93, 94, 96, 99, 2000 Free Software Foundation, Inc.
63 This is free software; see the source for copying conditions. There is NO
64 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
67 Try \`$me --help' for more information."
70 # Only set these to C if already set. These must not be set unconditionally
71 # because not all systems understand e.g. LANG=C (notably SCO).
72 # Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'!
73 # Non-C LC_CTYPE values break the ctype check.
74 if test "${LANG+set}" = set; then LANG
=C
; export LANG
; fi
75 if test "${LC_ALL+set}" = set; then LC_ALL
=C
; export LC_ALL
; fi
76 if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES
=C
; export LC_MESSAGES
; fi
77 if test "${LC_CTYPE+set}" = set; then LC_CTYPE
=C
; export LC_CTYPE
; fi
80 # We use echo to avoid assuming a particular line-breaking character.
81 # The extra dot is to prevent the shell from consuming trailing
82 # line-breaks from the sub-command output. A line-break within
83 # single-quotes doesn't work because, if this script is created in a
84 # platform that uses two characters for line-breaks (e.g., DOS), tr
86 ac_LF_and_DOT
=`echo; echo .`
89 # Handle the case that m4 has moved since we were configured.
90 # It may have been found originally in a build directory.
93 /*) test -f "$M4" || M4
=m4 ;;
95 # Some non-GNU m4's don't reject the --help option, so give them /dev/null.
96 case `$M4 --help </dev/null 2>&1` in
98 *) echo "$me: Autoconf requires GNU m4 1.4 or later" >&2; exit 1 ;;
102 : ${AC_MACRODIR=@datadir@}
103 : ${AC_ACLOCALDIR=`(aclocal --print-ac-dir) 2>/dev/null`}
106 # Trace Autoconf's initialization?
114 # Install links to the needed *.m4 extensions.
116 # Trace the first arguments of some macros
118 # Produce the configure script (default)
124 while test $# -gt 0 ; do
126 --version |
--vers* |
-V )
127 echo "$version" ; exit 0 ;;
129 echo "$usage"; exit 0 ;;
131 --debug |
--d* |
-d )
133 --verbose |
--verb* |
-v )
137 --localdir=* |
--l*=* )
138 localdir
=`echo "$1" | sed -e 's/^[^=]*=//'`
140 --localdir |
--l* |
-l )
142 test $# = 0 && { echo "$help" >&2; exit 1; }
146 --macrodir=* |
--m*=* )
147 AC_MACRODIR
=`echo "$1" | sed -e 's/^[^=]*=//'`
149 --macrodir |
--m* |
-m )
151 test $# = 0 && { echo "$help" >&2; exit 1; }
162 test $# = 0 && { echo "$help" >&2; exit 1; }
163 traces
="$traces '"`echo "$1" | sed "s/'/'\\\\\\\\''/g"`"'"
167 traces
="$traces '"`echo "$1" |
168 sed -e "s/^[^=]*=//;s/:.*//;s/'/'\\\\\\\\''/g"`"'"
170 --initialization |
-i )
176 test $# = 0 && { echo "$help" >&2; exit 1; }
180 outfile
=`echo "$1" | sed -e 's/^[^=]*=//'`
185 test $# = 0 && { echo "$help" >&2; exit 1; }
186 warnings
="$warnings "`echo $1 | sed -e 's/,/ /g'`
189 warnings
="$warnings "`echo "$1" | sed -e 's/^[^=]*=//;s/,/ /g'`
191 -W* ) # People are used to -Wall, -Werror etc.
192 warnings
="$warnings "`echo "$1" | sed -e 's/^-W//;s/,/ /g'`
195 -- ) # Stop option processing
197 - ) # Use stdin as input.
201 echo "$me: invalid option $1"
210 : ${warnings=`echo $WARNINGS | sed -e 's/,/ /g'`}
212 # Trap on 0 to stop playing with `rm'.
215 trap 'status=$?; rm -rf $tmp && exit $status' 0
216 trap 'exit $?' 1 2 13 15
219 # Create a (secure) tmp directory for tmp files.
222 tmp
=`(umask 077 && mktemp -d -q "$TMPDIR/acXXXXXX") 2>/dev/null` &&
226 tmp
=$TMPDIR/ac$$
&& (umask 077 && mkdir
$tmp)
229 echo "$me: cannot create a temporary directory in $TMPDIR" >&2
234 test -n "$localdir" && use_localdir
="-I$localdir"
235 run_m4
="$M4 $use_localdir -I $AC_MACRODIR autoconf.m4"
236 run_m4f
="$M4 $use_localdir --reload $AC_MACRODIR/autoconf.m4f"
238 # Find the input file.
240 0) infile
=configure.
in
241 test $task = script && test "x$outfile" = x
&& outfile
=configure
;;
244 echo "$me: invalid number of arguments."
249 # We need an actual file.
250 if test z
$infile = z-
; then
253 elif test ! -r "$infile"; then
254 echo "$me: $infile: No such file or directory" >&2
258 # Output is produced into FD 4. Prepare it.
260 x- | x
) # Output to stdout
266 # Initializations are performed. Proceed to the main task.
269 ## --------------------------------- ##
270 ## Generate the `configure' script. ##
271 ## --------------------------------- ##
273 # Enable the requested warnings.
274 warnings_opt
=`echo "$warnings" |
275 sed -e 's/\([^ ][^ ]*\)/-DAC_WARNING_ENABLE(\1) /g'`
276 $run_m4f $warnings_opt $infile >$tmp/configure ||
exit 2
278 # You could add your own prefixes to pattern if you wanted to check for
279 # them too, e.g. pattern='\(AC_\|ILT_\)', except that UNIX sed doesn't do
283 if grep "^[^#]*$pattern" $tmp/configure
>/dev
/null
2>&1; then
284 echo "$me: undefined macros:" >&2
285 sed -n "s/^[^#]*\\($pattern[_A-Za-z0-9]*\\).*/\\1/p" $tmp/configure |
287 grep -n "^[^#]*$macro" $infile /dev
/null
288 test $?
= 1 && echo "***BUG in Autoconf--please report*** $macro"
293 if test -n "$outfile"; then
297 # Put the real line numbers into configure to make config.log more
298 # helpful. Because quoting can sometimes get really painful in m4,
299 # there are special @tokens@ to substitute.
312 if ($0 ~ /__oline__/)
313 while (sub(/__oline__/, oline))
315 while (sub(/@<:@/, "["))
317 while (sub(/@:>@/, "]"))
319 while (sub(/@S\|@/, "$"))
321 while (sub(/@%:@/, "#"))
324 }' <$tmp/configure
>&4
325 ;; # End of the task script.
333 # A program to trace m4 macros.
334 cat >$tmp/trace.
m4 <<\EOF
337 # _MODE(SEPARATOR, ELT1, ELT2...)
338 # -------------------------------
339 # List the elements, separating then with SEPARATOR.
341 # `at' -- the elements are enclosed in brackets.
342 # `star' -- the elements are listed as are.
343 # `percent' -- the elements are `smashed': spaces are singled out,
344 # and no new line remains.
346 [ifelse
([$#], [1], [],
348 [[[$2]][$1]$0([$1], shift(shift($@
)))])])
350 [ifelse
([$#], [1], [],
351 [$#], [2], [smash
([$2])],
352 [smash
([$2])[$1]$0([$1], shift(shift($@
)))])])
354 [ifelse
([$#], [1], [],
356 [[$2][$1]$0([$1], shift(shift($@
)))])])
358 # Smash quotes its result.
360 [patsubst
(patsubst
(patsubst
([[[$1]]],
366 [^
*\
(.
*\
) *$
], [[\
1]])])
367 define
([args
], [shift(shift(shift(shift(shift($@
)))))])
368 define
([at], [_
$0([$1], args
($@
))])
369 define
([percent
], [_
$0([$1], args
($@
))])
370 define
([star
], [_
$0([$1], args
($@
))])
372 # A program to translate user tracing requests into m4 macros.
373 cat >$tmp/translate.
awk <<\EOF
374 function trans
(arg
, sep
)
385 # Name (also available as $0).
392 # $@, list of quoted effective arguments.
394 return "]at([" (separator ? separator
: ",") "], $@)["
395 # $*, list of unquoted effective arguments.
397 return "]star([" (separator ? separator
: ",") "], $@)["
398 # $%, list of smashed unquoted effective arguments.
400 return "]percent([" (separator ? separator
: ":") "], $@)["
403 function error
(message
)
405 print message |
"cat >&2"
410 # Accumulate the whole input.
411 request
= request
$0 "\n"
416 request
= substr
(request
, 1, length
(request
) - 1)
417 # The default request is `$f:$l:$n:$*'.
418 colon
= index
(request
, ":")
419 macro
= colon ? substr
(request
, 1, colon
- 1) : request
420 request
= colon ? substr
(request
, colon
+ 1) : "$f:$l:$n:$%"
424 for (cp = request
; cp; cp = substr
(cp, 2))
426 char
= substr
(cp, 1, 1)
429 if (match
(cp, /^\$
[0-9]+/))
432 res
= res
"$" (substr
(cp, 2, RLENGTH
- 1) + 4)
433 cp = substr
(cp, RLENGTH
)
435 else if (substr
(cp, 2, 1) ~
/[fldn$@
%*]/)
437 # $x, no separator given.
438 res
= res trans
(substr
(cp, 2, 1))
441 else if (substr
(cp, 2, 1) == "{")
443 # ${sep}x, long separator.
444 end
= index
(cp, "}")
446 error
("invalid escape: " cp)
447 separator
= substr
(cp, 3, end
- 3)
448 if (substr
(cp, end
+ 1, 1) ~
/[*@
%]/)
449 res
= res trans
(substr
(cp, end
+ 1, 1), separator
)
451 error
("invalid escape: " cp)
452 cp = substr
(cp, end
+ 1)
454 else if (substr
(cp, 3, 1) ~
/[*@
%]/)
456 # $sx, short separator `s'.
457 res
= res trans
(substr
(cp, 3, 1), substr
(cp, 2, 1))
462 error
("invalid escape: " substr
(cp, 1, 2))
469 # Produce the definition of AT_<MACRO> = the translation of the request.
470 print
"define([AT_" macro
"], [[" res
"]])"
474 # Extract both the m4 program and the m4 options from TRACES.
475 eval set dummy
"$traces"
479 # The request may be several lines long, hence sed has to quit.
480 trace_opt
="$trace_opt -t "`echo "$trace" | sed -e 's/:.*//;q'`
481 echo "$trace" |
$AWK -f $tmp/translate.
awk >>$tmp/trace.
m4 ||
exit 1
483 echo "divert(0)dnl" >>$tmp/trace.
m4
485 # Do we trace the initialization?
486 # `errprint' must be silent, otherwise there can be warnings mixed
487 # with traces in m4's stderr.
488 if $initialization; then
489 run_m4_trace
="$run_m4 $trace_opt -daflq -Derrprint"
491 run_m4_trace
="$run_m4f $trace_opt -daflq -Derrprint"
494 # Run m4 on the input file to get traces.
495 $verbose "Running $run_m4_trace $infile | $M4 $tmp/trace.m4" >&2
496 $run_m4_trace $infile 2>&1 >/dev
/null |
497 sed -e 's/^m4trace:\([^:][^:]*\):\([0-9][0-9]*\): -\([0-9][0-9]*\)- \([^(][^(]*\)(\(.*\)$/AT_\4([\1], [\2], [\3], [\4], \5/' \
498 -e 's/^m4trace:\([^:][^:]*\):\([0-9][0-9]*\): -\([0-9][0-9]*\)- \(.*\)$/AT_\4([\1], [\2], [\3], [\4])/' |
499 # Now we are ready to run m4 to process the trace file.
500 $M4 $tmp/trace.
m4 - |
501 # It makes no sense to try to transform __oline__.
513 ## -------------------------------------------------------- ##
514 ## Task --install. Install links to the library m4 files. ##
515 ## -------------------------------------------------------- ##
517 # An m4 program that reports what macros are requested, and where
519 cat >$tmp/request.
m4 <<\EOF
520 dnl Keep the definition of the old AC_DEFUN
521 define
([AC_DEFUN_OLD
], defn
([AC_DEFUN
]))
523 dnl Define the macro so that the first
time it is expanded
, it reports
524 dnl on stderr its name
, and where it was defined.
527 [ifdef
([AC_DECLARED
{$1}],,
528 [define
([AC_DECLARED
{$1}])errprint
(]]__file__
:__line__
:[[ [$1]
532 dnl All the includes must be disabled. If they are not
, since people don
't
533 dnl protect the first argument of AC_DEFUN, then, if read a second time
534 dnl this argument will be expanded, and we'll get pure junk out of
m4.
538 # Run m4 with all the library files, discard stdout, save stderr in
540 run_m4_request
="$run_m4f -dipa -t m4_include -t m4_sinclude $tmp/request.m4"
541 $verbose $run_m4_request $localdir/*.
m4 $AC_ACLOCALDIR/*.
m4 $infile >&2
542 $run_m4_request $localdir/*.
m4 $AC_ACLOCALDIR/*.
m4 $infile 2>&1 >/dev
/null |
543 # Keep only the good lines, there may be other outputs
544 grep '^[^: ]*:[0-9][0-9]*:[^:]*$' >$tmp/requested
546 # Extract the files that are not in the local dir, and install the links.
547 # Save in `installed' the list of installed links.
548 $verbose "Required macros:" >&2
549 $verbose "`sed -e 's/^/| /' $tmp/requested`" >&2
553 file=`echo "$line" | sed -e 's/:.*//'`
554 filename
=`echo "$file" | sed -e 's,.*/,,'`
555 macro
=`echo "$line" | sed -e 's/.*:[ ]*//'`
556 if test -f "$file" && test "x$file" != "x$infile"; then
557 if test -f $localdir/$filename; then
558 $verbose "$filename already installed" >&2
560 $verbose "installing $file which provides $macro" >&2
561 ln -s "$file" "$localdir/$filename" ||
562 cp "$file" "$localdir/$filename" ||
564 echo "$me: cannot link from $file to $localdir/$filename" >&2
568 echo "$localdir/$filename" >>$tmp/installed
571 # Now that we have installed the links, and that we know that the
572 # user needs the FILES, check that there is an exact correspondence.
573 # Use yourself to get the list of the included files.
576 # Not m4_s?include, because it would catch acsite and aclocal, which
577 # we don't care about.
578 $0 -l "$localdir" -t AC_INCLUDE
:'$1' $infile |
581 # All the included files are needed.
582 for file in `cat $tmp/included`;
584 if fgrep
"$file" $tmp/installed
>/dev
/null
2>&1; then :; else
585 echo "\`$file' is uselessly included" >&2
588 # All the needed files are included.
589 for file in `sort $tmp/installed | uniq`;
591 if fgrep
"$file" $tmp/included
>/dev
/null
2>&1; then :; else
592 echo "\`$file' is not included" >&2
603 *)echo "$me: internal error: unknown task: $task" >&2