2
0

autoheader.in 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. #! @PERL@
  2. # -*- Perl -*-
  3. # @configure_input@
  4. eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac'
  5. if 0;
  6. # autoheader -- create `config.h.in' from `configure.ac'
  7. # Copyright (C) 1992-1994, 1996, 1998-2012 Free Software Foundation,
  8. # Inc.
  9. # This program is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation, either version 3 of the License, or
  12. # (at your option) any later version.
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. # Written by Roland McGrath.
  20. # Rewritten in Perl by Akim Demaille.
  21. BEGIN
  22. {
  23. my $pkgdatadir = $ENV{'autom4te_perllibdir'} || '@pkgdatadir@';
  24. unshift @INC, "$pkgdatadir";
  25. # Override SHELL. On DJGPP SHELL may not be set to a shell
  26. # that can handle redirection and quote arguments correctly,
  27. # e.g.: COMMAND.COM. For DJGPP always use the shell that configure
  28. # has detected.
  29. $ENV{'SHELL'} = '@SHELL@' if ($^O eq 'dos');
  30. }
  31. use Autom4te::ChannelDefs;
  32. use Autom4te::Channels;
  33. use Autom4te::Configure_ac;
  34. use Autom4te::FileUtils;
  35. use Autom4te::General;
  36. use Autom4te::XFile;
  37. use strict;
  38. # Using `do FILE', we need `local' vars.
  39. use vars qw ($config_h %verbatim %symbol);
  40. # Lib files.
  41. my $autom4te = $ENV{'AUTOM4TE'} || '@bindir@/@autom4te-name@';
  42. local $config_h;
  43. my $config_h_in;
  44. my @prepend_include;
  45. my @include;
  46. # $HELP
  47. # -----
  48. $help = "Usage: $0 [OPTION]... [TEMPLATE-FILE]
  49. Create a template file of C \`\#define\' statements for \`configure\' to
  50. use. To this end, scan TEMPLATE-FILE, or \`configure.ac\' if present,
  51. or else \`configure.in\'.
  52. -h, --help print this help, then exit
  53. -V, --version print version number, then exit
  54. -v, --verbose verbosely report processing
  55. -d, --debug don\'t remove temporary files
  56. -f, --force consider all files obsolete
  57. -W, --warnings=CATEGORY report the warnings falling in CATEGORY
  58. " . Autom4te::ChannelDefs::usage () . "
  59. Library directories:
  60. -B, --prepend-include=DIR prepend directory DIR to search path
  61. -I, --include=DIR append directory DIR to search path
  62. Report bugs to <bug-autoconf\@gnu.org>.
  63. GNU Autoconf home page: <http://www.gnu.org/software/autoconf/>.
  64. General help using GNU software: <http://www.gnu.org/gethelp/>.
  65. ";
  66. # $VERSION
  67. # --------
  68. $version = "autoheader (@PACKAGE_NAME@) @VERSION@
  69. Copyright (C) @RELEASE_YEAR@ Free Software Foundation, Inc.
  70. License GPLv3+/Autoconf: GNU GPL version 3 or later
  71. <http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.html>
  72. This is free software: you are free to change and redistribute it.
  73. There is NO WARRANTY, to the extent permitted by law.
  74. Written by Roland McGrath and Akim Demaille.
  75. ";
  76. ## ---------- ##
  77. ## Routines. ##
  78. ## ---------- ##
  79. # parse_args ()
  80. # -------------
  81. # Process any command line arguments.
  82. sub parse_args ()
  83. {
  84. my $srcdir;
  85. parse_WARNINGS;
  86. getopt ('I|include=s' => \@include,
  87. 'B|prepend-include=s' => \@prepend_include,
  88. 'W|warnings=s' => \&parse_warnings);
  89. if (! @ARGV)
  90. {
  91. my $configure_ac = require_configure_ac;
  92. push @ARGV, $configure_ac;
  93. }
  94. }
  95. ## -------------- ##
  96. ## Main program. ##
  97. ## -------------- ##
  98. mktmpdir ('ah');
  99. switch_warning 'obsolete';
  100. parse_args;
  101. # Preach.
  102. my $config_h_top = find_file ("config.h.top?",
  103. reverse (@prepend_include), @include);
  104. my $config_h_bot = find_file ("config.h.bot?",
  105. reverse (@prepend_include), @include);
  106. my $acconfig_h = find_file ("acconfig.h?",
  107. reverse (@prepend_include), @include);
  108. if ($config_h_top || $config_h_bot || $acconfig_h)
  109. {
  110. my $msg = << "END";
  111. Using auxiliary files such as \`acconfig.h\', \`config.h.bot\'
  112. and \`config.h.top\', to define templates for \`config.h.in\'
  113. is deprecated and discouraged.
  114. Using the third argument of \`AC_DEFINE\' and
  115. \`AC_DEFINE_UNQUOTED\' allows one to define a template without
  116. \`acconfig.h\':
  117. AC_DEFINE([NEED_FUNC_MAIN], 1,
  118. [Define if a function \`main\' is needed.])
  119. More sophisticated templates can also be produced, see the
  120. documentation.
  121. END
  122. $msg =~ s/^ /WARNING: /gm;
  123. msg 'obsolete', $msg;
  124. }
  125. # Set up autoconf.
  126. my $autoconf = "'$autom4te' --language=autoconf ";
  127. $autoconf .= join (' --include=', '', map { shell_quote ($_) } @include);
  128. $autoconf .= join (' --prepend-include=', '', map { shell_quote ($_) } @prepend_include);
  129. $autoconf .= ' --debug' if $debug;
  130. $autoconf .= ' --force' if $force;
  131. $autoconf .= ' --verbose' if $verbose;
  132. # ----------------------- #
  133. # Real work starts here. #
  134. # ----------------------- #
  135. # Source what the traces are trying to tell us.
  136. verb "$me: running $autoconf to trace from $ARGV[0]";
  137. my $quoted_tmp = shell_quote ($tmp);
  138. xsystem ("$autoconf"
  139. # If you change this list, update the
  140. # `Autoheader-preselections' section of autom4te.in.
  141. . ' --trace AC_CONFIG_HEADERS:\'$$config_h ||= \'"\'"\'$1\'"\'"\';\''
  142. . ' --trace AH_OUTPUT:\'$$verbatim{\'"\'"\'$1\'"\'"\'} = \'"\'"\'$2\'"\'"\';\''
  143. . ' --trace AC_DEFINE_TRACE_LITERAL:\'$$symbol{\'"\'"\'$1\'"\'"\'} = 1;\''
  144. . " " . shell_quote ($ARGV[0]) . " >$quoted_tmp/traces.pl");
  145. local (%verbatim, %symbol);
  146. debug "$me: \`do'ing $tmp/traces.pl:\n" . `sed 's/^/| /' $quoted_tmp/traces.pl`;
  147. do "$tmp/traces.pl";
  148. warn "couldn't parse $tmp/traces.pl: $@" if $@;
  149. unless ($config_h)
  150. {
  151. error "error: AC_CONFIG_HEADERS not found in $ARGV[0]";
  152. exit 1;
  153. }
  154. # We template only the first CONFIG_HEADER.
  155. $config_h =~ s/ .*//;
  156. # Support "outfile[:infile]", defaulting infile="outfile.in".
  157. ($config_h, $config_h_in) = split (':', $config_h, 2);
  158. $config_h_in ||= "$config_h.in";
  159. # %SYMBOL might contain things like `F77_FUNC(name,NAME)', but we keep
  160. # only the name of the macro.
  161. %symbol = map { s/\(.*//; $_ => 1 } keys %symbol;
  162. my $out = new Autom4te::XFile ("> " . open_quote ("$tmp/config.hin"));
  163. # Don't write "do not edit" -- it will get copied into the
  164. # config.h, which it's ok to edit.
  165. print $out "/* $config_h_in. Generated from $ARGV[0] by autoheader. */\n";
  166. # Dump the top.
  167. if ($config_h_top)
  168. {
  169. my $in = new Autom4te::XFile ("< " . open_quote ($config_h_top));
  170. while ($_ = $in->getline)
  171. {
  172. print $out $_;
  173. }
  174. }
  175. # Dump `acconfig.h', except for its bottom portion.
  176. if ($acconfig_h)
  177. {
  178. my $in = new Autom4te::XFile ("< " . open_quote ($acconfig_h));
  179. while ($_ = $in->getline)
  180. {
  181. last if /\@BOTTOM\@/;
  182. next if /\@TOP\@/;
  183. print $out $_;
  184. }
  185. }
  186. # Dump the templates from `configure.ac'.
  187. foreach (sort keys %verbatim)
  188. {
  189. print $out "\n$verbatim{$_}\n";
  190. }
  191. # Dump bottom portion of `acconfig.h'.
  192. if ($acconfig_h)
  193. {
  194. my $in = new Autom4te::XFile ("< " . open_quote ($acconfig_h));
  195. my $dump = 0;
  196. while ($_ = $in->getline)
  197. {
  198. print $out $_ if $dump;
  199. $dump = 1 if /\@BOTTOM\@/;
  200. }
  201. }
  202. # Dump the bottom.
  203. if ($config_h_bot)
  204. {
  205. my $in = new Autom4te::XFile ("< " . open_quote ($config_h_bot));
  206. while ($_ = $in->getline)
  207. {
  208. print $out $_;
  209. }
  210. }
  211. $out->close;
  212. # Check that all the symbols have a template.
  213. {
  214. my $in = new Autom4te::XFile ("< " . open_quote ("$tmp/config.hin"));
  215. my $suggest_ac_define = 1;
  216. while ($_ = $in->getline)
  217. {
  218. my ($symbol) = /^\#\s*\w+\s+(\w+)/
  219. or next;
  220. delete $symbol{$symbol};
  221. }
  222. foreach (sort keys %symbol)
  223. {
  224. msg 'syntax', "warning: missing template: $_";
  225. if ($suggest_ac_define)
  226. {
  227. msg 'syntax', "Use AC_DEFINE([$_], [], [Description])";
  228. $suggest_ac_define = 0;
  229. }
  230. }
  231. exit 1
  232. if keys %symbol;
  233. }
  234. update_file ("$tmp/config.hin", "$config_h_in", $force);
  235. ### Setup "GNU" style for perl-mode and cperl-mode.
  236. ## Local Variables:
  237. ## perl-indent-level: 2
  238. ## perl-continued-statement-offset: 2
  239. ## perl-continued-brace-offset: 0
  240. ## perl-brace-offset: 0
  241. ## perl-brace-imaginary-offset: 0
  242. ## perl-label-offset: -2
  243. ## cperl-indent-level: 2
  244. ## cperl-brace-offset: 0
  245. ## cperl-continued-brace-offset: 0
  246. ## cperl-label-offset: -2
  247. ## cperl-extra-newline-before-brace: t
  248. ## cperl-merge-trailing-else: nil
  249. ## cperl-continued-statement-offset: 2
  250. ## End: