Nothing
[automake.git] / aclocal.in
blobff3dbc33ab2908f354b29accbc3fbb5b2ada7aa0
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 $prefix = "@prefix@";
13 $acdir = "@datadir@/@PACKAGE@";
15 # Some globals.
17 # Exit status.
18 $exit_status = 0;
20 # Output.
21 $output = '';
23 # Which files have been seen.
24 %file_seen = ();
26 # How much to say.
27 $verbosity = 0;
29 @obsolete_macros =
30     (
31      'AC_FEATURE_CTYPE',
32      'AC_FEATURE_ERRNO',
33      'AC_FEATURE_EXIT',
34      'AC_SYSTEM_HEADER',
35      'fp_C_PROTOTYPES',
36      'fp_FUNC_FNMATCH',
37      'fp_PROG_CC_STDC',
38      'fp_PROG_INSTALL',
39      'fp_WITH_DMALLOC',
40      'fp_WITH_REGEX',
41      'gm_PROG_LIBTOOL',
42      'jm_MAINTAINER_MODE',
43      'md_PATH_PROG',
44      'md_TYPE_PTRDIFF_T',
45      'ud_GNU_GETTEXT',
46      'ud_LC_MESSAGES',
47      'ud_PATH_LISPDIR',
48      'ud_WITH_NLS'
49      );
51 $obsolete_rx = '(' . join ('|', @obsolete_macros) . ')';
55 &parse_arguments (@ARGV);
56 &scan_configure;
57 if (! $exit_status)
59     &write_aclocal;
62 exit $exit_status;
64 ################################################################
66 # Print usage and exit.
67 sub usage
69     local ($status) = @_;
71     print "Usage: aclocal [OPTIONS] ...\n";
72     print "\
73   --acdir=DIR           directory holding config files
74   --help                print this help, then exit
75   --verbose             don't be silent
76   --version             print version number, then exit\n";
78     exit $status;
81 # Parse command line.
82 sub parse_arguments
84     local (@arglist) = @_;
86     while (@arglist)
87     {
88         if ($arglist[0] =~ /^--acdir=(.+)$/)
89         {
90             $acdir = $1;
91         }
92         elsif ($arglist[0] eq '--verbose')
93         {
94             ++$verbosity;
95         }
96         elsif ($arglist[0] eq '--version')
97         {
98             print "aclocal - Autosystem $VERSION\n";
99             exit 0;
100         }
101         elsif ($arglist[0] eq '--help')
102         {
103             &usage (0);
104         }
105         else
106         {
107             &usage (1);
108         }
110         shift (@arglist);
111     }
114 ################################################################
116 sub scan_configure
118     # First, construct list of regexps to match the things we actually
119     # have.
120     opendir (DIR, $acdir)
121         || die "aclocal: couldn't open directory \`$acdir': $!\n";
122     local ($search, $elt);
123     foreach (sort grep (! /^\./, readdir (DIR)))
124     {
125         # Only examine .m4 files.
126         next unless s/\.m4$//;
128         # Skip some files when running out of srcdir.  Eg "aclocal.m4"
129         # must be skipped.
130         next unless /^[A-Za-z]+_[A-Z_]+$/;
132         print STDERR "Finding $_\n" if $verbosity;
133         ($elt = $_) =~ s/(\W)/\\$1/g;
134         $search .= "&add_file (\"$elt\") if /$elt/;\n";
135     }
136     closedir (DIR);
138     # Construct a new function that does the searching.  We use a
139     # function (instead of just evalling $search in the loop) so that
140     # "die" is correctly and easily propagated if run.
141     eval 'sub search { ' . $search . '};';
143     open (CONFIGURE, "configure.in")
144         || die "aclocal: couldn't open \`configure.in': $!\n";
146     while (<CONFIGURE>)
147     {
148         # Remove comments from current line.
149         s/\bdnl\b.*$//;
150         s/\#.*$//;
152         if (/$obsolete_rx/o)
153         {
154             chop;
155             warn "configure.in: $.: obsolete macro \`$_'\n";
156             $exit_status = 1;
157             next;
158         }
160         # Search for things we know about.  The "search" sub is
161         # constructed dynamically, above.
162         &search;
163     }
165     close (CONFIGURE);
167     # Include this file if it exists
168     if (-f 'acinclude.m4')
169     {
170         &add_file ('acinclude.m4');
171     }
174 ################################################################
176 # Add a file to output.
177 sub add_file
179     local ($file) = @_;
180     local ($fullfile) = $file;
182     return if ($file_seen{$file});
183     $file_seen{$file} = 1;
185     if (! -f $file)
186     {
187         $fullfile = $acdir . '/' . $file . '.m4';
188         if (! -f $fullfile)
189         {
190             # Maybe the file is an Autoconf built-in.  Check the only
191             # way we know how.  Suggestions on how to make this better
192             # are welcome.
193             return if $file =~ /^AC_[A-Z_]+$/;
194             die "aclocal: file \`$file' not found\n";
195         }
196     }
198     open (FILE, $fullfile)
199         || die "aclocal: couldn't open \`$fullfile': $!\n";
201     local (@rlist);
202     while (<FILE>)
203     {
204         $output .= $_;
205         # See if some other macro is required.
206         if (/AC_REQUIRE\(\[?([^])]*)\]?\)/)
207         {
208             push (@rlist, $1);
209         }
210     }
211     $output .= "\n";
212     close (FILE);
214     foreach $file (@rlist)
215     {
216         &add_file ($file);
217     }
220 ################################################################
222 # Write output.
223 sub write_aclocal
225     return if ! $output;
227     print STDERR "Writing aclocal.m4\n" if $verbosity;
229     open (ACLOCAL, "> aclocal.m4")
230         || die "aclocal: couldn't open \`aclocal.m4' for writing: $!\n";
231     print ACLOCAL "dnl aclocal.m4 generated automatically by aclocal $VERSION\n\n";
232     print ACLOCAL $output;
233     close (ACLOCAL);