Dependency bug fix
[automake.git] / aclocal.in
blob3ce839cb33d3a7968dcdeaaebcafcfd733a61913
1 #!@PERL@
2 # -*- perl -*-
3 # @configure_input@
5 eval 'exec @PERL@ -S $0 ${1+"$@"}'
6     if 0;
8 # aclocal - scan configure.in and generate aclocal.m4.
10 # Some constants.
11 $VERSION = "@VERSION@";
12 $PACKAGE = "@PACKAGE@";
13 $prefix = "@prefix@";
14 # Note that this isn't pkgdatadir, but a separate directory.
15 $acdir = "@datadir@/aclocal";
17 # Some globals.
19 # Exit status.
20 $exit_status = 0;
22 # Text to output.
23 $output = '';
25 # Output file name.
26 $output_file = 'aclocal.m4';
28 # Which macros have been seen.
29 %macro_seen = ();
31 # Which files have been seen.
32 %file_seen = ();
34 # How much to say.
35 $verbosity = 0;
37 @obsolete_macros =
38     (
39      'AC_FEATURE_CTYPE',
40      'AC_FEATURE_ERRNO',
41      'AC_FEATURE_EXIT',
42      'AC_SYSTEM_HEADER',
43      'fp_C_PROTOTYPES',
44      'fp_FUNC_FNMATCH',
45      'fp_PROG_CC_STDC',
46      'fp_PROG_INSTALL',
47      'fp_WITH_DMALLOC',
48      'fp_WITH_REGEX',
49      'gm_PROG_LIBTOOL',
50      'jm_MAINTAINER_MODE',
51      'md_TYPE_PTRDIFF_T',
52      'ud_PATH_LISPDIR',
53 # These aren't quite obsolete.
54 #      'md_PATH_PROG',
55 #      'ud_GNU_GETTEXT',
56 #      'ud_LC_MESSAGES',
57 #      'ud_WITH_NLS'
58      );
60 $obsolete_rx = '(' . join ('|', @obsolete_macros) . ')';
64 &parse_arguments (@ARGV);
65 &scan_configure;
66 if (! $exit_status)
68     &write_aclocal;
71 exit $exit_status;
73 ################################################################
75 # Print usage and exit.
76 sub usage
78     local ($status) = @_;
80     print "Usage: aclocal [OPTIONS] ...\n";
81     print "\
82   --acdir=DIR           directory holding config files
83   --help                print this help, then exit
84   --output=FILE         put output in FILE (default aclocal.m4)
85   --verbose             don't be silent
86   --version             print version number, then exit
88 Report bugs to <bug-gnu-utils\@prep.ai.mit.edu>\n";
90     exit $status;
93 # Parse command line.
94 sub parse_arguments
96     local (@arglist) = @_;
98     while (@arglist)
99     {
100         if ($arglist[0] =~ /^--acdir=(.+)$/)
101         {
102             $acdir = $1;
103         }
104         elsif ($arglist[0] =~/^--output=(.+)$/)
105         {
106             $output_file = $1;
107         }
108         elsif ($arglist[0] eq '--verbose')
109         {
110             ++$verbosity;
111         }
112         elsif ($arglist[0] eq '--version')
113         {
114             print "aclocal - GNU $PACKAGE $VERSION\n";
115             exit 0;
116         }
117         elsif ($arglist[0] eq '--help')
118         {
119             &usage (0);
120         }
121         else
122         {
123             &usage (1);
124         }
126         shift (@arglist);
127     }
130 ################################################################
132 sub scan_configure
134     # First, construct list of regexps to match the things we actually
135     # have.
136     opendir (DIR, $acdir)
137         || die "aclocal: couldn't open directory \`$acdir': $!\n";
138     local ($search, $elt);
139     foreach (sort grep (! /^\./, readdir (DIR)))
140     {
141         # Only examine .m4 files.
142         next unless s/\.m4$//;
144         # Skip some files when running out of srcdir.  Eg "aclocal.m4"
145         # must be skipped.
146         next unless /^[A-Za-z]+_[A-Z_]+$/;
148         print STDERR "Finding $_\n" if $verbosity;
149         ($elt = $_) =~ s/(\W)/\\$1/g;
150         $search .= "&add_file (\"$elt\") if /$elt/;\n";
151     }
152     closedir (DIR);
154     # Construct a new function that does the searching.  We use a
155     # function (instead of just evalling $search in the loop) so that
156     # "die" is correctly and easily propagated if run.
157     eval 'sub search { ' . $search . '};';
159     open (CONFIGURE, "configure.in")
160         || die "aclocal: couldn't open \`configure.in': $!\n";
162     while (<CONFIGURE>)
163     {
164         # Remove comments from current line.
165         s/\bdnl\b.*$//;
166         s/\#.*$//;
168         if (/$obsolete_rx/o)
169         {
170             chop;
171             warn "aclocal: configure.in: $.: obsolete macro \`$_'\n";
172             $exit_status = 1;
173             next;
174         }
176         # Search for things we know about.  The "search" sub is
177         # constructed dynamically, above.
178         &search;
179     }
181     close (CONFIGURE);
183     # Include this file if it exists
184     if (-f 'acinclude.m4')
185     {
186         &add_file ('acinclude.m4');
187     }
190 ################################################################
192 # Add a file to output.
193 sub add_file
195     local ($file) = @_;
196     local ($fullfile) = $file;
198     return if ($file_seen{$file});
199     $file_seen{$file} = 1;
201     if (! -f $file)
202     {
203         $fullfile = $acdir . '/' . $file . '.m4';
204         if (! -f $fullfile)
205         {
206             # Maybe the file is an Autoconf built-in.  Check the only
207             # way we know how.  Suggestions on how to make this better
208             # are welcome.  FIXME should give file and line number of
209             # enclosing file.
210             return if $file =~ /^AC_[A-Z_]+$/;
211             die "aclocal: file \`$file' not found\n";
212         }
213     }
215     open (FILE, $fullfile)
216         || die "aclocal: couldn't open \`$fullfile': $!\n";
218     local (@rlist);
219     while (<FILE>)
220     {
221         $output .= $_;
223         # See if we're defining a macro that was already seen.  This
224         # is mostly a special case for `acinclude.m4'.
225         if (/AC_DEFUN\(\[?([^])\n]+)\]?/)
226         {
227             if ($1 ne $file && $file_seen{$1})
228             {
229                 warn "aclocal: $fullfile: $.: duplicated macro \`$1'\n";
230                 $exit_status = 1;
231             }
232             $macro_seen{$1} = 1;
233         }
235         # See if some other macro is required.
236         if (/AC_REQUIRE\(\[?([^])]*)\]?\)/)
237         {
238             push (@rlist, $1) unless defined $macro_seen{$1};
239         }
240     }
241     $output .= "\n";
242     close (FILE);
244     foreach $file (@rlist)
245     {
246         &add_file ($file);
247     }
250 ################################################################
252 # Write output.
253 sub write_aclocal
255     return if ! $output;
257     print STDERR "Writing aclocal.m4\n" if $verbosity;
259     open (ACLOCAL, "> aclocal.m4")
260         || die "aclocal: couldn't open \`aclocal.m4' for writing: $!\n";
261     print ACLOCAL "dnl aclocal.m4 generated automatically by aclocal $VERSION\n\n";
262     print ACLOCAL $output;
263     close (ACLOCAL);