autogen.sh 9.61 KB
Newer Older
1
:
2
#
3 4 5 6 7
# This script checks various configure parameters and uses three files:
#   * autogen.input (ro)
#   * autogen.lastrun (rw)
#   * autogen.lastrun.bak (rw)
#
Andrea Gelmini's avatar
Andrea Gelmini committed
8
# If _no_ parameters:
9 10 11 12
#   Read args from autogen.input or autogen.lastrun
# Else
#   Backup autogen.lastrun as autogen.lastrun.bak
#   Write autogen.lastrun with new commandline args
13 14 15
#
# Run configure with checked args
#
16 17
    eval 'exec perl -S $0 ${1+"$@"}'
        if 0;
18

19
use strict;
20
use Cwd ('cwd', 'realpath');
21 22 23 24 25 26 27 28 29 30 31 32
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;
33

34 35 36 37
sub clean()
{
    system ("rm -Rf autom4te.cache");
    system ("rm -f missing install-sh mkinstalldirs libtool ltmain.sh");
38
    print "Cleaned the build tree\n";
39
}
40

41
my $aclocal;
42
my $autoconf;
43

44 45 46 47 48
# check we have various vital tools
sub sanity_checks($)
{
    my $system = shift;
    my @path = split (':', $ENV{'PATH'});
49 50 51
    my %required =
      (
       'pkg-config' => "pkg-config is required to be installed",
52
       $autoconf    => "autoconf is required",
53
       $aclocal     => "$aclocal is required",
54
      );
55 56

    for my $elem (@path) {
57
        for my $app (keys %required) {
58
            if (-f "$elem/$app") {
59 60
                delete $required{$app};
            }
61 62 63
        }
    }
    if ((keys %required) > 0) {
64 65
        print ("Various low-level dependencies are missing, please install them:\n");
        for my $app (keys %required) {
66
            print "\t $app: " . $required{$app} . "\n";
67 68
        }
        exit (1);
69 70 71
    }
}

