2 eval 'exec perl -S $0 ${1+"$@"}'
6 use Cwd
('cwd', 'realpath');
9 my
$src_path=dirname(realpath
($0));
10 my
$build_path=realpath
(cwd
());
11 # since this looks crazy, if you have a symlink on a path up to and including
12 # the current directory, we need our configure to run in the realpath of that
13 # such that compiled (realpath'd) dependency filenames match the filenames
14 # used in our makefiles - ie. this gets dependencies right via SRC_ROOT
16 # more amazingly, if you don't clobber 'PWD' shells will re-assert their
17 # old path from the environment, not cwd.
18 $ENV{PWD
} = $build_path;
22 system
("rm -Rf autom4te.cache");
23 system
("rm -f missing install-sh mkinstalldirs libtool ltmain.sh");
24 print
"Cleaned the build tree\n";
29 # check we have various vital tools
33 my @path
= split (':', $ENV{'PATH'});
36 'pkg-config' => "pkg-config is required to be installed",
37 'autoconf' => "autoconf is required",
38 $aclocal => "$aclocal is required",
41 for my
$elem (@path
) {
42 for my
$app (keys
%required
) {
43 if (-f "$elem/$app") {
44 delete
$required{$app};
48 if ((keys
%required
) > 0) {
49 print
("Various low-level dependencies are missing, please install them:\n");
50 for my
$app (keys
%required
) {
51 print
"\t $app: " .
$required{$app} .
"\n";
57 # one argument per line
63 open
($fh, $file) || die
"can't open file: $file";
66 # migrate from the old system
67 if ( substr
($_, 0, 1) eq
"'" ) {
68 print
"Migrating options from the old autogen.lastrun format, using:\n";
71 foreach my $opt (@opts) {
72 if ( substr($opt, 0, 1) eq "-" ) {
77 } elsif ( substr($_, 0, 1) eq "#" ) {
84 # print "read args from file '$file': @lst\n";
88 sub invalid_distro($$)
90 my ($config, $distro) = @_;
91 print STDERR "Can't
find distro option
set: $config\nThis is not necessarily a problem.
\n";
92 print STDERR "Distros with distro option sets are
:\n";
94 opendir ($dirh, "$src_path/distro-configs
");
95 while (($_ = readdir ($dirh))) {
96 /(.*)\.conf$/ || next;
97 print STDERR "\t$1\n";
102 # Handle help arguments first, so we don't clobber autogen.lastrun
103 for my $arg (@ARGV) {
104 if ($arg =~ /^(--help|-h|-\?)$/) {
105 system (".
/configure
--help");
110 my @cmdline_args = ();
112 my $input = "autogen.input
";
113 my $lastrun = "autogen.lastrun
";
117 warn "Ignoring
$lastrun, using
$input.
\n" if (-f $lastrun);
118 @cmdline_args = read_args ($input);
119 } elsif (-f $lastrun) {
120 print STDERR "Reading
$lastrun. Please rename it to
$input to avoid this message.
\n";
121 @cmdline_args = read_args ($lastrun);
124 @cmdline_args = @ARGV;
128 my $default_config = "$src_path/distro-configs
/default.conf
";
129 if (-f $default_config) {
130 print STDERR "Reading default config
file: $default_config.
\n";
131 push @args, read_args ($default_config);
133 for my $arg (@cmdline_args) {
134 if ($arg eq '--clean') {
136 } elsif ($arg =~ m/--with-distro=(.*)$/) {
137 my $config = "$src_path/distro-configs
/$1.conf
";
139 invalid_distro ($config, $1);
141 push @args, read_args ($config);
147 for my $arg (@args) {
148 if ($arg =~ /^([A-Z]+)=(.*)/) {
153 # Alloc $ACLOCAL to specify which aclocal to use
154 $aclocal = $ENV{ACLOCAL} ? $ENV{ACLOCAL} : 'aclocal';
156 my $system = `uname -s`;
159 sanity_checks ($system) unless($system eq 'Darwin');
161 my $aclocal_flags = $ENV{ACLOCAL_FLAGS};
163 $aclocal_flags .= " -I $src_path/m4";
164 $aclocal_flags .= " -I $src_path/m
4/mac
" if ($system eq 'Darwin');
165 $aclocal_flags .= " -I /opt
/freeware
/share
/aclocal
" if ($system eq 'AIX');
167 $ENV{AUTOMAKE_EXTRA_FLAGS} = '--warnings=no-portability' if (!($system eq 'Darwin'));
169 if ($src_path ne $build_path)
171 system ("ln -sf $src_path/configure.ac configure.ac
");
172 system ("ln -sf $src_path/g g
");
174 system ("$aclocal $aclocal_flags") && die "Failed to run aclocal
";
175 unlink ("configure
");
176 system ("autoconf
-I ${src_path}") && die "Failed to run autoconf
";
177 die "Failed to generate the configure
script" if (! -f "configure
");
179 if (defined $ENV{NOCONFIGURE}) {
180 print "Skipping configure process.
";
182 # Save autogen.lastrun only if we did get some arguments on the command-line
183 if (! -f $input && @ARGV) {
184 if (scalar(@cmdline_args) > 0) {
185 # if there's already an autogen.lastrun, make a backup first
187 open (my $fh, $lastrun) || warn "Can
't open $lastrun.\n";
188 open (BAK, ">$lastrun.bak") || warn "Can't create backup
file $lastrun.bak.
\n";
192 close (BAK) && close ($fh);
194 # print "Saving command-line args to
$lastrun\n";
196 open ($fh, ">autogen.lastrun
") || die "Can
't open autogen.lastrun: $!";
197 for my $arg (@cmdline_args) {
203 push @args, "--srcdir=$src_path";
204 push @args, "--enable-option-checking=fatal";
206 print "Running ./configure with '" . join ("' '", @args), "'\n";
207 system ("./configure", @args) && die "Error running configure";
212 # cperl-indent-level: 4
214 # indent-tabs-mode: nil
217 # vim:set ft=perl shiftwidth=4 softtabstop=4 expandtab: #