Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / autogen.sh
bloba2a9675127853300a91580fe82007adf351642b5
2 eval 'exec perl -S $0 ${1+"$@"}'
3 if 0;
5 use strict;
6 use Cwd ('cwd', 'realpath');
7 use File::Basename;
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
15 chdir ($build_path);
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;
20 sub clean()
22 system ("rm -Rf autom4te.cache");
23 system ("rm -f missing install-sh mkinstalldirs libtool ltmain.sh");
24 print "Cleaned the build tree\n";
27 my $aclocal;
29 # check we have various vital tools
30 sub sanity_checks($)
32 my $system = shift;
33 my @path = split (':', $ENV{'PATH'});
34 my %required =
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";
53 exit (1);
57 # one argument per line
58 sub read_args($)
60 my $file = shift;
61 my $fh;
62 my @lst;
63 open ($fh, $file) || die "can't open file: $file";
64 while (<$fh>) {
65 chomp();
66 # migrate from the old system
67 if ( substr($_, 0, 1) eq "'" ) {
68 print "Migrating options from the old autogen.lastrun format, using:\n";
69 my @opts;
70 @opts = split(/'/);
71 foreach my $opt (@opts) {
72 if ( substr($opt, 0, 1) eq "-" ) {
73 push @lst, $opt;
74 print " $opt\n";
77 } elsif ( substr($_, 0, 1) eq "#" ) {
78 # comment
79 } elsif ( length == 0 ) {
80 # empty line
81 } else {
82 push @lst, $_;
85 close ($fh);
86 # print "read args from file '$file': @lst\n";
87 return @lst;
90 sub invalid_distro($$)
92 my ($config, $distro) = @_;
93 print STDERR "Can't find distro option set: $config\nThis is not necessarily a problem.\n";
94 print STDERR "Distros with distro option sets are:\n";
95 my $dirh;
96 opendir ($dirh, "$src_path/distro-configs");
97 while (($_ = readdir ($dirh))) {
98 /(.*)\.conf$/ || next;
99 print STDERR "\t$1\n";
101 closedir ($dirh);
104 # Alloc $ACLOCAL to specify which aclocal to use
105 $aclocal = $ENV{ACLOCAL} ? $ENV{ACLOCAL} : 'aclocal';
107 my $system = `uname -s`;
108 chomp $system;
110 sanity_checks ($system) unless($system eq 'Darwin');
112 my $aclocal_flags = $ENV{ACLOCAL_FLAGS};
114 $aclocal_flags .= " -I $src_path/m4";
115 $aclocal_flags .= " -I $src_path/m4/mac" if ($system eq 'Darwin');
116 $aclocal_flags .= " -I /opt/freeware/share/aclocal" if ($system eq 'AIX');
118 $ENV{AUTOMAKE_EXTRA_FLAGS} = '--warnings=no-portability' if (!($system eq 'Darwin'));
120 if ($src_path ne $build_path)
122 system ("ln -sf $src_path/configure.ac configure.ac");
123 system ("ln -sf $src_path/g g");
125 system ("$aclocal $aclocal_flags") && die "Failed to run aclocal";
126 unlink ("configure");
127 system ("autoconf -I ${src_path}") && die "Failed to run autoconf";
128 die "Failed to generate the configure script" if (! -f "configure");
130 # Handle help arguments first, so we don't clobber autogen.lastrun
131 for my $arg (@ARGV) {
132 if ($arg =~ /^(--help|-h|-\?)$/) {
133 system ("./configure --help");
134 exit;
138 my @cmdline_args = ();
140 my $input = "autogen.input";
141 my $lastrun = "autogen.lastrun";
143 if (!@ARGV) {
144 if (-f $input) {
145 warn "Ignoring $lastrun, using $input.\n" if (-f $lastrun);
146 @cmdline_args = read_args ($input);
147 } elsif (-f $lastrun) {
148 print STDERR "Reading $lastrun. Please rename it to $input to avoid this message.\n";
149 @cmdline_args = read_args ($lastrun);
151 } else {
152 @cmdline_args = @ARGV;
155 my @args;
156 my $default_config = "$src_path/distro-configs/default.conf";
157 if (-f $default_config) {
158 print STDERR "Reading default config file: $default_config.\n";
159 push @args, read_args ($default_config);
161 for my $arg (@cmdline_args) {
162 if ($arg eq '--clean') {
163 clean();
164 } elsif ($arg =~ m/--with-distro=(.*)$/) {
165 my $config = "$src_path/distro-configs/$1.conf";
166 if (! -f $config) {
167 invalid_distro ($config, $1);
168 } else {
169 push @args, read_args ($config);
171 } else {
172 push @args, $arg;
175 for my $arg (@args) {
176 if ($arg =~ /^([A-Z]+)=(.*)/) {
177 $ENV{$1} = $2;
181 if (defined $ENV{NOCONFIGURE}) {
182 print "Skipping configure process.";
183 } else {
184 # Save autogen.lastrun only if we did get some arguments on the command-line
185 if (! -f $input && @ARGV) {
186 if (scalar(@cmdline_args) > 0) {
187 # if there's already an autogen.lastrun, make a backup first
188 if (-e $lastrun) {
189 open (my $fh, $lastrun) || warn "Can't open $lastrun.\n";
190 open (BAK, ">$lastrun.bak") || warn "Can't create backup file $lastrun.bak.\n";
191 while (<$fh>) {
192 print BAK;
194 close (BAK) && close ($fh);
196 # print "Saving command-line args to $lastrun\n";
197 my $fh;
198 open ($fh, ">autogen.lastrun") || die "Can't open autogen.lastrun: $!";
199 for my $arg (@cmdline_args) {
200 print $fh "$arg\n";
202 close ($fh);
205 push @args, "--srcdir=$src_path";
206 push @args, "--enable-option-checking=fatal";
208 print "Running ./configure with '" . join ("' '", @args), "'\n";
209 system ("./configure", @args) && die "Error running configure";
212 # Local Variables:
213 # mode: perl
214 # cperl-indent-level: 4
215 # tab-width: 4
216 # indent-tabs-mode: nil
217 # End:
219 # vim:set ft=perl shiftwidth=4 softtabstop=4 expandtab: #