*** empty log message ***
[autoconf.git] / autoconf.sh
blob31d7cfccdbdcf018a941b22ea04d40de18cabf68
1 #! @SHELL@
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)
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 # 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,.*/,,'`
26 usage="\
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'.
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 -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
50 Tracing:
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>."
58 version="\
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."
66 help="\
67 Try \`$me --help' for more information."
69 # NLS nuisances.
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
79 # ac_LF_and_DOT
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
85 # would break.
86 ac_LF_and_DOT=`echo; echo .`
88 # Find GNU m4.
89 # Handle the case that m4 has moved since we were configured.
90 # It may have been found originally in a build directory.
91 : ${M4=@M4@}
92 case "$M4" in
93 /*) test -f "$M4" || M4=m4 ;;
94 esac
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
97 *reload-state*);;
98 *) echo "$me: Autoconf requires GNU m4 1.4 or later" >&2; exit 1 ;;
99 esac
101 # Variables.
102 : ${AC_MACRODIR=@datadir@}
103 : ${AC_ACLOCALDIR=`(aclocal --print-ac-dir) 2>/dev/null`}
104 : ${AWK=@AWK@}
105 debug=false
106 # Trace Autoconf's initialization?
107 initialization=false
108 localdir=
109 outfile=
110 # Exit status.
111 status=0
112 # Tasks:
113 # - install
114 # Install links to the needed *.m4 extensions.
115 # - trace
116 # Trace the first arguments of some macros
117 # - script
118 # Produce the configure script (default)
119 task=script
120 tmp=
121 verbose=:
123 # Parse command line
124 while test $# -gt 0 ; do
125 case "$1" in
126 --version | --vers* | -V )
127 echo "$version" ; exit 0 ;;
128 --help | --h* | -h )
129 echo "$usage"; exit 0 ;;
131 --debug | --d* | -d )
132 debug=:; shift ;;
133 --verbose | --verb* | -v )
134 verbose=echo
135 shift;;
137 --localdir=* | --l*=* )
138 localdir=`echo "$1" | sed -e 's/^[^=]*=//'`
139 shift ;;
140 --localdir | --l* | -l )
141 shift
142 test $# = 0 && { echo "$help" >&2; exit 1; }
143 localdir=$1
144 shift ;;
146 --macrodir=* | --m*=* )
147 AC_MACRODIR=`echo "$1" | sed -e 's/^[^=]*=//'`
148 shift ;;
149 --macrodir | --m* | -m )
150 shift
151 test $# = 0 && { echo "$help" >&2; exit 1; }
152 AC_MACRODIR=$1
153 shift ;;
155 --install )
156 task=install
157 shift;;
159 --trace | -t )
160 task=trace
161 shift
162 test $# = 0 && { echo "$help" >&2; exit 1; }
163 traces="$traces '"`echo "$1" | sed "s/'/'\\\\\\\\''/g"`"'"
164 shift ;;
165 --trace=* )
166 task=trace
167 traces="$traces '"`echo "$1" |
168 sed -e "s/^[^=]*=//;s/:.*//;s/'/'\\\\\\\\''/g"`"'"
169 shift ;;
170 --initialization | -i )
171 initialization=:
172 shift;;
174 --output | -o )
175 shift
176 test $# = 0 && { echo "$help" >&2; exit 1; }
177 outfile=$1
178 shift ;;
179 --output=* )
180 outfile=`echo "$1" | sed -e 's/^[^=]*=//'`
181 shift ;;
183 --warnings | -W )
184 shift
185 test $# = 0 && { echo "$help" >&2; exit 1; }
186 warnings="$warnings "`echo $1 | sed -e 's/,/ /g'`
187 shift ;;
188 --warnings=* )
189 warnings="$warnings "`echo "$1" | sed -e 's/^[^=]*=//;s/,/ /g'`
190 shift ;;
191 -W* ) # People are used to -Wall, -Werror etc.
192 warnings="$warnings "`echo "$1" | sed -e 's/^-W//;s/,/ /g'`
193 shift ;;
195 -- ) # Stop option processing
196 shift; break ;;
197 - ) # Use stdin as input.
198 break ;;
199 -* )
200 exec >&2
201 echo "$me: invalid option $1"
202 echo "$help"
203 exit 1 ;;
205 break ;;
206 esac
207 done
209 # Support $WARNINGS.
210 : ${warnings=`echo $WARNINGS | sed -e 's/,/ /g'`}
212 # Trap on 0 to stop playing with `rm'.
213 $debug ||
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.
220 : ${TMPDIR=/tmp}
222 tmp=`(umask 077 && mktemp -d -q "$TMPDIR/acXXXXXX") 2>/dev/null` &&
223 test -n "$tmp"
224 } ||
226 tmp=$TMPDIR/ac$$ && (umask 077 && mkdir $tmp)
227 } ||
229 echo "$me: cannot create a temporary directory in $TMPDIR" >&2
230 exit 1;
233 # Running m4.
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.
239 case $# in
240 0) infile=configure.in
241 test $task = script && test "x$outfile" = x && outfile=configure;;
242 1) infile=$1 ;;
243 *) exec >&2
244 echo "$me: invalid number of arguments."
245 echo "$help"
246 exit 1 ;;
247 esac
249 # We need an actual file.
250 if test z$infile = z-; then
251 infile=$tmp/stdin
252 cat >$infile
253 elif test ! -r "$infile"; then
254 echo "$me: $infile: No such file or directory" >&2
255 exit 1
258 # Output is produced into FD 4. Prepare it.
259 case "x$outfile" in
260 x- | x ) # Output to stdout
261 exec 4>&1 ;;
263 exec 4>$outfile;;
264 esac
266 # Initializations are performed. Proceed to the main task.
267 case $task in
269 ## --------------------------------- ##
270 ## Generate the `configure' script. ##
271 ## --------------------------------- ##
272 script)
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
280 # alternation.
281 pattern="A[CHM]_"
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 |
286 while read macro; do
287 grep -n "^[^#]*$macro" $infile /dev/null
288 test $? = 1 && echo "***BUG in Autoconf--please report*** $macro"
289 done | sort -u >&2
290 status=1
293 if test -n "$outfile"; then
294 chmod +x $outfile
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.
300 $AWK '
302 sub(/[ ]*$/, "")
303 if ($0 == "")
305 if (!duplicate)
306 print
307 duplicate = 1
308 next
310 duplicate = 0
311 oline++
312 if ($0 ~ /__oline__/)
313 while (sub(/__oline__/, oline))
314 continue
315 while (sub(/@<:@/, "["))
316 continue
317 while (sub(/@:>@/, "]"))
318 continue
319 while (sub(/@S\|@/, "$"))
320 continue
321 while (sub(/@%:@/, "#"))
322 continue
323 print
324 }' <$tmp/configure >&4
325 ;; # End of the task script.
329 ## -------------- ##
330 ## Trace macros. ##
331 ## -------------- ##
332 trace)
333 # A program to trace m4 macros.
334 cat >$tmp/trace.m4 <<\EOF
335 divert(-1)
336 changequote([, ])
337 # _MODE(SEPARATOR, ELT1, ELT2...)
338 # -------------------------------
339 # List the elements, separating then with SEPARATOR.
340 # MODE can be:
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.
345 define([_at],
346 [ifelse([$#], [1], [],
347 [$#], [2], [[[$2]]],
348 [[[$2]][$1]$0([$1], shift(shift($@)))])])
349 define([_percent],
350 [ifelse([$#], [1], [],
351 [$#], [2], [smash([$2])],
352 [smash([$2])[$1]$0([$1], shift(shift($@)))])])
353 define([_star],
354 [ifelse([$#], [1], [],
355 [$#], [2], [[$2]],
356 [[$2][$1]$0([$1], shift(shift($@)))])])
358 # Smash quotes its result.
359 define([smash],
360 [patsubst(patsubst(patsubst([[[$1]]],
364 ]+],
365 [ ]),
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)
376 # File name.
377 if (arg == "f")
378 return "$1"
379 # Line number.
380 if (arg == "l")
381 return "$2"
382 # Depth.
383 if (arg == "d")
384 return "$3"
385 # Name (also available as $0).
386 if (arg == "n")
387 return "$4"
388 # Escaped dollar.
389 if (arg == "$")
390 return "$"
392 # $@, list of quoted effective arguments.
393 if (arg == "@")
394 return "]at([" (separator ? separator : ",") "], $@)["
395 # $*, list of unquoted effective arguments.
396 if (arg == "*")
397 return "]star([" (separator ? separator : ",") "], $@)["
398 # $%, list of smashed unquoted effective arguments.
399 if (arg == "%")
400 return "]percent([" (separator ? separator : ":") "], $@)["
403 function error (message)
405 print message | "cat >&2"
406 exit 1
410 # Accumulate the whole input.
411 request = request $0 "\n"
414 END {
415 # Chomp.
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:$%"
422 res = ""
424 for (cp = request; cp; cp = substr (cp, 2))
426 char = substr (cp, 1, 1)
427 if (char == "$")
429 if (match (cp, /^\$[0-9]+/))
431 # $n -> $(n + 4)
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))
439 cp = substr (cp, 2)
441 else if (substr (cp, 2, 1) == "{")
443 # ${sep}x, long separator.
444 end = index (cp, "}")
445 if (!end)
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)
450 else
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))
458 cp = substr(cp, 3)
460 else
462 error("invalid escape: " substr (cp, 1, 2))
465 else
466 res = res char
469 # Produce the definition of AT_<MACRO> = the translation of the request.
470 print "define([AT_" macro "], [[" res "]])"
471 close("cat >&2")
474 # Extract both the m4 program and the m4 options from TRACES.
475 eval set dummy "$traces"
476 shift
477 for trace
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
482 done
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"
490 else
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__.
502 sed '
503 s/@<:@/[/g
504 s/@:>@/]/g
505 s/@S|@/$/g
506 s/@%:@/#/g
507 ' >&4
513 ## -------------------------------------------------------- ##
514 ## Task --install. Install links to the library m4 files. ##
515 ## -------------------------------------------------------- ##
516 install)
517 # An m4 program that reports what macros are requested, and where
518 # they were defined.
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.
525 define([AC_DEFUN],
526 [AC_DEFUN_OLD([$1],
527 [ifdef([AC_DECLARED{$1}],,
528 [define([AC_DECLARED{$1}])errprint(]]__file__:__line__:[[ [$1]
529 )])dnl
530 ][$2])])
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.
535 define([AC_INCLUDE])
538 # Run m4 with all the library files, discard stdout, save stderr in
539 # $requested.
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
550 cat $tmp/requested |
551 while read line
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
559 else
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
565 exit 1
568 echo "$localdir/$filename" >>$tmp/installed
570 done
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.
574 export AC_ACLOCALDIR
575 export AC_MACRODIR
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 |
579 sort |
580 uniq >$tmp/included
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
587 done
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
594 done
599 ## ------------ ##
600 ## Unknown task ##
601 ## ------------ ##
603 *)echo "$me: internal error: unknown task: $task" >&2
604 exit 1
605 esac
607 exit $status