~ubuntu-branches/ubuntu/maverick/autoconf/maverick

« back to all changes in this revision

Viewing changes to bin/autoupdate.in

  • Committer: Bazaar Package Importer
  • Author(s): Ben Pfaff
  • Date: 2007-01-17 19:57:13 UTC
  • mfrom: (3.1.7 feisty)
  • Revision ID: james.westby@ubuntu.com-20070117195713-n2q7e2pbpu4ezbx7
Tags: 2.61-4
debian/control: Require m4 version 1.4.8 or later.  Thanks to Jim
Paris <jim@jtan.com> for reporting this bug.  Closes: #407385.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! @PERL@ -w
2
2
# -*- perl -*-
 
3
# @configure_input@
 
4
 
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.
6
8
 
7
9
# This program is free software; you can redistribute it and/or modify
16
18
 
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
20
 
# 02111-1307, USA.
 
21
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
22
# 02110-1301, USA.
21
23
 
22
24
# Originally written by David MacKenzie <djm@gnu.ai.mit.edu>.
23
25
# Rewritten by Akim Demaille <akim@freefriends.org>.
82
84
# $VERSION
83
85
# --------
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.
 
91
 
85
92
Written by David J. MacKenzie and Akim Demaille.
86
 
 
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.
90
93
";
91
94
 
92
95
## ---------- ##
113
116
}
114
117
 
115
118
 
116
 
# ------------- #
117
 
# M4 builtins.  #
118
 
# ------------- #
119
 
 
120
 
my @m4_builtins;
121
 
 
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 ()
 
119
 
 
120
# ----------------- #
 
121
# Autoconf macros.  #
 
122
# ----------------- #
 
123
 
 
124
my (%ac_macros, %au_macros, %m4_builtins);
 
125
 
 
126
# HANDLE_AUTOCONF_MACROS ()
 
127
# -------------------------
 
128
# @M4_BUILTINS -- M4 builtins and a useful comment.
 
129
sub handle_autoconf_macros ()
129
130
{
130
 
  # Get the list of builtins.
 
131
  # Get the 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)
134
135
    {
135
 
      push @m4_builtins, $1
 
136
      $m4_builtins{$1} = 1
136
137
        if /^(\w+):/;
137
138
    }
138
139
  $m4_defs->close;
139
140
 
140
 
  # Output the files.
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)
151
 
    {
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";
155
 
    }
156
 
}
157
 
 
158
 
 
159
 
 
160
 
# ----------------- #
161
 
# Autoconf macros.  #
162
 
# ----------------- #
163
 
 
164
 
 
165
 
# @AU_MACROS & AC_MACROS -- AU and AC macros and yet another useful comment.
166
 
my (%ac_macros, %au_macros);
167
 
 
168
 
 
169
 
# HANDLE_AUTOCONF_MACROS ()
170
 
# -------------------------
171
 
# @M4_BUILTINS -- M4 builtins and a useful comment.
172
 
sub handle_autoconf_macros ()
173
 
{
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)
179
146
    {
180
147
      chomp;
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)$/;
189
 
      if ($domain eq "AC")
190
 
        {
191
 
          $ac_macros{$macro} = $set;
 
149
      if ($domain eq "AU")
 
150
        {
 
151
          $au_macros{$macro} = 1;
 
152
        }
 
153
      elsif ($file =~ /(^|\/)m4sugar\/(m4sugar|version)\.m4$/)
 
154
        {
 
155
          # Add the m4sugar macros to m4_builtins.
 
156
          $m4_builtins{$macro} = 1;
192
157
        }
193
158
      else
194
159
        {
195
 
          $au_macros{$macro} = $set;
 
160
          # Autoconf, aclocal, and m4sh macros.
 
161
          $ac_macros{$macro} = 1;
196
162
        }
197
163
    }
198
164
  $macros->close;
