PageRenderTime 938ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/src/netbsd/src/gnu/dist/autoconf/autoconf.in

https://bitbucket.org/killerpenguinassassins/open_distrib_devel
Autoconf | 770 lines | 511 code | 87 blank | 172 comment | 85 complexity | 8b54c32bfd7ab7c1646068f3c53ca810 MD5 | raw file
Possible License(s): CC0-1.0, MIT, LGPL-2.0, LGPL-3.0, WTFPL, GPL-2.0, BSD-2-Clause, AGPL-3.0, CC-BY-SA-3.0, MPL-2.0, JSON, BSD-3-Clause-No-Nuclear-License-2014, LGPL-2.1, CPL-1.0, AGPL-1.0, 0BSD, ISC, Apache-2.0, GPL-3.0, IPL-1.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. #! @SHELL@
  2. # -*- shell-script -*-
  3. # autoconf -- create `configure' using m4 macros
  4. # Copyright 1992, 1993, 1994, 1996, 1999, 2000, 2001
  5. # Free Software Foundation, Inc.
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2, or (at your option)
  9. # 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.
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  17. # 02111-1307, USA.
  18. me=`echo "$0" | sed -e 's,.*[\\/],,'`
  19. usage="\
  20. Usage: $0 [OPTION] ... [TEMPLATE-FILE]
  21. Generate a configuration script from a TEMPLATE-FILE if given, or
  22. \`configure.ac' if present, or else \`configure.in'. Output is sent
  23. to the standard output if TEMPLATE-FILE is given, else into
  24. \`configure'.
  25. Operation modes:
  26. -h, --help print this help, then exit
  27. -V, --version print version number, then exit
  28. -v, --verbose verbosely report processing
  29. -d, --debug don't remove temporary files
  30. -o, --output=FILE save output in FILE (stdout is the default)
  31. -W, --warnings=CATEGORY report the warnings falling in CATEGORY [syntax]
  32. Warning categories include:
  33. \`cross' cross compilation issues
  34. \`obsolete' obsolete constructs
  35. \`syntax' dubious syntactic constructs
  36. \`all' all the warnings
  37. \`no-CATEGORY' turn off the warnings on CATEGORY
  38. \`none' turn off all the warnings
  39. \`error' warnings are error
  40. The environment variable \`WARNINGS' is honored.
  41. Library directories:
  42. -A, --autoconf-dir=ACDIR Autoconf's macro files location (rarely needed)
  43. -l, --localdir=DIR location of the \`aclocal.m4' file
  44. Tracing:
  45. -t, --trace=MACRO report the list of calls to MACRO
  46. -i, --initialization also trace Autoconf's initialization process
  47. In tracing mode, no configuration script is created.
  48. Report bugs to <bug-autoconf@gnu.org>."
  49. version="\
  50. autoconf (@PACKAGE_NAME@) @VERSION@
  51. Written by David J. MacKenzie.
  52. Copyright 1992, 1993, 1994, 1996, 1999, 2000, 2001
  53. Free Software Foundation, Inc.
  54. This is free software; see the source for copying conditions. There is NO
  55. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
  56. help="\
  57. Try \`$me --help' for more information."
  58. exit_missing_arg="\
  59. echo \"$me: option \\\`\$1' requires an argument\" >&2
  60. echo \"\$help\" >&2
  61. exit 1"
  62. # NLS nuisances.
  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_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi
  66. if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
  67. # ac_LF_and_DOT
  68. # We use echo to avoid assuming a particular line-breaking character.
  69. # The extra dot is to prevent the shell from consuming trailing
  70. # line-breaks from the sub-command output. A line-break within
  71. # single-quotes doesn't work because, if this script is created in a
  72. # platform that uses two characters for line-breaks (e.g., DOS), tr
  73. # would break.
  74. ac_LF_and_DOT=`echo; echo .`
  75. # Find GNU m4.
  76. : ${M4=@M4@}
  77. # Find a good AWK.
  78. : ${AWK=@AWK@}
  79. if echo xfoo | $AWK '/foo|^bar$/ { print }' | grep xfoo >/dev/null; then :; else
  80. echo "$me: the regex engine of $AWK is too broken to be used" >&2
  81. echo "$me: you might want to install GNU AWK" >&2
  82. exit 1
  83. fi
  84. # Variables.
  85. : ${autoconf_dir=${AC_MACRODIR=@datadir@}}
  86. test -z "$AC_ACLOCALDIR" &&
  87. AC_ACLOCALDIR=`(aclocal --print-ac-dir) 2>/dev/null`
  88. debug=false
  89. # Trace Autoconf's initialization?
  90. initialization=false
  91. localdir=.
  92. outfile=
  93. # Exit status.
  94. status=0
  95. # Tasks:
  96. # - trace
  97. # Trace the first arguments of some macros
  98. # - script
  99. # Produce the configure script (default)
  100. task=script
  101. tmp=
  102. verbose=:
  103. # Parse command line.
  104. while test $# -gt 0 ; do
  105. optarg=`expr "x$1" : 'x--[^=]*=\(.*\)' \| \
  106. "x$1" : 'x-.\(.*\)'`
  107. case $1 in
  108. --version | -V )
  109. echo "$version" ; exit 0 ;;
  110. --help | -h )
  111. echo "$usage"; exit 0 ;;
  112. --debug | -d )
  113. debug=:; shift ;;
  114. --verbose | -v )
  115. verbose=echo
  116. shift;;
  117. --localdir=* | -l?* )
  118. localdir=$optarg
  119. shift ;;
  120. --localdir | -l )
  121. test $# = 1 && eval "$exit_missing_arg"
  122. shift
  123. localdir=$1
  124. shift ;;
  125. --autoconf-dir=* | -A?* )
  126. autoconf_dir=$optarg
  127. shift ;;
  128. --autoconf-dir | -A )
  129. test $# = 1 && eval "$exit_missing_arg"
  130. shift
  131. autoconf_dir=$1
  132. shift ;;
  133. --macrodir=* | -m?* )
  134. echo "$me: warning: --macrodir is obsolete, use --autoconf-dir" >&2
  135. autoconf_dir=$optarg
  136. shift ;;
  137. --macrodir | -m )
  138. echo "$me: warning: --macrodir is obsolete, use --autoconf-dir" >&2
  139. test $# = 1 && eval "$exit_missing_arg"
  140. shift
  141. autoconf_dir=$1
  142. shift ;;
  143. --trace=* | -t?* )
  144. task=trace
  145. traces="$traces '"`echo "$optarg" | sed "s/'/'\\\\\\\\''/g"`"'"
  146. shift ;;
  147. --trace | -t )
  148. test $# = 1 && eval "$exit_missing_arg"
  149. task=trace
  150. shift
  151. traces="$traces '"`echo "$1" | sed "s/'/'\\\\\\\\''/g"`"'"
  152. shift ;;
  153. --initialization | -i )
  154. initialization=:
  155. shift;;
  156. --output=* | -o?* )
  157. outfile=$optarg
  158. shift ;;
  159. --output | -o )
  160. test $# = 1 && eval "$exit_missing_arg"
  161. shift
  162. outfile=$1
  163. shift ;;
  164. --warnings=* | -W?* )
  165. warnings=$warnings,$optarg
  166. shift ;;
  167. --warnings | -W )
  168. test $# = 1 && eval "$exit_missing_arg"
  169. shift
  170. warnings=$warnings,$1
  171. shift ;;
  172. -- ) # Stop option processing
  173. shift; break ;;
  174. - ) # Use stdin as input.
  175. break ;;
  176. -* )
  177. exec >&2
  178. echo "$me: invalid option $1"
  179. echo "$help"
  180. exit 1 ;;
  181. * )
  182. break ;;
  183. esac
  184. done
  185. # The warnings are the concatenation of 1. application's defaults,
  186. # 2. $WARNINGS, $3 command line options, in that order.
  187. # Set them in the order expected by the M4 macros: the converse.
  188. alphabet='abcdefghijklmnopqrstuvwxyz'
  189. ALPHABET='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  190. NUMBERS='0123456789'
  191. WORDCHAR=_$alphabet$ALPHABET$NUMBERS
  192. m4_warnings=
  193. for warning in `IFS=,; echo syntax $WARNINGS $warnings |
  194. tr $ALPHABET $alphabet`
  195. do
  196. test -n $warning || continue
  197. m4_warnings="$warning"`test -n "$m4_warnings" && echo ",$m4_warnings"`
  198. done
  199. # Trap on 0 to stop playing with `rm'.
  200. $debug ||
  201. {
  202. trap 'status=$?; rm -rf $tmp && exit $status' 0
  203. trap '(exit 1); exit 1' 1 2 13 15
  204. }
  205. # Create a (secure) tmp directory for tmp files.
  206. : ${TMPDIR=/tmp}
  207. {
  208. tmp=`(umask 077 && mktemp -d -q "$TMPDIR/acXXXXXX") 2>/dev/null` &&
  209. test -n "$tmp" && test -d "$tmp"
  210. } ||
  211. {
  212. tmp=$TMPDIR/ac$$
  213. (umask 077 && mkdir $tmp)
  214. } ||
  215. {
  216. echo "$me: cannot create a temporary directory in $TMPDIR" >&2
  217. (exit 1); exit 1;
  218. }
  219. # Running m4.
  220. test -f "$autoconf_dir/acsite.m4" && acsite_m4="$autoconf_dir/acsite.m4"
  221. test -f "$localdir/aclocal.m4" && aclocal_m4="$localdir/aclocal.m4"
  222. m4_common="-I $autoconf_dir -I $localdir -Dm4_tmpdir=$tmp"
  223. m4_prefiles=" $autoconf_dir/autoconf.m4 $acsite_m4 $aclocal_m4"
  224. m4f_prefiles=$m4_prefiles
  225. run_m4="$M4 $m4_common"
  226. # Find the input file.
  227. case $# in
  228. 0)
  229. case `ls configure.ac configure.in 2>/dev/null` in
  230. *ac*in )
  231. echo "$me: warning: both \`configure.ac' and \`configure.in' are present." >&2
  232. echo "$me: warning: proceeding with \`configure.ac'." >&2
  233. infile=configure.ac;;
  234. *ac ) infile=configure.ac;;
  235. *in ) infile=configure.in;;
  236. * )
  237. echo "$me: no input file" >&2
  238. exit 1;;
  239. esac
  240. test $task = script && test -z "$outfile" && outfile=configure;;
  241. 1) infile=$1 ;;
  242. *) exec >&2
  243. echo "$me: invalid number of arguments."
  244. echo "$help"
  245. (exit 1); exit 1 ;;
  246. esac
  247. # Unless specified, the output is stdout.
  248. test -z "$outfile" && outfile=-
  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); exit 1
  256. fi
  257. # Output is produced into FD 4. Prepare it.
  258. case $outfile in
  259. -) # Output to stdout
  260. exec 4>&1 ;;
  261. * )
  262. exec 4>$outfile;;
  263. esac
  264. # Initializations are performed. Proceed to the main task.
  265. case $task in
  266. ## --------------------------------- ##
  267. ## Generate the `configure' script. ##
  268. ## --------------------------------- ##
  269. script)
  270. # M4 expansion.
  271. : >$tmp/forbidden.rx
  272. : >$tmp/allowed.rx
  273. $verbose "$me: running $run_m4 -Dm4_warnings=$m4_warnings $m4f_prefiles $infile" >&2
  274. $run_m4 -Dm4_warnings=$m4_warnings $m4f_prefiles $infile >$tmp/configure ||
  275. { (exit 1); exit 1; }
  276. if test "x$outfile" != x-; then
  277. chmod +x $outfile
  278. fi
  279. # Put the real line numbers into configure to make config.log more
  280. # helpful. Because quoting can sometimes get really painful in m4,
  281. # there are special @tokens@ to substitute.
  282. sed 's/^ //' >"$tmp/finalize.awk" <<EOF
  283. # Load the list of tokens which escape the forbidden patterns.
  284. BEGIN {
  285. # Be sure the read GAWK documentation to understand the parens
  286. # around \`tmp "/forbidden.rx"'.
  287. while ((getline pattern < (tmp "/forbidden.rx")) > 0)
  288. forbidden = (forbidden ? forbidden "|" : "") pattern
  289. close (tmp "/forbidden.rx")
  290. if (verbose)
  291. errprint("$me: forbidden: " forbidden)
  292. while ((getline pattern < (tmp "/allowed.rx")) > 0)
  293. allowed = (allowed ? allowed "|" : "") pattern
  294. if (!allowed)
  295. allowed = "^$"
  296. close (tmp "/allowed.rx")
  297. if (verbose)
  298. errprint("$me: allowed: " allowed)
  299. }
  300. function errprint (message)
  301. {
  302. # BAD! the pipe to 'cat >&2' doesn't work for DJGPP.
  303. # print message | "cat >&2"
  304. # Use normal redirection instead:
  305. print message > "$tmp/finalize.err"
  306. }
  307. function undefined (file, line, macro)
  308. {
  309. errprint(file ":" line ": error: possibly undefined macro: " macro)
  310. }
  311. # Body.
  312. {
  313. sub (/[ \t]*$/, "")
  314. if (\$0 == "")
  315. {
  316. if (!duplicate)
  317. {
  318. oline++
  319. print
  320. }
  321. duplicate = 1
  322. next
  323. }
  324. duplicate = 0
  325. oline++
  326. if (\$0 ~ /__oline__/)
  327. while (sub (/__oline__/, oline))
  328. continue
  329. while (sub (/@<:@/, "["))
  330. continue
  331. while (sub (/@:>@/, "]"))
  332. continue
  333. while (sub (/@S\|@/, "$"))
  334. continue
  335. while (sub (/@%:@/, "#"))
  336. continue
  337. print
  338. # Dubious feature: we tolerate macro names when commented.
  339. sub (/#.*/, "")
  340. # Get the tokens.
  341. split (\$0, tokens, /[^$WORDCHAR]*/)
  342. for (token in tokens)
  343. if (match (tokens[token], forbidden) &&
  344. !match (tokens[token], allowed))
  345. {
  346. macros [tokens [token]] = oline
  347. some_macros_were_not_expanded = 1
  348. }
  349. }
  350. # If there are some macros which are left unexpanded in the output,
  351. # try to find the input which is responsible. Otherwise, try to help.
  352. END {
  353. if (some_macros_were_not_expanded)
  354. {
  355. line = 0
  356. while (getline < "$infile")
  357. {
  358. line++
  359. for (macro in macros)
  360. if (index (\$0, macro))
  361. {
  362. delete macros [macro]
  363. undefined("$infile", line, macro)
  364. }
  365. }
  366. close ("$infile")
  367. for (macro in macros)
  368. undefined("$outfile", macros [macro], macro)
  369. exit 1
  370. }
  371. }
  372. EOF
  373. $AWK -v tmp="$tmp" \
  374. `$verbose "-v verbose=1"` \
  375. -f "$tmp/finalize.awk" <$tmp/configure >&4 ||
  376. { test -f "$tmp/finalize.err" && cat "$tmp/finalize.err" >&2
  377. (exit 1); exit 1; }
  378. test -f "$tmp/finalize.err" && cat "$tmp/finalize.err" >&2
  379. ;; # End of the task script.
  380. ## -------------- ##
  381. ## Trace macros. ##
  382. ## -------------- ##
  383. trace)
  384. # trace.m4
  385. # --------
  386. # Routines to process formatted m4 traces.
  387. sed 's/^ //' >$tmp/trace.m4 <<\EOF
  388. divert(-1)
  389. changequote([, ])
  390. # _at_MODE(SEPARATOR, ELT1, ELT2...)
  391. # ----------------------------------
  392. # List the elements, separating then with SEPARATOR.
  393. # MODE can be:
  394. # `at' -- the elements are enclosed in brackets.
  395. # `star' -- the elements are listed as are.
  396. # `percent' -- the elements are `flattened': spaces are singled out,
  397. # and no new line remains.
  398. define([_at_at],
  399. [at_ifelse([$#], [1], [],
  400. [$#], [2], [[[$2]]],
  401. [[[$2]][$1]$0([$1], at_shift(at_shift($@)))])])
  402. define([_at_percent],
  403. [at_ifelse([$#], [1], [],
  404. [$#], [2], [at_flatten([$2])],
  405. [at_flatten([$2])[$1]$0([$1], at_shift(at_shift($@)))])])
  406. define([_at_star],
  407. [at_ifelse([$#], [1], [],
  408. [$#], [2], [[$2]],
  409. [[$2][$1]$0([$1], at_shift(at_shift($@)))])])
  410. # FLATTEN quotes its result.
  411. define([at_flatten],
  412. [at_patsubst(at_patsubst(at_patsubst([[[$1]]],
  413. [\\
  414. ]),
  415. [[
  416. ]+],
  417. [ ]),
  418. [^ *\(.*\) *$], [[\1]])])
  419. define([at_args], [at_shift(at_shift(at_shift(at_shift(at_shift($@)))))])
  420. define([at_at], [_$0([$1], at_args($@))])
  421. define([at_percent], [_$0([$1], at_args($@))])
  422. define([at_star], [_$0([$1], at_args($@))])
  423. EOF
  424. # If you trace `define', then on `define([m4_exit], defn([m4exit])' you
  425. # will produce
  426. #
  427. # AT_define([m4sugar.m4], [115], [1], [define], [m4_exit], <m4exit>)
  428. #
  429. # Since `<m4exit>' is not quoted, the outter m4, when processing
  430. # `trace.m4' will exit prematurely. Hence, move all the builtins to
  431. # the `at_' name space.
  432. echo '# Copy the builtins.' >>$tmp/trace.m4
  433. echo "dumpdef" |
  434. $M4 2>&1 >/dev/null |
  435. sed 's/^\([^:]*\):.*/define([at_\1], defn([\1]))/' >>$tmp/trace.m4
  436. echo >>$tmp/trace.m4
  437. echo '# Disable the builtins.' >>$tmp/trace.m4
  438. echo "dumpdef" |
  439. $M4 2>&1 >/dev/null |
  440. sed 's/^\([^:]*\):.*/at_undefine([\1])/' >>$tmp/trace.m4
  441. echo >>$tmp/trace.m4
  442. # trace2m4.sed
  443. # ------------
  444. # Transform the traces from m4 into an m4 input file.
  445. # Typically, transform:
  446. #
  447. # | m4trace:configure.ac:3: -1- AC_SUBST([exec_prefix], [NONE])
  448. #
  449. # into
  450. #
  451. # | AT_AC_SUBST([configure.ac], [3], [1], [AC_SUBST], [exec_prefix], [NONE])
  452. #
  453. # Pay attention that the file name might include colons, if under DOS
  454. # for instance, so we don't use `[^:][^:]*'.
  455. # The first s/// catches multiline traces, the second, traces as above.
  456. preamble='m4trace:\(..*\):\([0-9][0-9]*\): -\([0-9][0-9]*\)-'
  457. cat >$tmp/trace2m4.sed <<EOF
  458. s/^$preamble \([^(][^(]*\)(\(.*\)$/AT_\4([\1], [\2], [\3], [\4], \5/
  459. s/^$preamble \(.*\)$/AT_\4([\1], [\2], [\3], [\4])/
  460. EOF
  461. # translate.awk
  462. # -------------
  463. # Translate user tracing requests into m4 macros.
  464. cat >$tmp/translate.awk <<\EOF
  465. function trans (arg, sep)
  466. {
  467. # File name.
  468. if (arg == "f")
  469. return "$1"
  470. # Line number.
  471. if (arg == "l")
  472. return "$2"
  473. # Depth.
  474. if (arg == "d")
  475. return "$3"
  476. # Name (also available as $0).
  477. if (arg == "n")
  478. return "$4"
  479. # Escaped dollar.
  480. if (arg == "$")
  481. return "$"
  482. # $@, list of quoted effective arguments.
  483. if (arg == "@")
  484. return "]at_at([" (separator ? separator : ",") "], $@)["
  485. # $*, list of unquoted effective arguments.
  486. if (arg == "*")
  487. return "]at_star([" (separator ? separator : ",") "], $@)["
  488. # $%, list of flattened unquoted effective arguments.
  489. if (arg == "%")
  490. return "]at_percent([" (separator ? separator : ":") "], $@)["
  491. }
  492. function error (message)
  493. {
  494. print message | "cat >&2"
  495. exit 1
  496. }
  497. {
  498. # Accumulate the whole input.
  499. request = request $0 "\n"
  500. }
  501. END {
  502. # Chomp.
  503. request = substr (request, 1, length (request) - 1)
  504. # The default request is `$f:$l:$n:$*'.
  505. colon = index (request, ":")
  506. macro = colon ? substr (request, 1, colon - 1) : request
  507. request = colon ? substr (request, colon + 1) : "$f:$l:$n:$%"
  508. res = ""
  509. for (cp = request; cp; cp = substr (cp, 2))
  510. {
  511. char = substr (cp, 1, 1)
  512. if (char == "$")
  513. {
  514. if (match (cp, /^\$[0-9]+/))
  515. {
  516. # $n -> $(n + 4)
  517. res = res "$" (substr (cp, 2, RLENGTH - 1) + 4)
  518. cp = substr (cp, RLENGTH)
  519. }
  520. else if (substr (cp, 2, 1) ~ /[fldn$@%*]/)
  521. {
  522. # $x, no separator given.
  523. res = res trans(substr (cp, 2, 1))
  524. cp = substr (cp, 2)
  525. }
  526. else if (substr (cp, 2, 1) == "{")
  527. {
  528. # ${sep}x, long separator.
  529. end = index (cp, "}")
  530. if (!end)
  531. error("invalid escape: " cp)
  532. separator = substr (cp, 3, end - 3)
  533. if (substr (cp, end + 1, 1) ~ /[*@%]/)
  534. res = res trans(substr (cp, end + 1, 1), separator)
  535. else
  536. error("invalid escape: " cp)
  537. cp = substr (cp, end + 1)
  538. }
  539. else if (substr (cp, 3, 1) ~ /[*@%]/)
  540. {
  541. # $sx, short separator `s'.
  542. res = res trans(substr (cp, 3, 1), substr (cp, 2, 1))
  543. cp = substr(cp, 3)
  544. }
  545. else
  546. {
  547. error("invalid escape: " substr (cp, 1, 2))
  548. }
  549. }
  550. else
  551. res = res char
  552. }
  553. # Produce the definition of AT_<MACRO> = the translation of the request.
  554. print "at_define([AT_" macro "],"
  555. print "[[" res "]])"
  556. print ""
  557. close("cat >&2")
  558. }
  559. EOF
  560. # Extract both the m4 program and the m4 options from TRACES.
  561. echo "## ------------------------- ##" >>$tmp/trace.m4
  562. echo "## Trace processing macros. ##" >>$tmp/trace.m4
  563. echo "## ------------------------- ##" >>$tmp/trace.m4
  564. echo >>$tmp/trace.m4
  565. eval set dummy "$traces"
  566. shift
  567. for trace
  568. do
  569. echo "# $trace" >>$tmp/trace.m4
  570. # The request may be several lines long, hence sed has to quit.
  571. macro_name=`echo "$trace" | sed 's/:.*//;q'`
  572. # If for instance TRACE is `define', be sure to have an empty
  573. # TRACE_FORMAT.
  574. case $trace in
  575. $macro_name:* )
  576. trace_format=`echo "$trace" | sed "1s/^$macro_name:/:/"`;;
  577. * )
  578. trace_format=;;
  579. esac
  580. # GNU M4 1.4's tracing of builtins is buggy. When run on this input:
  581. #
  582. # | divert(-1)
  583. # | changequote([, ])
  584. # | define([m4_eval], defn([eval]))
  585. # | eval(1)
  586. # | m4_eval(2)
  587. # | undefine([eval])
  588. # | m4_eval(3)
  589. #
  590. # it behaves this way:
  591. #
  592. # | % m4 input.m4 -da -t eval
  593. # | m4trace: -1- eval(1)
  594. # | m4trace: -1- m4_eval(2)
  595. # | m4trace: -1- m4_eval(3)
  596. # | %
  597. #
  598. # Conversely:
  599. #
  600. # | % m4 input.m4 -da -t m4_eval
  601. # | %
  602. #
  603. # So we will merge them, i.e. tracing `BUILTIN' or tracing
  604. # `m4_BUILTIN' will be the same: tracing both, but honoring the
  605. # *last* trace specification.
  606. # FIXME: This is not enough: in the output `$0' will be `BUILTIN'
  607. # sometimes and `m4_BUILTIN' at others. We should render a unique name,
  608. # the one specified by the user.
  609. base_name=`echo "$macro_name" | sed 's/^m4_//'`
  610. if echo "ifdef(\`$base_name', \`', \`m4exit(-1)')" | $M4; then
  611. # BASE_NAME is a builtin.
  612. trace_opt="$trace_opt -t $base_name -t m4_$base_name"
  613. echo "$base_name$trace_format" |
  614. $AWK -f $tmp/translate.awk >>$tmp/trace.m4 ||
  615. { (exit 1); exit 1; }
  616. echo "m4_$base_name$trace_format" |
  617. $AWK -f $tmp/translate.awk >>$tmp/trace.m4 ||
  618. { (exit 1); exit 1; }
  619. else
  620. # MACRO_NAME is not a builtin.
  621. trace_opt="$trace_opt -t $macro_name"
  622. echo "$trace" |
  623. $AWK -f $tmp/translate.awk >>$tmp/trace.m4 ||
  624. { (exit 1); exit 1; }
  625. fi
  626. echo >>$tmp/trace.m4
  627. done
  628. echo "## ------------------- ##" >>$tmp/trace.m4
  629. echo "## Traces to process. ##" >>$tmp/trace.m4
  630. echo "## ------------------- ##" >>$tmp/trace.m4
  631. echo >>$tmp/trace.m4
  632. echo "at_divert(0)at_dnl" >>$tmp/trace.m4
  633. # Do we trace the initialization?
  634. # `errprint' must be silent, otherwise there can be warnings mixed
  635. # with traces in m4's stderr.
  636. run_m4_trace="$run_m4 $trace_opt -daflq -Derrprint"
  637. if $initialization; then
  638. trace_prefiles="$m4_prefiles"
  639. else
  640. trace_prefiles="$m4f_prefiles"
  641. fi
  642. # Run m4 on the input file to get traces.
  643. #
  644. # We used to have a simple pipe, which was very convenient as it
  645. # allows to use traces on never ending expansions (i.e., when
  646. # debugging :) but it is requires to keep error messages *and*
  647. # traces in stderr. This is too fragile, as it results in
  648. # unexpected data in the output. autoheader has been fragile to
  649. # this.
  650. $verbose "$me: running $run_m4_trace -o $tmp/traces $trace_prefiles $infile" >&2
  651. $run_m4_trace -o $tmp/traces $trace_prefiles $infile >/dev/null ||
  652. {
  653. echo "$me: tracing failed" >&2
  654. (exit 1); exit 1
  655. }
  656. $verbose "$me: running $M4 $tmp/trace.m4" >&2
  657. sed -f $tmp/trace2m4.sed $tmp/traces |
  658. # Now we are ready to run m4 to process the trace file.
  659. if $debug; then
  660. cat >>$tmp/trace.m4
  661. $M4 $tmp/trace.m4
  662. else
  663. $M4 $tmp/trace.m4 -
  664. fi |
  665. # It makes no sense to try to transform __oline__.
  666. sed '
  667. s/@<:@/[/g
  668. s/@:>@/]/g
  669. s/@S|@/$/g
  670. s/@%:@/#/g
  671. ' >&4 ||
  672. {
  673. echo "$me: traces formatting failed" >&2
  674. (exit 1); exit 1
  675. }
  676. ;;
  677. ## ------------ ##
  678. ## Unknown task ##
  679. ## ------------ ##
  680. *) echo "$me: internal error: unknown task: $task" >&2
  681. (exit 1); exit 1
  682. esac
  683. (exit $status); exit $status