3
5
# autoupdate - modernize an Autoconf file.
4
# Copyright (C) 1994, 1999, 2000, 2001, 2002, 2003
6
# Copyright (C) 1994, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
5
7
# Free Software Foundation, Inc.
7
9
# This program is free software; you can redistribute it and/or modify
17
19
# You should have received a copy of the GNU General Public License
18
20
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22
24
# Originally written by David MacKenzie <djm@gnu.ai.mit.edu>.
23
25
# Rewritten by Akim Demaille <akim@freefriends.org>.
84
86
$version = "autoupdate (@PACKAGE_NAME@) @VERSION@
87
Copyright (C) 2006 Free Software Foundation, Inc.
88
This is free software. You may redistribute copies of it under the terms of
89
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
90
There is NO WARRANTY, to the extent permitted by law.
85
92
Written by David J. MacKenzie and Akim Demaille.
87
Copyright (C) 2003 Free Software Foundation, Inc.
88
This is free software; see the source for copying conditions. There is NO
89
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
122
# &handle_m4_symbols ()
123
# ---------------------
124
# Create the following $tmp files:
125
# m4.m4 -- enable the m4 builtins.
126
# unm4.m4 -- disable the m4 builtins.
127
# savem4.m4 -- save the m4 builtins.
128
sub handle_m4_macros ()
120
# ----------------- #
122
# ----------------- #
124
my (%ac_macros, %au_macros, %m4_builtins);
126
# HANDLE_AUTOCONF_MACROS ()
127
# -------------------------
128
# @M4_BUILTINS -- M4 builtins and a useful comment.
129
sub handle_autoconf_macros ()
130
# Get the list of builtins.
131
132
xsystem ("echo dumpdef | $m4 2>$tmp/m4.defs >/dev/null");
132
133
my $m4_defs = new Autom4te::XFile "$tmp/m4.defs";
133
134
while ($_ = $m4_defs->getline)
135
push @m4_builtins, $1
141
my $m4_m4 = new Autom4te::XFile ">$tmp/m4.m4";
142
print $m4_m4 "# m4.m4 -- enable the m4 builtins.\n";
143
my $unm4_m4 = new Autom4te::XFile ">$tmp/unm4.m4";
144
print $unm4_m4 "# unm4.m4 -- disable the m4 builtins.\n";
145
print $unm4_m4 "# Because Autoconf, via M4sugar, redefines some of these\n";
146
print $unm4_m4 "# macros, and therefore since unac.m4 disables them,\n";
147
print $unm4_m4 "# disable only if defined.\n";
148
my $m4save_m4 = new Autom4te::XFile ">$tmp/m4save.m4";
149
print $m4save_m4 "# savem4.m4 -- save the m4 builtins.\n";
150
foreach (@m4_builtins)
152
print $m4save_m4 "define([_au_$_], defn([$_]))\n";
153
print $unm4_m4 "_au_ifdef([$_], [_au_undefine([$_])])\n";
154
print $m4_m4 "_au_define([$_], _au_defn([_au_$_]))\n";
160
# ----------------- #
162
# ----------------- #
165
# @AU_MACROS & AC_MACROS -- AU and AC macros and yet another useful comment.
166
my (%ac_macros, %au_macros);
169
# HANDLE_AUTOCONF_MACROS ()
170
# -------------------------
171
# @M4_BUILTINS -- M4 builtins and a useful comment.
172
sub handle_autoconf_macros ()
174
141
my $macros = new Autom4te::XFile ("$autoconf"
175
. " --trace AU_DEFUN:'AU:\$f:\$1'"
142
. " --trace AU_DEFINE:'AU:\$f:\$1'"
176
143
. " --trace define:'AC:\$f:\$1'"
177
144
. " --melt /dev/null |");
178
145
while ($_ = $macros->getline)
181
148
my ($domain, $file, $macro) = /^(AC|AU):(.*):([^:]*)$/ or next;
182
# ../lib/m4sugar/m4sugar.m4 -> m4sugar
183
# ../lib/autoconf/general.m4 -> autoconf
184
# aclocal.m4 -> aclocal
185
my $set = basename (dirname ($file));
186
$set = 'aclocal' if $file eq 'aclocal.m4';
187
error "unknown set: $set: $_"
188
unless $set =~ /^(m4sugar|aclocal|autoconf)$/;
191
$ac_macros{$macro} = $set;
151
$au_macros{$macro} = 1;
153
elsif ($file =~ /(^|\/)m4sugar\/(m4sugar|version)\.m4$/)
155
# Add the m4sugar macros to m4_builtins.
156
$m4_builtins{$macro} = 1;
195
$au_macros{$macro} = $set;
160
# Autoconf, aclocal, and m4sh macros.
161
$ac_macros{$macro} = 1;
200
167
# Don't keep AU macros in @AC_MACROS.
201
168
delete $ac_macros{$_}
202
169
foreach (keys %au_macros);
203
170
# Don't keep M4sugar macros which are redefined by Autoconf,
204
171
# such as `builtin', `changequote' etc. See autoconf/autoconf.m4.
205
172
delete $ac_macros{$_}
206
foreach (@m4_builtins);
173
foreach (keys %m4_builtins);
207
174
error "no current Autoconf macros found"
208
175
unless keys %ac_macros;
209
176
error "no obsolete Autoconf macros found"
223
190
print $ac_m4 "# ac.m4 -- autoquoting definitions of the AC macros.\n";
224
191
my $unac_m4 = new Autom4te::XFile ">$tmp/unac.m4";
225
192
print $unac_m4 "# unac.m4 -- undefine the AC macros.\n";
226
foreach (sort grep { $ac_macros{$_} ne 'm4sugar' } keys %ac_macros)
228
print $ac_m4 "_au_define([$_], [[\$0(\$\@)]])\n";
229
print $unac_m4 "_au_undefine([$_])\n";
193
foreach (sort keys %ac_macros)
195
print $ac_m4 "_au_m4_define([$_], [m4_if(\$#, 0, [[\$0]], [[\$0(\$\@)]])])\n";
196
print $unac_m4 "_au_m4_undefine([$_])\n";
199
# m4save.m4 -- save the m4 builtins.
200
# unm4.m4 -- disable the m4 builtins.
201
# m4.m4 -- enable the m4 builtins.
202
my $m4save_m4 = new Autom4te::XFile ">$tmp/m4save.m4";
203
print $m4save_m4 "# m4save.m4 -- save the m4 builtins.\n";
204
my $unm4_m4 = new Autom4te::XFile ">$tmp/unm4.m4";
205
print $unm4_m4 "# unm4.m4 -- disable the m4 builtins.\n";
206
my $m4_m4 = new Autom4te::XFile ">$tmp/m4.m4";
207
print $m4_m4 "# m4.m4 -- enable the m4 builtins.\n";
208
foreach (sort keys %m4_builtins)
210
print $m4save_m4 "_au__save([$_])\n";
211
print $unm4_m4 "_au__undefine([$_])\n";
212
print $m4_m4 "_au__restore([$_])\n";
243
226
$autoconf .= join (' --prepend-include=', '', @prepend_include);
247
229
handle_autoconf_macros;
249
231
# $au_changequote -- enable the quote `[', `]' right before any AU macro.
250
232
my $au_changequote =
251
's/\b(' . join ('|', keys %au_macros) . ')\b/_au_changequote([,])$1/g';
233
's/\b(' . join ('|', keys %au_macros) . ')\b/_au_m4_changequote([,])$1/g';
253
235
# au.m4 -- definitions the AU macros.
254
xsystem ("$autoconf --trace AU_DEFUN:'_au_defun(\@<:\@\$1\@:>\@,
236
xsystem ("$autoconf --trace AU_DEFINE:'_au_defun(\@<:\@\$1\@:>\@,
255
237
\@<:\@\$2\@:>\@)' --melt /dev/null "
256
238
. ">$tmp/au.m4");
281
262
my $input_m4 = <<\EOF;
282
263
divert(-1) -*- Autoconf -*-
266
# Define our special macros:
267
define([_au__defn], defn([defn]))
268
define([_au__divert], defn([divert]))
269
define([_au__include], defn([include]))
270
define([_au__undefine], defn([undefine]))
271
define([_au__save], [m4_ifdef([$1], [m4_copy([$1], [_au_$1])])])
272
define([_au__restore],
273
[_au_m4_ifdef([_au_$1],
274
[_au_m4_define([$1], _au__defn([_au_$1]))])])
277
include(m4sugar/m4sugar.m4)
279
# Redefine __file__ to make warnings nicer; $file is replaced below.
280
m4_define([__file__], [$file])
282
# Redefine m4_location to fix the line number.
283
m4_define([m4_location], [__file__:m4_eval(__line__ - _au__first_line)])
285
285
# Move all the builtins into the `_au_' pseudo namespace
286
m4_include([m4save.m4])
288
288
# _au_defun(NAME, BODY)
289
289
# ---------------------
290
290
# Define NAME to BODY, plus AU activation/deactivation.
291
_au_define([_au_defun],
291
_au_m4_define([_au_defun],
295
295
_au_disable()])])
297
297
# Import the definition of the obsolete macros.
298
_au__include([au.m4])
301
301
## ------------------------ ##
316
# Reenable the builtins, and m4sugar.
317
_au_define([__au_enable],
316
# Reenable the builtins, m4sugar, and the autoquoting AC macros.
317
_au_m4_define([__au_enable],
319
319
# Enable special characters.
322
# Enable the m4 builtins, m4sugar and the autoquoting AC macros.
324
_au_include([m4sugar/m4sugar.m4])
320
_au_m4_changecom([#])
322
_au__include([m4.m4])
323
_au__include([ac.m4])
331
# Called at the beginning of all the obsolete macros. Reenable the
332
# builtins, and m4sugar if needed.
333
_au_define([_au_enable],
334
[_au_ifdef([_au_enabled],
329
# Called at the beginning of all the obsolete macros. If this is the
330
# outermost level, call __au_enable.
331
_au_m4_define([_au_enable],
332
[_au_m4_ifdef([_au_enabled],
336
334
[__au_enable()])_au_dnl
337
_au_pushdef([_au_enabled])])
335
_au_m4_pushdef([_au_enabled])])
342
# Disable the builtins, and m4sugar.
343
_au_define([__au_disable],
345
# Disable m4sugar, the AC autoquoting macros, and m4.
346
_au_include([unac.m4])
347
_au_include([unm4.m4])
340
# Disable the AC autoquoting macros, m4sugar, and m4.
341
_au_m4_define([__au_disable],
343
_au__include([unac.m4])
344
_au__include([unm4.m4])
349
346
# Disable special characters.
357
# Called at the end of all the obsolete macros. Disable the
358
# builtins, and m4sugar if needed..
359
_au_define([_au_disable],
360
[_au_popdef([_au_enabled])_au_dnl
361
_au_ifdef([_au_enabled],
354
# Called at the end of all the obsolete macros. If we are at the
355
# outermost level, call __au_disable.
356
_au_m4_define([_au_disable],
357
[_au_m4_popdef([_au_enabled])_au_dnl
358
_au_m4_ifdef([_au_enabled],
363
360
[__au_disable()])])
366
363
## ------------------------------- ##
367
364
## Disable, and process the file. ##
368
365
## ------------------------------- ##
370
# Disable m4: M4sugar and the AC autoquoting macros are not loaded yet,
371
# hence invoking `_au_disable' is wrong.
372
_au_include([unm4.m4])
374
# Disable special characters.
366
# The AC autoquoting macros are not loaded yet, hence invoking
367
# `_au_disable' would be wrong.
368
_au__include([unm4.m4])
370
# Disable special characters, and set the first line number.
374
_au_m4_define(_au__first_line, _au___line__)_au__divert(0)_au_dnl
381
377
$input_m4 =~ s/^ //mg;
378
$input_m4 =~ s/\$file/$file/g;
383
380
# prepared input -- input, but reenables the quote before each AU macro.
384
381
open INPUT_M4, ">$tmp/input.m4"
712
709
# No big deal for the semantics (unless the macro depends upon $#, which
713
710
# is bad), but the users would not be happy.
715
# Additionally, we introduced quotes that we not there before, which is
712
# Additionally, we introduced quotes that were not there before, which is
716
713
# OK in most cases, but could change the semantics of the file.
718
715
# Cruel dilemma: we do want the auto-quoting definition of `NEW' when