Bump version to 4.1-6
[LibreOffice.git] / autogen.sh
blob7b1b72635b98ed1c4e6a0736a3cb70285124e1ca
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 } else {
80 push @lst, $_;
83 close ($fh);
84 # print "read args from file '$file': @lst\n";
85 return @lst;
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";
93 my $dirh;
94 opendir ($dirh, "$src_path/distro-configs");
95 while (($_ = readdir ($dirh))) {
96 /(.*)\.conf$/ || next;
97 print STDERR "\t$1\n";
99 closedir ($dirh);
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");
106 exit;
110 my @cmdline_args = ();
112 my $input = "autogen.input";
113 my $lastrun = "autogen.lastrun";
115 if (!@ARGV) {
116 if (-f $input) {
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);
123 } else {
124 @cmdline_args = @ARGV;
127 my @args;
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') {
135 clean();
136 } elsif ($arg =~ m/--with-distro=(.*)$/) {
137 my $config = "$src_path/distro-configs/$1.conf";
138 if (! -f $config) {
139 invalid_distro ($config, $1);
140 } else {
141 push @args, read_args ($config);
143 } else {
144 push @args, $arg;
147 for my $arg (@args) {
148 if ($arg =~ /^([A-Z]+)=(.*)/) {
149 $ENV{$1} = $2;
153 # Alloc $ACLOCAL to specify which aclocal to use
154 $aclocal = $ENV{ACLOCAL} ? $ENV{ACLOCAL} : 'aclocal';
156 my $system = `uname -s`;
157 chomp $system;
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/m4/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.";
181 } else {
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
186 if (-e $lastrun) {
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";
189 while (<$fh>) {
190 print BAK;
192 close (BAK) && close ($fh);
194 # print "Saving command-line args to $lastrun\n";
195 my $fh;
196 open ($fh, ">autogen.lastrun") || die "Can't open autogen.lastrun: $!";
197 for my $arg (@cmdline_args) {
198 print $fh "$arg\n";
200 close ($fh);
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";
210 # Local Variables:
211 # mode: perl
212 # cperl-indent-level: 4
213 # tab-width: 4
214 # indent-tabs-mode: nil
215 # End:
217 # vim:set ft=perl shiftwidth=4 softtabstop=4 expandtab: #