5 eval 'exec @PERL@ -S $0 ${1+"$@"}'
8 # aclocal - scan configure.in and generate aclocal.m4.
11 $VERSION = "@VERSION@";
12 $PACKAGE = "@PACKAGE@";
14 $acdir = "@datadir@/@PACKAGE@";
25 $output_file = 'aclocal.m4';
27 # Which macros have been seen.
30 # Which files have been seen.
52 # These aren't quite obsolete.
59 $obsolete_rx = '(' . join ('|', @obsolete_macros) . ')';
63 &parse_arguments (@ARGV);
72 ################################################################
74 # Print usage and exit.
79 print "Usage: aclocal [OPTIONS] ...\n";
81 --acdir=DIR directory holding config files
82 --help print this help, then exit
83 --output=FILE put output in FILE (default aclocal.m4)
84 --verbose don't be silent
85 --version print version number, then exit\n";
93 local (@arglist) = @_;
97 if ($arglist[0] =~ /^--acdir=(.+)$/)
101 elsif ($arglist[0] =~/^--output=(.+)$/)
105 elsif ($arglist[0] eq '--verbose')
109 elsif ($arglist[0] eq '--version')
111 print "aclocal - GNU $PACKAGE $VERSION\n";
114 elsif ($arglist[0] eq '--help')
127 ################################################################
131 # First, construct list of regexps to match the things we actually
133 opendir (DIR, $acdir)
134 || die "aclocal: couldn't open directory \`$acdir': $!\n";
135 local ($search, $elt);
136 foreach (sort grep (! /^\./, readdir (DIR)))
138 # Only examine .m4 files.
139 next unless s/\.m4$//;
141 # Skip some files when running out of srcdir. Eg "aclocal.m4"
143 next unless /^[A-Za-z]+_[A-Z_]+$/;
145 print STDERR "Finding $_\n" if $verbosity;
146 ($elt = $_) =~ s/(\W)/\\$1/g;
147 $search .= "&add_file (\"$elt\") if /$elt/;\n";
151 # Construct a new function that does the searching. We use a
152 # function (instead of just evalling $search in the loop) so that
153 # "die" is correctly and easily propagated if run.
154 eval 'sub search { ' . $search . '};';
156 open (CONFIGURE, "configure.in")
157 || die "aclocal: couldn't open \`configure.in': $!\n";
161 # Remove comments from current line.
168 warn "aclocal: configure.in: $.: obsolete macro \`$_'\n";
173 # Search for things we know about. The "search" sub is
174 # constructed dynamically, above.
180 # Include this file if it exists
181 if (-f 'acinclude.m4')
183 &add_file ('acinclude.m4');
187 ################################################################
189 # Add a file to output.
193 local ($fullfile) = $file;
195 return if ($file_seen{$file});
196 $file_seen{$file} = 1;
200 $fullfile = $acdir . '/' . $file . '.m4';
203 # Maybe the file is an Autoconf built-in. Check the only
204 # way we know how. Suggestions on how to make this better
205 # are welcome. FIXME should give file and line number of
207 return if $file =~ /^AC_[A-Z_]+$/;
208 die "aclocal: file \`$file' not found\n";
212 open (FILE, $fullfile)
213 || die "aclocal: couldn't open \`$fullfile': $!\n";
220 # See if we're defining a macro that was already seen. This
221 # is mostly a special case for `acinclude.m4'.
222 if (/AC_DEFUN\(\[?([^])\n]+)\]?/)
224 if ($1 ne $file && $file_seen{$1})
226 warn "aclocal: $fullfile: $.: duplicated macro \`$1'\n";
232 # See if some other macro is required.
233 if (/AC_REQUIRE\(\[?([^])]*)\]?\)/)
235 push (@rlist, $1) unless defined $macro_seen{$1};
241 foreach $file (@rlist)
247 ################################################################
254 print STDERR "Writing aclocal.m4\n" if $verbosity;
256 open (ACLOCAL, "> aclocal.m4")
257 || die "aclocal: couldn't open \`aclocal.m4' for writing: $!\n";
258 print ACLOCAL "dnl aclocal.m4 generated automatically by aclocal $VERSION\n\n";
259 print ACLOCAL $output;