199
165
 
 
166
 
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)
227
 
    {
228
 
      print $ac_m4   "_au_define([$_], [[\$0(\$\@)]])\n";
229
 
      print $unac_m4 "_au_undefine([$_])\n";
 
193
  foreach (sort keys %ac_macros)
 
194
    {
 
195
      print $ac_m4   "_au_m4_define([$_], [m4_if(\$#, 0, [[\$0]], [[\$0(\$\@)]])])\n";
 
196
      print $unac_m4 "_au_m4_undefine([$_])\n";
 
197
    }
 
198
 
 
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)
 
209
    {
 
210
      print $m4save_m4 "_au__save([$_])\n";
 
211
      print $unm4_m4   "_au__undefine([$_])\n";
 
212
      print $m4_m4     "_au__restore([$_])\n";
230
213
    }
231
214
}
232
215
 
243
226
$autoconf .= join (' --prepend-include=', '', @prepend_include);
244
227
 
245
228
mktmpdir ('au');
246
 
handle_m4_macros;
247
229
handle_autoconf_macros;
248
230
 
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';
252
234
 
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");
257
239
 
263
245
 
264
246
foreach my $file (@ARGV)
265
247
  {
266
 
    my $filename = $file;
267
248
    # We need an actual file.
268
249
    if ($file eq '-')
269
250
      {
280
261
    # input file.
281
262
    my $input_m4 = <<\EOF;
282
263
      divert(-1)                                            -*- Autoconf -*-
283
 
      changequote([, ])
 
264
      changequote([,])
 
265
 
 
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]))])])
 
275
 
 
276
      # Set up m4sugar.
 
277
      include(m4sugar/m4sugar.m4)
 
278
 
 
279
      # Redefine __file__ to make warnings nicer; $file is replaced below.
 
280
      m4_define([__file__], [$file])
 
281
 
 
282
      # Redefine m4_location to fix the line number.
 
283
      m4_define([m4_location], [__file__:m4_eval(__line__ - _au__first_line)])
284
284
 
285
285
      # Move all the builtins into the `_au_' pseudo namespace
286
 
      include([m4save.m4])
 
286
      m4_include([m4save.m4])
287
287
 
288
288
      # _au_defun(NAME, BODY)
289
289
      # ---------------------
290
290
      # Define NAME to BODY, plus AU activation/deactivation.
291
 
      _au_define([_au_defun],
292
 
      [_au_define([$1],
 
291
      _au_m4_define([_au_defun],
 
292
      [_au_m4_define([$1],
293
293
      [_au_enable()dnl
294
294
      $2[]dnl
295
295
      _au_disable()])])
296
296
 
297
297
      # Import the definition of the obsolete macros.
298
 
      _au_include([au.m4])
 
298
      _au__include([au.m4])
299
299
 
300
300
 
301
301
      ## ------------------------ ##
313
313
 
314
314
      # __au_enable
315
315
      # -----------
316
 
      # Reenable the builtins, and m4sugar.
317
 
      _au_define([__au_enable],
318
 
      [_au_divert(-1)
 
316
      # Reenable the builtins, m4sugar, and the autoquoting AC macros.
 
317
      _au_m4_define([__au_enable],
 
318
      [_au__divert(-1)
319
319
      # Enable special characters.
320
 
      _au_changecom([#])
321
 
 
322
 
      # Enable the m4 builtins, m4sugar and the autoquoting AC macros.
323
 
      _au_include([m4.m4])
324
 
      _au_include([m4sugar/m4sugar.m4])
325
 
      _au_include([ac.m4])
326
 
 
327
 
      _au_divert(0)])
 
320
      _au_m4_changecom([#])
 
321
 
 
322
      _au__include([m4.m4])
 
323
      _au__include([ac.m4])
 
324
 
 
325
      _au__divert(0)])
328
326
 
329
327
      # _au_enable
330
328
      # ----------
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],
335
333
                 [],
336
334
                 [__au_enable()])_au_dnl
337
 
      _au_pushdef([_au_enabled])])
 
335
      _au_m4_pushdef([_au_enabled])])
338
336
 
339
337
 
340
338
      # __au_disable
341
339
      # ------------
342
 
      # Disable the builtins, and m4sugar.
343
 
      _au_define([__au_disable],
344
 
      [_au_divert(-1)
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],
 
342
      [_au__divert(-1)
 
343
      _au__include([unac.m4])
 
344
      _au__include([unm4.m4])
348
345
 
349
346
      # Disable special characters.
350
 
      _au_changequote()
351
 
      _au_changecom()
 
347
      _au_m4_changequote()
 
348
      _au_m4_changecom()
352
349
 
353
 
      _au_divert(0)])
 
350
      _au__divert(0)])
