android: file-cache to improve performance.
[LibreOffice.git] / autogen.sh
blob10bdffe610e2516933c244a31d0691d00b6c70ae
3 # This script checks various configure parameters and uses three files:
4 # * autogen.input (ro)
5 # * autogen.lastrun (rw)
6 # * autogen.lastrun.bak (rw)
8 # If _no_ parameters:
9 # Read args from autogen.input or autogen.lastrun
10 # Else
11 # Backup autogen.lastrun as autogen.lastrun.bak
12 # Write autogen.lastrun with new commandline args
14 # Run configure with checked args
16 eval 'exec perl -S $0 ${1+"$@"}'
17 if 0;
19 use strict;
20 use Cwd ('cwd', 'realpath');
21 use File::Basename;
23 my $src_path=dirname(realpath($0));
24 my $build_path=realpath(cwd());
25 # since this looks crazy, if you have a symlink on a path up to and including
26 # the current directory, we need our configure to run in the realpath of that
27 # such that compiled (realpath'd) dependency filenames match the filenames
28 # used in our makefiles - ie. this gets dependencies right via SRC_ROOT
29 chdir ($build_path);
30 # more amazingly, if you don't clobber 'PWD' shells will re-assert their
31 # old path from the environment, not cwd.
32 $ENV{PWD} = $build_path;
34 my $aclocal;
35 my $autoconf;
37 # check we have various vital tools
38 sub sanity_checks($)
40 my $system = shift;
41 my @path = split (':', $ENV{'PATH'});
42 my %required =
44 'pkg-config' => "pkg-config is required to be installed",
45 $autoconf => "autoconf is required",
46 $aclocal => "$aclocal is required",
49 for my $elem (@path) {
50 for my $app (keys %required) {
51 if (-f "$elem/$app") {
52 delete $required{$app};
56 if ((keys %required) > 0) {
57 print ("Various low-level dependencies are missing, please install them:\n");
58 for my $app (keys %required) {
59 print "\t $app: " . $required{$app} . "\n";
61 exit (1);
65 # one argument per line
66 sub read_args($)
68 my $file = shift;
69 my $fh;
70 my @lst;
71 open ($fh, $file) || die "can't open file: $file";
72 while (<$fh>) {
73 chomp();
74 s/^\s+//;
75 s/\s+$//;
76 # migrate from the old system
77 if ( substr($_, 0, 1) eq "'" ) {
78 print STDERR "Migrating options from the old autogen.lastrun format, using:\n";
79 my @opts;
80 @opts = split(/'/);
81 foreach my $opt (@opts) {
82 if ( substr($opt, 0, 1) eq "-" ) {
83 push @lst, $opt;
84 print STDERR " $opt\n";
87 } elsif ( substr($_, 0, 1) eq "#" ) {
88 # comment
89 } elsif ( length == 0 ) {
90 # empty line
91 } else {
92 push @lst, $_;
95 close ($fh);
96 # print "read args from file '$file': @lst\n";
97 return @lst;
100 sub show_distro_configs($$)
102 my ($prefix, $path) = @_;
103 my $dirh;
104 opendir ($dirh, "$path");
105 while (($_ = readdir ($dirh))) {
106 if (-d "$path/$_") {
107 show_distro_configs(
108 $prefix eq "" ? "$_/" : "$prefix/$_/", "$path/$_")
109 unless $_ eq '.' || $_ eq '..';
110 next;
112 /(.*)\.conf$/ || next;
113 print STDERR "\t$prefix$1\n";
115 closedir ($dirh);
118 sub invalid_distro($$)
120 my ($config, $distro) = @_;
121 print STDERR "Can't find distro option set: $config\n";
122 print STDERR "Distros with distro option sets are:\n";
123 show_distro_configs("", "$src_path/distro-configs");
124 exit (1);
127 # Avoid confusing "aclocal: error: non-option arguments are not accepted: '.../m4'." error message.
128 die "\$src_path must not contain spaces, but it is '$src_path'." if ($src_path =~ / /);
130 # Alloc $ACLOCAL to specify which aclocal to use
131 $aclocal = $ENV{ACLOCAL} ? $ENV{ACLOCAL} : 'aclocal';
132 # Alloc $AUTOCONF to specify which autoconf to use
133 # (e.g. autoconf268 from a backports repo)
134 $autoconf = $ENV{AUTOCONF} ? $ENV{AUTOCONF} : 'autoconf';
136 my $system = `uname -s`;
137 chomp $system;
139 sanity_checks ($system) unless($system eq 'Darwin');
141 # If we are running in a LODE env, make sure we find the right aclocal
142 # by making sure that LODE_HOME/opt/bin is in the PATH
143 if (defined $ENV{LODE_HOME})
145 my $lode_path = quotemeta "$ENV{LODE_HOME}/opt/bin";
146 if($ENV{PATH} !~ $lode_path)
148 $ENV{PATH}="$ENV{LODE_HOME}/opt/bin:$ENV{PATH}";
149 print STDERR "add LODE_HOME/opt/bin in PATH\n";
153 my $aclocal_flags = $ENV{ACLOCAL_FLAGS};
155 $aclocal_flags .= " -I $src_path/m4";
156 $aclocal_flags .= " -I $src_path/m4/mac" if ($system eq 'Darwin');
157 $aclocal_flags .= " -I /opt/freeware/share/aclocal" if ($system eq 'AIX');
159 $ENV{AUTOMAKE_EXTRA_FLAGS} = '--warnings=no-portability' if (!($system eq 'Darwin'));
161 if ($src_path ne $build_path)
163 system ("ln -sf $src_path/configure.ac configure.ac");
164 system ("ln -sf $src_path/g g");
165 my $src_path_win=$src_path;
166 if ($system =~ /CYGWIN.*/) {
167 $src_path_win=`cygpath -m $src_path`;
168 chomp $src_path_win;
170 my @modules = <$src_path/*/Makefile>;
171 foreach my $module (@modules)
173 my $dir = basename (dirname ($module));
174 mkdir ($dir);
175 system ("rm -f $dir/Makefile");
176 system ("printf 'module_directory:=$src_path_win/$dir/\ninclude \$(module_directory)/../solenv/gbuild/partial_build.mk\n' > $dir/Makefile");
178 my @external_modules = <$src_path/external/*/Makefile>;
179 mkdir ("external");
180 system ("ln -sf $src_path/external/Module_external.mk external/");
181 foreach my $module (@external_modules)
183 my $dir = basename (dirname ($module));
184 mkdir ("external/$dir");
185 system ("rm -f external/$dir/Makefile");
186 system ("printf 'module_directory:=$src_path_win/external/$dir/\ninclude \$(module_directory)/../../solenv/gbuild/partial_build.mk\n' > external/$dir/Makefile");
189 system ("$aclocal $aclocal_flags") && die "Failed to run aclocal";
190 unlink ("configure");
191 system ("$autoconf -I ${src_path}") && die "Failed to run autoconf";
192 die "Failed to generate the configure script" if (! -f "configure");
194 # Handle help arguments first, so we don't clobber autogen.lastrun
195 for my $arg (@ARGV) {
196 if ($arg =~ /^(--help|-h|-\?)$/) {
197 print STDOUT "autogen.sh - libreoffice configuration helper\n";
198 print STDOUT " --with-distro use a config from distro-configs/\n";
199 print STDOUT " the name needs to be passed without extension\n";
200 print STDOUT " --best-effort don't fail on un-known configure with/enable options\n";
201 print STDOUT "\nOther arguments passed directly to configure:\n\n";
202 system ("./configure --help");
203 exit;
207 my @cmdline_args = ();
209 my $input = "autogen.input";
210 my $lastrun = "autogen.lastrun";
212 if (!@ARGV) {
213 if (-f $input) {
214 if (-f $lastrun) {
215 print STDERR <<WARNING;
216 ********************************************************************
218 * Reading $input and ignoring $lastrun!
219 * Consider removing $lastrun to get rid of this warning.
221 ********************************************************************
222 WARNING
224 @cmdline_args = read_args ($input);
225 } elsif (-f $lastrun) {
226 print STDERR "Reading $lastrun. Please rename it to $input to avoid this message.\n";
227 @cmdline_args = read_args ($lastrun);
229 } else {
230 if (-f $input) {
231 print STDERR <<WARNING;
232 ********************************************************************
234 * Using commandline arguments and ignoring $input!
236 ********************************************************************
237 WARNING
239 @cmdline_args = @ARGV;
242 my @args;
243 my $default_config = "$src_path/distro-configs/default.conf";
244 my $option_checking = 'fatal';
246 if (-f $default_config) {
247 print STDERR "Reading default config file: $default_config.\n";
248 push @args, read_args ($default_config);
250 for my $arg (@cmdline_args) {
251 if ($arg =~ m/--with-distro=(.*)$/) {
252 my $config = "$src_path/distro-configs/$1.conf";
253 if (! -f $config) {
254 invalid_distro ($config, $1);
256 push @args, read_args ($config);
257 } elsif ($arg =~ m/--best-effort$/) {
258 $option_checking = 'warn';
259 } else {
260 push @args, $arg;
264 if (defined $ENV{NOCONFIGURE}) {
265 print "Skipping configure process.";
266 } else {
267 # Save autogen.lastrun only if we did get some arguments on the command-line
268 if (! -f $input && @ARGV) {
269 if (scalar(@cmdline_args) > 0) {
270 # if there's already an autogen.lastrun, make a backup first
271 if (-e $lastrun) {
272 open (my $fh, $lastrun) || warn "Can't open $lastrun.\n";
273 open (BAK, ">$lastrun.bak") || warn "Can't create backup file $lastrun.bak.\n";
274 while (<$fh>) {
275 print BAK;
277 close (BAK) && close ($fh);
279 # print "Saving command-line args to $lastrun\n";
280 my $fh;
281 open ($fh, ">autogen.lastrun") || die "Can't open autogen.lastrun: $!";
282 for my $arg (@cmdline_args) {
283 print $fh "$arg\n";
285 close ($fh);
288 push @args, "--srcdir=$src_path";
289 push @args, "--enable-option-checking=$option_checking";
291 print "Running ./configure with '" . join (" ", @args), "'\n";
292 system ("./configure", @args) && die "Error running configure";
295 # Local Variables:
296 # mode: perl
297 # cperl-indent-level: 4
298 # tab-width: 4
299 # indent-tabs-mode: nil
300 # End:
302 # vim:set ft=perl shiftwidth=4 softtabstop=4 expandtab: #