2011-04-05 10:16:33 -05:00
|
|
|
:
|
|
|
|
eval 'exec perl -S $0 ${1+"$@"}'
|
|
|
|
if 0;
|
2010-08-24 08:03:44 -05:00
|
|
|
|
2011-04-05 10:16:33 -05:00
|
|
|
use strict;
|
2012-03-29 11:27:08 -05:00
|
|
|
use Cwd ('cwd', 'realpath');
|
2012-12-11 07:49:24 -06:00
|
|
|
use File::Basename;
|
|
|
|
|
|
|
|
my $src_path=dirname(realpath($0));
|
|
|
|
my $build_path=realpath(cwd());
|
|
|
|
# since this looks crazy, if you have a symlink on a path up to and including
|
|
|
|
# the current directory, we need our configure to run in the realpath of that
|
|
|
|
# such that compiled (realpath'd) dependency filenames match the filenames
|
|
|
|
# used in our makefiles - ie. this gets dependencies right via SRC_ROOT
|
|
|
|
chdir ($build_path);
|
|
|
|
# more amazingly, if you don't clobber 'PWD' shells will re-assert their
|
|
|
|
# old path from the environment, not cwd.
|
|
|
|
$ENV{PWD} = $build_path;
|
2010-08-24 08:03:44 -05:00
|
|
|
|
2011-04-05 10:16:33 -05:00
|
|
|
sub clean()
|
|
|
|
{
|
|
|
|
system ("rm -Rf autom4te.cache");
|
|
|
|
system ("rm -f missing install-sh mkinstalldirs libtool ltmain.sh");
|
|
|
|
print "cleaned the build tree\n";
|
|
|
|
}
|
2010-08-24 08:03:44 -05:00
|
|
|
|
2011-07-03 09:05:14 -05:00
|
|
|
my $aclocal;
|
2011-07-03 02:52:21 -05:00
|
|
|
|
2011-05-30 09:23:15 -05:00
|
|
|
# check we have various vital tools
|
|
|
|
sub sanity_checks($)
|
|
|
|
{
|
|
|
|
my $system = shift;
|
|
|
|
my @path = split (':', $ENV{'PATH'});
|
2011-05-31 02:00:39 -05:00
|
|
|
my %required =
|
|
|
|
(
|
|
|
|
'pkg-config' => "pkg-config is required to be installed",
|
|
|
|
'autoconf' => "autoconf is required",
|
2011-07-03 02:52:21 -05:00
|
|
|
$aclocal => "$aclocal is required",
|
2011-05-31 02:00:39 -05:00
|
|
|
);
|
2011-05-30 09:23:15 -05:00
|
|
|
|
|
|
|
for my $elem (@path) {
|
2011-05-31 02:00:39 -05:00
|
|
|
for my $app (keys %required) {
|
2011-05-31 02:32:37 -05:00
|
|
|
if (-f "$elem/$app") {
|
2011-05-31 02:00:39 -05:00
|
|
|
delete $required{$app};
|
|
|
|
}
|
2011-05-30 09:23:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((keys %required) > 0) {
|
2011-05-31 02:00:39 -05:00
|
|
|
print ("Various low-level dependencies are missing, please install them:\n");
|
|
|
|
for my $app (keys %required) {
|
2011-05-31 02:32:37 -05:00
|
|
|
print "\t $app: " . $required{$app} . "\n";
|
2011-05-31 02:00:39 -05:00
|
|
|
}
|
|
|
|
exit (1);
|
2011-05-30 09:23:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-05 10:16:33 -05:00
|
|
|
# one argument per line
|
|
|
|
sub read_args($)
|
2010-08-24 08:03:44 -05:00
|
|
|
{
|
2011-04-05 10:16:33 -05:00
|
|
|
my $file = shift;
|
|
|
|
my $fh;
|
|
|
|
my @lst;
|
|
|
|
open ($fh, $file) || die "can't open file: $file";
|
|
|
|
while (<$fh>) {
|
2011-05-31 02:00:39 -05:00
|
|
|
chomp();
|
|
|
|
# migrate from the old system
|
|
|
|
if ( substr($_, 0, 1) eq "'" ) {
|
|
|
|
print "Migrating options from the old autogen.lastrun format, using:\n";
|
|
|
|
my @opts;
|
|
|
|
@opts = split(/'/);
|
|
|
|
foreach my $opt (@opts) {
|
|
|
|
if ( substr($opt, 0, 1) eq "-" ) {
|
|
|
|
push @lst, $opt;
|
|
|
|
print " $opt\n";
|
|
|
|
}
|
|
|
|
}
|
2011-08-24 09:49:28 -05:00
|
|
|
} elsif ( substr($_, 0, 1) eq "#" ) {
|
|
|
|
# comment
|
2011-05-31 02:00:39 -05:00
|
|
|
} else {
|
|
|
|
push @lst, $_;
|
2011-04-06 01:48:26 -05:00
|
|
|
}
|
|
|
|
}
|
2011-04-05 10:16:33 -05:00
|
|
|
close ($fh);
|
2011-05-31 02:00:39 -05:00
|
|
|
# print "read args from file '$file': @lst\n";
|
2011-04-05 10:16:33 -05:00
|
|
|
return @lst;
|
2010-12-01 12:03:56 -06:00
|
|
|
}
|
|
|
|
|
2011-04-05 10:16:33 -05:00
|
|
|
sub invalid_distro($$)
|
2010-12-01 12:03:56 -06:00
|
|
|
{
|
2011-04-05 10:16:33 -05:00
|
|
|
my ($config, $distro) = @_;
|
2011-04-08 05:28:48 -05:00
|
|
|
print STDERR "Can't find distro option set: $config\nThis is not necessarily a problem.\n";
|
|
|
|
print STDERR "Distros with distro option sets are:\n";
|
2011-04-05 10:16:33 -05:00
|
|
|
my $dirh;
|
2012-12-11 07:49:24 -06:00
|
|
|
opendir ($dirh, "$src_path/distro-configs");
|
2011-04-08 05:14:52 -05:00
|
|
|
while (($_ = readdir ($dirh))) {
|
2011-05-31 02:00:39 -05:00
|
|
|
/(.*)\.conf$/ || next;
|
|
|
|
print STDERR "\t$1\n";
|
2011-04-05 10:16:33 -05:00
|
|
|
}
|
|
|
|
closedir ($dirh);
|
|
|
|
}
|
|
|
|
|
2012-03-12 17:27:16 -05:00
|
|
|
# Handle help arguments first, so we don't clobber autogen.lastrun
|
|
|
|
for my $arg (@ARGV) {
|
|
|
|
if ($arg =~ /^(--help|-h|-\?)$/) {
|
|
|
|
system ("./configure --help");
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-05 10:16:33 -05:00
|
|
|
my @cmdline_args = ();
|
2011-04-05 10:16:33 -05:00
|
|
|
if (!@ARGV) {
|
2011-04-05 10:16:33 -05:00
|
|
|
my $lastrun = "autogen.lastrun";
|
|
|
|
@cmdline_args = read_args ($lastrun) if (-f $lastrun);
|
|
|
|
} else {
|
|
|
|
@cmdline_args = @ARGV;
|
2010-08-24 08:03:44 -05:00
|
|
|
}
|
|
|
|
|
2012-11-17 04:12:31 -06:00
|
|
|
my @args;
|
2012-12-11 07:49:24 -06:00
|
|
|
my $default_config = "$src_path/distro-configs/default.conf";
|
2012-11-17 04:12:31 -06:00
|
|
|
if (-f $default_config) {
|
|
|
|
print STDERR "Reading default config file: $default_config\n";
|
|
|
|
push @args, read_args ($default_config);
|
|
|
|
}
|
2011-04-05 10:16:33 -05:00
|
|
|
for my $arg (@cmdline_args) {
|
|
|
|
if ($arg eq '--clean') {
|
2011-05-31 02:00:39 -05:00
|
|
|
clean();
|
2011-04-05 10:16:33 -05:00
|
|
|
} elsif ($arg =~ m/--with-distro=(.*)$/) {
|
2012-12-11 07:49:24 -06:00
|
|
|
my $config = "$src_path/distro-configs/$1.conf";
|
2011-05-31 02:00:39 -05:00
|
|
|
if (! -f $config) {
|
|
|
|
invalid_distro ($config, $1);
|
2011-04-08 05:28:48 -05:00
|
|
|
} else {
|
2012-06-05 04:57:31 -05:00
|
|
|
push @args, read_args ($config);
|
|
|
|
}
|
|
|
|
} else {
|
2011-05-31 02:00:39 -05:00
|
|
|
push @args, $arg;
|
2011-04-05 10:16:33 -05:00
|
|
|
}
|
|
|
|
}
|
2011-07-03 09:05:14 -05:00
|
|
|
for my $arg (@args) {
|
|
|
|
if ($arg =~ /^([A-Z]+)=(.*)/) {
|
|
|
|
$ENV{$1} = $2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Alloc $ACLOCAL to specify which aclocal to use
|
|
|
|
$aclocal = $ENV{ACLOCAL} ? $ENV{ACLOCAL} : 'aclocal';
|
2011-04-05 10:16:33 -05:00
|
|
|
|
|
|
|
my $system = `uname -s`;
|
2011-04-05 14:21:38 -05:00
|
|
|
chomp $system;
|
2010-08-24 08:03:44 -05:00
|
|
|
|
2011-05-30 10:35:24 -05:00
|
|
|
sanity_checks ($system) unless($system eq 'Darwin');
|
2011-05-30 09:23:15 -05:00
|
|
|
|
2011-04-05 10:16:33 -05:00
|
|
|
my $aclocal_flags = $ENV{ACLOCAL_FLAGS};
|
2010-11-27 09:03:38 -06:00
|
|
|
|
2012-12-11 07:49:24 -06:00
|
|
|
$aclocal_flags .= " -I $src_path/m4";
|
|
|
|
$aclocal_flags .= " -I $src_path/m4/mac" if ($system eq 'Darwin');
|
2011-04-05 14:21:38 -05:00
|
|
|
|
|
|
|
$ENV{AUTOMAKE_EXTRA_FLAGS} = '--warnings=no-portability' if (!($system eq 'Darwin'));
|
2010-12-01 06:20:29 -06:00
|
|
|
|
2012-12-11 07:49:24 -06:00
|
|
|
if ($src_path ne $build_path)
|
|
|
|
{
|
|
|
|
system ("ln -sf $src_path/configure.ac configure.ac");
|
|
|
|
system ("ln -sf $src_path/g g");
|
|
|
|
}
|
2011-07-03 02:52:21 -05:00
|
|
|
system ("$aclocal $aclocal_flags") && die "Failed to run aclocal";
|
2011-04-07 07:27:23 -05:00
|
|
|
unlink ("configure");
|
2012-12-11 07:49:24 -06:00
|
|
|
system ("autoconf -I ${src_path}") && die "Failed to run autoconf";
|
2012-11-30 15:42:36 -06:00
|
|
|
die "failed to generate configure" if (! -f "configure");
|
2011-04-05 10:16:33 -05:00
|
|
|
|
|
|
|
if (defined $ENV{NOCONFIGURE}) {
|
|
|
|
print "Skipping configure process.";
|
|
|
|
} else {
|
2011-05-29 11:39:18 -05:00
|
|
|
# Save autogen.lastrun only if we did get some arguments on the command-line
|
|
|
|
if (@ARGV) {
|
2011-08-30 20:48:32 -05:00
|
|
|
if (scalar(@cmdline_args) > 0) {
|
2012-02-29 04:50:02 -06:00
|
|
|
# if there's already an autogen.lastrun, make a backup first
|
|
|
|
if (-e "autogen.lastrun") {
|
2012-03-02 13:21:59 -06:00
|
|
|
open (my $fh, "autogen.lastrun") || warn "can't open autogen.lastrun. \n";
|
|
|
|
open (BAK, ">autogen.lastrun.bak") || warn "can't create backup file. \n";
|
|
|
|
while (<$fh>) {
|
|
|
|
print BAK;
|
|
|
|
}
|
|
|
|
close (BAK) && close ($fh);
|
2012-02-29 04:50:02 -06:00
|
|
|
}
|
2011-05-29 11:39:18 -05:00
|
|
|
# print "writing args to autogen.lastrun\n";
|
|
|
|
my $fh;
|
|
|
|
open ($fh, ">autogen.lastrun") || die "can't open autogen.lastrun: $!";
|
|
|
|
for my $arg (@cmdline_args) {
|
|
|
|
print $fh "$arg\n";
|
|
|
|
}
|
|
|
|
close ($fh);
|
|
|
|
}
|
2011-04-05 10:16:33 -05:00
|
|
|
}
|
2011-08-29 02:04:42 -05:00
|
|
|
elsif ( ! -e "autogen.lastrun")
|
2011-08-28 13:52:14 -05:00
|
|
|
{
|
2012-03-02 13:21:59 -06:00
|
|
|
open (my $fh, ">autogen.lastrun") || die "can't create autogen.lastrun";
|
|
|
|
close ($fh);
|
2011-08-28 13:52:14 -05:00
|
|
|
}
|
2012-12-11 07:49:24 -06:00
|
|
|
push @args, "--srcdir=$src_path";
|
|
|
|
|
2011-04-05 10:16:33 -05:00
|
|
|
print "running ./configure with '" . join ("' '", @args), "'\n";
|
2011-08-18 00:25:58 -05:00
|
|
|
system ("./configure", @args) && die "Error running configure";
|
2011-04-05 10:16:33 -05:00
|
|
|
}
|
2011-05-29 11:41:15 -05:00
|
|
|
|
|
|
|
# Local Variables:
|
2011-05-31 02:00:39 -05:00
|
|
|
# mode: perl
|
|
|
|
# cperl-indent-level: 4
|
2011-05-29 11:41:15 -05:00
|
|
|
# tab-width: 4
|
|
|
|
# indent-tabs-mode: nil
|
|
|
|
# End:
|
|
|
|
|
2012-01-09 15:29:10 -06:00
|
|
|
# vim:set ft=perl shiftwidth=4 softtabstop=4 expandtab: #
|