354
351
 
355
352
      # _au_disable
356
353
      # -----------
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],
362
359
                [],
363
360
                [__au_disable()])])
364
361
 
366
363
      ## ------------------------------- ##
367
364
      ## Disable, and process the file.  ##
368
365
      ## ------------------------------- ##
369
 
      _au_divert(-1)
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])
373
 
 
374
 
      # Disable special characters.
375
 
      _au_changequote()
376
 
      _au_changecom()
377
 
 
378
 
      _au_divert(0)_au_dnl
 
366
      # The AC autoquoting macros are not loaded yet, hence invoking
 
367
      # `_au_disable' would be wrong.
 
368
      _au__include([unm4.m4])
 
369
 
 
370
      # Disable special characters, and set the first line number.
 
371
      _au_m4_changequote()
 
372
      _au_m4_changecom()
 
373
 
 
374
      _au_m4_define(_au__first_line, _au___line__)_au__divert(0)_au_dnl
379
375
EOF
380
376
 
381
377
    $input_m4 =~ s/^      //mg;
 
378
    $input_m4 =~ s/\$file/$file/g;
382
379
 
383
380
    # prepared input -- input, but reenables the quote before each AU macro.
384
381
    open INPUT_M4, ">$tmp/input.m4"
414
411
# The task of `autoupdate' is not trivial: the biggest difficulty being
415
412
# that you must limit the changes to the parts that really need to be
416
413
# updated.  Finding a satisfying implementation proved to be quite hard,
417
 
# as this is the fourth implementation of `autoupdate'.
 
414
# as this is the fifth implementation of `autoupdate'.
418
415
#
419
416
# Below, we will use a simple example of obsolete macro:
420
417
#
597
594
# strings which can become quickly huge, which slows it significantly.
598
595
#
599
596
# In particular one should avoid as much as possible to use `define' for
600
 
# temporaries.  Now that `define' as quite a complex meaning, it is an
 
597
# temporaries.  Now that `define' has quite a complex meaning, it is an
601
598
# expensive operations that should be limited to macros.  Use
602
599
# `m4_define' for temporaries.
603
600
#
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.
714
711
#
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.
717
714
#
718
715
# Cruel dilemma: we do want the auto-quoting definition of `NEW' when
884
881
# # ------------------------------
885
882
#
886
883
# This approach is heavily based on traces, but then there is an obvious
887
 
# problem: non expanded code will never be seen/ In particular, the body
 
884
# problem: non expanded code will never be seen.  In particular, the body
888
885
# of a `define' definition is not seen, so on the input
889
886
#
890
887
#         define([idem], [OLD(0, [$1])])
950
947
# this:
951
948
#
952
949
#  `m4save.m4'
953
 
#    moves the m4 builtins into the `_au_' pseudo namespace
 
950
#    moves the m4 builtins into the `_au_' pseudo namespace,
954
951
#  `unm4.m4'
955
 
#    undefines the builtins
 
952
#    undefines the builtins,
956
953
#  `m4.m4'
957
 
#    restores them
 
954
#    restores them.
958
955
#
959
956
# So `input.m4' is:
960
957
#