home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / automake-1.1e-bin.lha / bin / aclocal next >
Text File  |  1996-10-12  |  6KB  |  265 lines

  1. #!/bin/perl
  2. # -*- perl -*-
  3. # Generated automatically from aclocal.in by configure.
  4.  
  5. eval 'exec /bin/perl -S $0 ${1+"$@"}'
  6.     if 0;
  7.  
  8. # aclocal - scan configure.in and generate aclocal.m4.
  9.  
  10. # Some constants.
  11. $VERSION = "1.1e";
  12. $PACKAGE = "automake";
  13. $prefix = "/ade";
  14. # Note that this isn't pkgdatadir, but a separate directory.
  15. $acdir = "${prefix}/share/aclocal";
  16.  
  17. # Some globals.
  18.  
  19. # Exit status.
  20. $exit_status = 0;
  21.  
  22. # Text to output.
  23. $output = '';
  24.  
  25. # Output file name.
  26. $output_file = 'aclocal.m4';
  27.  
  28. # Which macros have been seen.
  29. %macro_seen = ();
  30.  
  31. # Which files have been seen.
  32. %file_seen = ();
  33.  
  34. # How much to say.
  35. $verbosity = 0;
  36.  
  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.      );
  59.  
  60. $obsolete_rx = '(' . join ('|', @obsolete_macros) . ')';
  61.  
  62.  
  63.  
  64. &parse_arguments (@ARGV);
  65. &scan_configure;
  66. if (! $exit_status)
  67. {
  68.     &write_aclocal;
  69. }
  70.  
  71. exit $exit_status;
  72.  
  73. ################################################################
  74.  
  75. # Print usage and exit.
  76. sub usage
  77. {
  78.     local ($status) = @_;
  79.  
  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
  87.  
  88. Report bugs to <bug-gnu-utils\@prep.ai.mit.edu>\n";
  89.  
  90.     exit $status;
  91. }
  92.  
  93. # Parse command line.
  94. sub parse_arguments
  95. {
  96.     local (@arglist) = @_;
  97.  
  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.     }
  125.  
  126.     shift (@arglist);
  127.     }
  128. }
  129.  
  130. ################################################################
  131.  
  132. sub scan_configure
  133. {
  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$//;
  143.  
  144.     # Skip some files when running out of srcdir.  Eg "aclocal.m4"
  145.     # must be skipped.
  146.     next unless /^[A-Za-z]+_[A-Z_]+$/;
  147.  
  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);
  153.  
  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 . '};';
  158.  
  159.     open (CONFIGURE, "configure.in")
  160.     || die "aclocal: couldn't open \`configure.in': $!\n";
  161.  
  162.     while (<CONFIGURE>)
  163.     {
  164.     # Remove comments from current line.
  165.     s/\bdnl\b.*$//;
  166.     s/\#.*$//;
  167.  
  168.     if (/$obsolete_rx/o)
  169.     {
  170.         chop;
  171.         warn "aclocal: configure.in: $.: obsolete macro \`$_'\n";
  172.         $exit_status = 1;
  173.         next;
  174.     }
  175.  
  176.     # Search for things we know about.  The "search" sub is
  177.     # constructed dynamically, above.
  178.     &search;
  179.     }
  180.  
  181.     close (CONFIGURE);
  182.  
  183.     # Include this file if it exists
  184.     if (-f 'acinclude.m4')
  185.     {
  186.     &add_file ('acinclude.m4');
  187.     }
  188. }
  189.  
  190. ################################################################
  191.  
  192. # Add a file to output.
  193. sub add_file
  194. {
  195.     local ($file) = @_;
  196.     local ($fullfile) = $file;
  197.  
  198.     return if ($file_seen{$file});
  199.     $file_seen{$file} = 1;
  200.  
  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.     }
  214.  
  215.     open (FILE, $fullfile)
  216.     || die "aclocal: couldn't open \`$fullfile': $!\n";
  217.  
  218.     local (@rlist);
  219.     while (<FILE>)
  220.     {
  221.     $output .= $_;
  222.  
  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.     }
  234.  
  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);
  243.  
  244.     foreach $file (@rlist)
  245.     {
  246.     &add_file ($file);
  247.     }
  248. }
  249.  
  250. ################################################################
  251.  
  252. # Write output.
  253. sub write_aclocal
  254. {
  255.     return if ! $output;
  256.  
  257.     print STDERR "Writing aclocal.m4\n" if $verbosity;
  258.  
  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);
  264. }
  265.