android: hackaround for rendering regression (disable charts)
[LibreOffice.git] / autogen.sh
bloba4bab811a36b6e50fd35c0a6c9871241915da459
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 sub clean()
36 system ("rm -Rf autom4te.cache");
37 system ("rm -f missing install-sh mkinstalldirs libtool ltmain.sh");
38 print "Cleaned the build tree\n";
41 my $aclocal;
43 # check we have various vital tools
44 sub sanity_checks($)
46 my $system = shift;
47 my @path = split (':', $ENV{'PATH'});
48 my %required =
50 'pkg-config' => "pkg-config is required to be installed",
51 'autoconf' => "autoconf is required",
52 $aclocal => "$aclocal is required",
55 for my $elem (@path) {
56 for my $app (keys %required) {
57 if (-f "$elem/$app") {
58 delete $required{$app};
62 if ((keys %required) > 0) {
63 print ("Various low-level dependencies are missing, please install them:\n");
64 for my $app (keys %required) {
65 print "\t $app: " . $required{$app} . "\n";
67 exit (1);
71 # one argument per line
72 sub read_args($)
74 my $file = shift;
75 my $fh;
76 my @lst;
77 open ($fh, $file) || die "can't open file: $file";
78 while (<$fh>) {
79 chomp();
80 s/\s+$//;
81 # migrate from the old system
82 if ( substr($_, 0, 1) eq "'" ) {
83 print STDERR "Migrating options from the old autogen.lastrun format, using:\n";
84 my @opts;
85 @opts = split(/'/);
86 foreach my $opt (@opts) {
87 if ( substr($opt, 0, 1) eq "-" ) {
88 push @lst, $opt;
89 print STDERR " $opt\n";
92 } elsif ( substr($_, 0, 1) eq "#" ) {
93 # comment
94 } elsif ( length == 0 ) {
95 # empty line
96 } else {
97 push @lst, $_;
100 close ($fh);
101 # print "read args from file '$file': @lst\n";
102 return @lst;
105 sub show_distro_configs($$)
107 my ($prefix, $path) = @_;
108 my $dirh;
109 opendir ($dirh, "$path");
110 while (($_ = readdir ($dirh))) {
111 if (-d "$path/$_") {
112 show_distro_configs(
113 $prefix eq "" ? "$_/" : "$prefix/$_/", "$path/$_")
114 unless $_ eq '.' || $_ eq '..';
115 next;
117 /(.*)\.conf$/ || next;
118 print STDERR "\t$prefix$1\n";
120 closedir ($dirh);
123 sub invalid_distro($$)
125 my ($config, $distro) = @_;
126 print STDERR "Can't find distro option set: $config\n";
127 print STDERR "Distros with distro option sets are:\n";
128 show_distro_configs("", "$src_path/distro-configs");
129 exit (1);
132 # Avoid confusing "aclocal: error: non-option arguments are not accepted: '.../m4'." error message.
133 die "\$src_path must not contain spaces, but it is '$src_path'." if ($src_path =~ / /);
135 # Alloc $ACLOCAL to specify which aclocal to use
136 $aclocal = $ENV{ACLOCAL} ? $ENV{ACLOCAL} : 'aclocal';
138 my $system = `uname -s`;
139 chomp $system;
141 sanity_checks ($system) unless($system eq 'Darwin');
143 # If we are running in a LODE env, make sure we find the right aclocal
144 # by making sure that LODE_HOME/opt/bin is in the PATH
145 if (defined $ENV{LODE_HOME})
147 my $lode_path = quotemeta "$ENV{LODE_HOME}/opt/bin";
148 if($ENV{PATH} !~ $lode_path)
150 $ENV{PATH}="$ENV{LODE_HOME}/opt/bin:$ENV{PATH}";
151 print STDERR "add LODE_HOME/opt/bin in PATH\n";
155 my $aclocal_flags = $ENV{ACLOCAL_FLAGS};
157 $aclocal_flags .= " -I $src_path/m4";
158 $aclocal_flags .= " -I $src_path/m4/mac" if ($system eq 'Darwin');
159 $aclocal_flags .= " -I /opt/freeware/share/aclocal" if ($system eq 'AIX');
161 $ENV{AUTOMAKE_EXTRA_FLAGS} = '--warnings=no-portability' if (!($system eq 'Darwin'));
163 if ($src_path ne $build_path)
165 system ("ln -sf $src_path/configure.ac configure.ac");
166 system ("ln -sf $src_path/g g");
167 my @modules = <$src_path/*/Makefile>;
168 foreach my $module (@modules)
170 my $dir = basename (dirname ($module));
171 mkdir ($dir);
172 system ("ln -sf $src_path/$dir/Makefile $dir/Makefile");
174 my @external_modules = <$src_path/external/*/Makefile>;
175 mkdir ("external");
176 system ("ln -sf $src_path/external/Module_external.mk external/");
177 foreach my $module (@external_modules)
179 my $dir = basename (dirname ($module));
180 mkdir ("external/$dir");
181 system ("ln -sf $src_path/external/$dir/Makefile external/$dir/Makefile");
184 system ("$aclocal $aclocal_flags") && die "Failed to run aclocal";
185 unlink ("configure");
186 system ("autoconf -I ${src_path}") && die "Failed to run autoconf";
187 die "Failed to generate the configure script" if (! -f "configure");
189 # Handle help arguments first, so we don't clobber autogen.lastrun
190 for my $arg (@ARGV) {
191 if ($arg =~ /^(--help|-h|-\?)$/) {
192 print STDOUT "autogen.sh - libreoffice configuration helper\n";
193 print STDOUT " --clean forcibly re-generate configuration\n";
194 print STDOUT " --best-effort don't fail on un-known configure with/enable options\n";
195 print STDOUT "\nOther arguments passed directly to configure:\n\n";
196 system ("./configure --help");
197 exit;
201 my @cmdline_args = ();
203 my $input = "autogen.input";
204 my $lastrun = "autogen.lastrun";
206 if (!@ARGV) {
207 if (-f $input) {
208 if (-f $lastrun) {
209 print STDERR <<WARNING;
210 ********************************************************************
212 * Reading $input and ignoring $lastrun!
213 * Consider removing $lastrun to get rid of this warning.
215 ********************************************************************
216 WARNING
218 @cmdline_args = read_args ($input);
219 } elsif (-f $lastrun) {
220 print STDERR "Reading $lastrun. Please rename it to $input to avoid this message.\n";
221 @cmdline_args = read_args ($lastrun);
223 } else {
224 if (-f $input) {
225 print STDERR <<WARNING;
226 ********************************************************************
228 * Using commandline arguments and ignoring $input!
230 ********************************************************************
231 WARNING
233 @cmdline_args = @ARGV;
236 my @args;
237 my $default_config = "$src_path/distro-configs/default.conf";
238 my $option_checking = 'fatal';
240 if (-f $default_config) {
241 print STDERR "Reading default config file: $default_config.\n";
242 push @args, read_args ($default_config);
244 for my $arg (@cmdline_args) {
245 if ($arg eq '--clean') {
246 clean();
247 } elsif ($arg =~ m/--with-distro=(.*)$/) {
248 my $config = "$src_path/distro-configs/$1.conf";
249 if (! -f $config) {
250 invalid_distro ($config, $1);
252 push @args, read_args ($config);
253 } elsif ($arg =~ m/--best-effort$/) {
254 $option_checking = 'warn';
255 } else {
256 push @args, $arg;
259 for my $arg (@args) {
260 if ($arg =~ /^([A-Z]+)=(.*)/) {
261 $ENV{$1} = $2;
265 if (defined $ENV{NOCONFIGURE}) {
266 print "Skipping configure process.";
267 } else {
268 # Save autogen.lastrun only if we did get some arguments on the command-line
269 if (! -f $input && @ARGV) {
270 if (scalar(@cmdline_args) > 0) {
271 # if there's already an autogen.lastrun, make a backup first
272 if (-e $lastrun) {
273 open (my $fh, $lastrun) || warn "Can't open $lastrun.\n";
274 open (BAK, ">$lastrun.bak") || warn "Can't create backup file $lastrun.bak.\n";
275 while (<$fh>) {
276 print BAK;
278 close (BAK) && close ($fh);
280 # print "Saving command-line args to $lastrun\n";
281 my $fh;
282 open ($fh, ">autogen.lastrun") || die "Can't open autogen.lastrun: $!";
283 for my $arg (@cmdline_args) {
284 print $fh "$arg\n";
286 close ($fh);
289 push @args, "--srcdir=$src_path";
290 push @args, "--enable-option-checking=$option_checking";
292 print "Running ./configure with '" . join (" ", @args), "'\n";
293 system ("./configure", @args) && die "Error running configure";
296 # Local Variables:
297 # mode: perl
298 # cperl-indent-level: 4
299 # tab-width: 4
300 # indent-tabs-mode: nil
301 # End:
303 # vim:set ft=perl shiftwidth=4 softtabstop=4 expandtab: #