72 73
# one argument per line
sub read_args($)
74
{
75 76 77 78 79
    my $file = shift;
    my $fh;
    my @lst;
    open ($fh, $file) || die "can't open file: $file";
    while (<$fh>) {
80
        chomp();
81
        s/^\s+//;
82
        s/\s+$//;
83 84
        # migrate from the old system
        if ( substr($_, 0, 1) eq "'" ) {
85
            print STDERR "Migrating options from the old autogen.lastrun format, using:\n";
86 87 88 89 90
            my @opts;
            @opts = split(/'/);
            foreach my $opt (@opts) {
                if ( substr($opt, 0, 1) eq "-" ) {
                    push @lst, $opt;
91
                    print STDERR "  $opt\n";
92 93
                }
            }
94 95
        } elsif ( substr($_, 0, 1) eq "#" ) {
            # comment
96 97
        } elsif ( length == 0 ) {
            # empty line
98 99
        } else {
            push @lst, $_;
100 101
        }
    }
102
    close ($fh);
103
    # print "read args from file '$file': @lst\n";
104
    return @lst;
105 106
}

107
sub show_distro_configs($$)
108
{
109
    my ($prefix, $path) = @_;
110
    my $dirh;
111
    opendir ($dirh, "$path");
112
    while (($_ = readdir ($dirh))) {
113 114 115 116 117 118
        if (-d "$path/$_") {
            show_distro_configs(
                    $prefix eq "" ? "$_/" : "$prefix/$_/", "$path/$_")
                unless $_ eq '.' || $_ eq '..';
            next;
        }
119
        /(.*)\.conf$/ || next;
120
        print STDERR "\t$prefix$1\n";
121 122 123 124
    }
    closedir ($dirh);
}

125 126 127
sub invalid_distro($$)
{
    my ($config, $distro) = @_;
128
    print STDERR "Can't find distro option set: $config\n";
129 130
    print STDERR "Distros with distro option sets are:\n";
    show_distro_configs("", "$src_path/distro-configs");
131
    exit (1);
132 133
}

134 135 136
# Avoid confusing "aclocal: error: non-option arguments are not accepted: '.../m4'." error message.
die "\$src_path must not contain spaces, but it is '$src_path'." if ($src_path =~ / /);

137 138
# Alloc $ACLOCAL to specify which aclocal to use
$aclocal = $ENV{ACLOCAL} ? $ENV{ACLOCAL} : 'aclocal';
139 140 141
# Alloc $AUTOCONF to specify which autoconf to use
# (e.g. autoconf268 from a backports repo)
$autoconf = $ENV{AUTOCONF} ? $ENV{AUTOCONF} : 'autoconf';
142 143 144 145 146 147

my $system = `uname -s`;
chomp $system;

sanity_checks ($system) unless($system eq 'Darwin');

148 149 150 151 152 153 154 155 156 157 158 159
# If we are running in a LODE env, make sure we find the right aclocal
# by making sure that LODE_HOME/opt/bin is in the PATH
if (defined $ENV{LODE_HOME})
{
    my $lode_path = quotemeta "$ENV{LODE_HOME}/opt/bin";
    if($ENV{PATH} !~ $lode_path)
    {
        $ENV{PATH}="$ENV{LODE_HOME}/opt/bin:$ENV{PATH}";
        print STDERR "add LODE_HOME/opt/bin in PATH\n";
    }
}

160 161 162 163 164 165 166 167 168 169 170 171
my $aclocal_flags = $ENV{ACLOCAL_FLAGS};

$aclocal_flags .= " -I $src_path/m4";
$aclocal_flags .= " -I $src_path/m4/mac" if ($system eq 'Darwin');
$aclocal_flags .= " -I /opt/freeware/share/aclocal" if ($system eq 'AIX');

$ENV{AUTOMAKE_EXTRA_FLAGS} = '--warnings=no-portability' if (!($system eq 'Darwin'));

if ($src_path ne $build_path)
{
    system ("ln -sf $src_path/configure.ac configure.ac");
    system ("ln -sf $src_path/g g");
172 173 174 175 176
    my $src_path_win=$src_path;
    if ($system =~ /CYGWIN.*/) {
        $src_path_win=`cygpath -m $src_path`;
        chomp $src_path_win;
    }
177 178 179 180 181
    my @modules = <$src_path/*/Makefile>;
    foreach my $module (@modules)
    {
        my $dir = basename (dirname ($module));
        mkdir ($dir);
182
        system ("rm -f $dir/Makefile");
183
        system ("printf 'module_directory:=$src_path_win/$dir/\ninclude \$(module_directory)/../solenv/gbuild/partial_build.mk\n' > $dir/Makefile");
184 185 186 187 188 189 190 191
    }
    my @external_modules = <$src_path/external/*/Makefile>;
    mkdir ("external");
    system ("ln -sf $src_path/external/Module_external.mk external/");
    foreach my $module (@external_modules)
    {
        my $dir = basename (dirname ($module));
        mkdir ("external/$dir");
192
        system ("rm -f external/$dir/Makefile");
193
        system ("printf 'module_directory:=$src_path_win/external/$dir/\ninclude \$(module_directory)/../../solenv/gbuild/partial_build.mk\n' > external/$dir/Makefile");
194
    }
195 196 197
}
system ("$aclocal $aclocal_flags") && die "Failed to run aclocal";
unlink ("configure");
198
system ("$autoconf -I ${src_path}") && die "Failed to run autoconf";
199 200
die "Failed to generate the configure script" if (! -f "configure");

201
# Handle help arguments first, so we don't clobber autogen.lastrun
202 203
for my $arg (@ARGV) {
    if ($arg =~ /^(--help|-h|-\?)$/) {
204 205
        print STDOUT "autogen.sh - libreoffice configuration helper\n";
        print STDOUT "   --clean        forcibly re-generate configuration\n";
206 207
        print STDOUT "   --with-distro  use a config from distro-configs/\n";
        print STDOUT "                  the name needs to be passed without extension\n";
208 209
        print STDOUT "   --best-effort  don't fail on un-known configure with/enable options\n";
        print STDOUT "\nOther arguments passed directly to configure:\n\n";
210 211 212 213 214
        system ("./configure --help");
        exit;
    }
}

215
my @cmdline_args = ();
216 217

my $input = "autogen.input";
218
my $lastrun = "autogen.lastrun";
219

220 221
if (!@ARGV) {
    if (-f $input) {
222 223 224 225 226 227 228 229 230 231
        if (-f $lastrun) {
            print STDERR <<WARNING;
********************************************************************
*
*   Reading $input and ignoring $lastrun!
*   Consider removing $lastrun to get rid of this warning.
*
********************************************************************
WARNING
        }
232
        @cmdline_args = read_args ($input);
233 234 235
    } elsif (-f $lastrun) {
        print STDERR "Reading $lastrun. Please rename it to $input to avoid this message.\n";
        @cmdline_args = read_args ($lastrun);
236
    }
237
} else {
238 239 240 241 242 243 244 245 246
    if (-f $input) {
        print STDERR <<WARNING;
********************************************************************
*
*   Using commandline arguments and ignoring $input!
*
********************************************************************
WARNING
    }
247
    @cmdline_args = @ARGV;
248 249
}

250
my @args;
251
my $default_config = "$src_path/distro-configs/default.conf";
252 253
my $option_checking = 'fatal';

254
if (-f $default_config) {
255
    print STDERR "Reading default config file: $default_config.\n";
256 257
    push @args, read_args ($default_config);
}
258 259
for my $arg (@cmdline_args) {
    if ($arg eq '--clean') {
260
        clean();
261
    } elsif ($arg =~ m/--with-distro=(.*)$/) {
262
        my $config = "$src_path/distro-configs/$1.conf";
263 264
        if (! -f $config) {
            invalid_distro ($config, $1);
Stephan Bergmann's avatar
Stephan Bergmann committed
265
        }
266
        push @args, read_args ($config);
267 268
    } elsif ($arg =~ m/--best-effort$/) {
        $option_checking = 'warn';
Stephan Bergmann's avatar
Stephan Bergmann committed
269
    } else {
270
        push @args, $arg;
271 272
    }
}
273

274 275 276
if (defined $ENV{NOCONFIGURE}) {
    print "Skipping configure process.";
} else {
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
    # Save autogen.lastrun only if we did get some arguments on the command-line
    if (! -f $input && @ARGV) {
        if (scalar(@cmdline_args) > 0) {
            # if there's already an autogen.lastrun, make a backup first
            if (-e $lastrun) {
                open (my $fh, $lastrun) || warn "Can't open $lastrun.\n";
                open (BAK, ">$lastrun.bak") || warn "Can't create backup file $lastrun.bak.\n";
                while (<$fh>) {
                    print BAK;
                }
                close (BAK) && close ($fh);
            }
            # print "Saving command-line args to $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);
        }
    }
298
    push @args, "--srcdir=$src_path";
299
    push @args, "--enable-option-checking=$option_checking";
300

301
    print "Running ./configure with '" . join (" ", @args), "'\n";
302
    system ("./configure", @args) && die "Error running configure";
303
}
304 305

# Local Variables:
306 307
# mode: perl
# cperl-indent-level: 4
308 309 310 311
# tab-width: 4
# indent-tabs-mode: nil
# End:

312
# vim:set ft=perl shiftwidth=4 softtabstop=4 expandtab: #