1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-01 16:19:43 +02:00
2010-01-24 09:19:39 +00:00

205 lines
5.7 KiB
Perl

#! /usr/bin/perl
$VERSION="0.10";
$PREFIX="/usr/local";
# -* perl *-
# Copyright (C) 1988 Eleftherios Gkioulekas <lf@amath.washington.edu>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a configuration
# script generated by Autoconf, you may include it under the same
# distribution terms that you use for the rest of that program.
# =======================
# == Usage information ==
# =======================
sub usage
{
print <<"EOF";
Usage:
% acconfig
Options:
--help Print this message
--version Show version information
Purpose:
This utility parses aclocal.m4 and creates an appropriate acconfig.h.
In your m4 files put the following lines:
dnl ACCONFIG [BOTTOM | TOP | TEMPLATE]
dnl .....
dnl END ACCONFIG
Everything that appears in ... will be included in acconfig.h
The parameter [bottom|top|template] determines where in acconfig.h
the enclosed text is meant to appear.
EOF
exit(0);
}
sub version
{
print <<"EOF";
acconfig $VERSION - Automatic generator for acconfig.h
Copyright (C) 1998 Eleftherios Gkioulekas <lf\@amath.washington.edu>
This is free software, and you are welcome to redistribute it and modify
it under certain conditions. There is ABSOLUTELY NO WARRANTY for this
software. For details refer to version 2 of the GNU General Public License.
EOF
exit(0);
}
sub invalid
{
print "Invalid usage. For help:\n";
print "% acconfig --help\n";
exit(1);
}
sub throw_error
{
local($errormsg) = @_;
print "line $line: $errormsg \n";
exit(1);
}
# ==================
# == The main fun ==
# ==================
# No more than one argument
do invalid() if ($#ARGV > 0);
# If there is one argument then check for --version or --help
if ($#ARGV == 0)
{
do version() if ($ARGV[0] eq "--version");
do usage() if ($ARGV[0] eq "--help");
# else, invalid usage
do invalid();
}
# Load the aclocal.m4 file in memory
open(FILE,"aclocal.m4") || die "Can't open aclocal.m4: $!";
@aclocal_content = <FILE>;
close(FILE);
# Load the configure.in file in memory
open(FILE,"configure.in") || die "Can't open configure.in: $!";
@configure_in_content = <FILE>;
@aclocal_content = (@aclocal_content, @configure_in_content);
close(FILE);
# Strip the carriage returns for each line
chop(@aclocal_content);
# Initialize contents of acconfig.h
$bottom_content = "";
$top_content = "";
$template_content = "";
# Initialize the state of the parser
# 0 if outside @acconfig
# 1 if inside and it is bottom
# 2 if inside and it is top
# 3 if inside and it is template
$inside_acconfig = 0;
# Now loop over the contents of aclocal.m4 and do it
$line = 0;
foreach (@aclocal_content)
{
#
# Do these things if we are in state 0
#
if ($inside_acconfig == 0)
{
# Detect whether the current line is a directive to switch state
if (/^dnl ACCONFIG BOTTOM/) { $inside_acconfig = 1; }
elsif (/^dnl ACCONFIG TOP/) { $inside_acconfig = 2; }
elsif (/^dnl ACCONFIG TEMPLATE/) { $inside_acconfig = 3; }
# Catch a couple of possible errors
elsif (/^dnl ACCONFIG/) { throw_error("invalid ACCONFIG directive."); }
elsif (/^dnl END/) { throw_error("unmatched END directive."); }
}
#
# Do these things if we are in state 1, 2 or 3
#
elsif ($inside_acconfig == 1 ||
$inside_acconfig == 2 ||
$inside_acconfig == 3)
{
# Detect whether we go back to state 0
if (/^dnl END ACCONFIG/) { $inside_acconfig = 0; }
# If this is an ordinary dnl line then add it to bottom_content
elsif (/^dnl/)
{
# Get rid of the dnl prefix
s/^dnl //g;
# Add the line to the appropriate content variable
if ($inside_acconfig == 1)
{ $bottom_content = $bottom_content . $_ . "\n"; }
if ($inside_acconfig == 2)
{ $top_content = $top_content . $_ . "\n"; }
if ($inside_acconfig == 3)
{ $template_content = $template_content . $_ . "\n"; }
}
# If this is something else, then that's an error!
else { throw_error("non-dnl line while inside ACCONFIG."); }
}
else
{ throw_error("INTERNAL ERROR: invalid value for inside_acconfig."); }
# Increase the line number by one
$line = $line + 1;
}
# Now generate acconfig.h
open(OUT,">acconfig.h");
print OUT <<"END";
/*
** This file has been automatically generated by 'acconfig' from aclocal.m4
** Copyright (C) 1988 Eleftherios Gkioulekas <lf\@amath.washington.edu>
**
** This file is free software; as a special exception the author gives
** unlimited permission to copy and/or distribute it, with or without
** modifications, as long as this notice is preserved.
**
** This program is distributed in the hope that it will be useful, but
** WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
** implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/* This is the top section */
$top_content
\@TOP\@
/* This is the template section */
/* These are standard for all packages using Automake */
#undef PACKAGE
#undef VERSION
/* And now the rest of the boys */
$template_content
\@BOTTOM\@
/* This is the bottom section */
$bottom_content
END
close(OUT);