blob: 20976ce66d3fda892ac3917dd2829f310d72cac7 [file] [log] [blame]
Michael Meeks434df162011-04-05 16:16:33 +01001:
Jan-Marek Glogowski806f4d82014-03-04 11:49:46 +00002#
Tor Lillqvistc32d54f2017-09-22 16:51:22 +03003# This script checks various configure parameters and uses three files:
4# * autogen.input (ro)
5# * autogen.lastrun (rw)
6# * autogen.lastrun.bak (rw)
7#
Andrea Gelmini64a31242017-08-17 16:41:20 +02008# If _no_ parameters:
Tor Lillqvistc32d54f2017-09-22 16:51:22 +03009# 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
Jan-Marek Glogowski806f4d82014-03-04 11:49:46 +000013#
14# Run configure with checked args
15#
Michael Meeks434df162011-04-05 16:16:33 +010016 eval 'exec perl -S $0 ${1+"$@"}'
17 if 0;
Jan Holesovsky55d3dff2010-08-24 15:03:44 +020018
Michael Meeks434df162011-04-05 16:16:33 +010019use strict;
Michael Meeks02f385b2012-03-29 17:27:08 +010020use Cwd ('cwd', 'realpath');
Norbert Thiebaudae4e3272012-12-11 07:49:24 -060021use File::Basename;
22
23my $src_path=dirname(realpath($0));
24my $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
29chdir ($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;
Jan Holesovsky55d3dff2010-08-24 15:03:44 +020033
Michael Meeks434df162011-04-05 16:16:33 +010034sub clean()
Jan Holesovsky55d3dff2010-08-24 15:03:44 +020035{
Michael Meeks434df162011-04-05 16:16:33 +010036 system ("rm -Rf autom4te.cache");
37 system ("rm -f missing install-sh mkinstalldirs libtool ltmain.sh");
Tor Lillqvistca0c54d2013-03-28 15:26:25 +020038 print "Cleaned the build tree\n";
Jan Holesovsky5da12b12010-12-01 19:03:56 +010039}
40
Tor Lillqviste3a07b82011-07-03 17:05:14 +030041my $aclocal;
Tor Lillqvist17399722011-07-03 10:52:21 +030042
Michael Meeksdd771be2011-05-30 15:23:15 +010043# check we have various vital tools
44sub sanity_checks($)
45{
46 my $system = shift;
47 my @path = split (':', $ENV{'PATH'});
Tor Lillqvist471fd2e2011-05-31 10:00:39 +030048 my %required =
49 (
50 'pkg-config' => "pkg-config is required to be installed",
51 'autoconf' => "autoconf is required",
Tor Lillqvist17399722011-07-03 10:52:21 +030052 $aclocal => "$aclocal is required",
Tor Lillqvist471fd2e2011-05-31 10:00:39 +030053 );
Michael Meeksdd771be2011-05-30 15:23:15 +010054
55 for my $elem (@path) {
Tor Lillqvist471fd2e2011-05-31 10:00:39 +030056 for my $app (keys %required) {
Tor Lillqvist29a2abb2011-05-31 10:32:37 +030057 if (-f "$elem/$app") {
Tor Lillqvist471fd2e2011-05-31 10:00:39 +030058 delete $required{$app};
59 }
Michael Meeksdd771be2011-05-30 15:23:15 +010060 }
61 }
Michael Meeksdd771be2011-05-30 15:23:15 +010062 if ((keys %required) > 0) {
Tor Lillqvist471fd2e2011-05-31 10:00:39 +030063 print ("Various low-level dependencies are missing, please install them:\n");
64 for my $app (keys %required) {
Tor Lillqvist29a2abb2011-05-31 10:32:37 +030065 print "\t $app: " . $required{$app} . "\n";
Tor Lillqvist471fd2e2011-05-31 10:00:39 +030066 }
67 exit (1);
Michael Meeksdd771be2011-05-30 15:23:15 +010068 }
69}
70
Michael Meeks434df162011-04-05 16:16:33 +010071# one argument per line
72sub read_args($)
Jan Holesovsky5da12b12010-12-01 19:03:56 +010073{
Michael Meeks434df162011-04-05 16:16:33 +010074 my $file = shift;
75 my $fh;
76 my @lst;
77 open ($fh, $file) || die "can't open file: $file";
78 while (<$fh>) {
Tor Lillqvist471fd2e2011-05-31 10:00:39 +030079 chomp();
Stephan Bergmann2f9ee542018-01-18 15:25:58 +010080 s/^\s+//;
Christian Lohmaier86908b32014-05-30 11:18:20 +020081 s/\s+$//;
Tor Lillqvist471fd2e2011-05-31 10:00:39 +030082 # migrate from the old system
83 if ( substr($_, 0, 1) eq "'" ) {
Jan-Marek Glogowski806f4d82014-03-04 11:49:46 +000084 print STDERR "Migrating options from the old autogen.lastrun format, using:\n";
Tor Lillqvist471fd2e2011-05-31 10:00:39 +030085 my @opts;
86 @opts = split(/'/);
87 foreach my $opt (@opts) {
88 if ( substr($opt, 0, 1) eq "-" ) {
89 push @lst, $opt;
Jan-Marek Glogowski806f4d82014-03-04 11:49:46 +000090 print STDERR " $opt\n";
Tor Lillqvist471fd2e2011-05-31 10:00:39 +030091 }
92 }
Tor Lillqviste0585302011-08-24 17:49:28 +030093 } elsif ( substr($_, 0, 1) eq "#" ) {
94 # comment
Isamu Mogi92e484c2013-07-20 09:45:36 +090095 } elsif ( length == 0 ) {
96 # empty line
Tor Lillqvist471fd2e2011-05-31 10:00:39 +030097 } else {
98 push @lst, $_;
Jan Holesovskyb2a2b922011-04-06 08:48:26 +020099 }
Michael Meeks434df162011-04-05 16:16:33 +0100100 }
101 close ($fh);
Tor Lillqvist471fd2e2011-05-31 10:00:39 +0300102 # print "read args from file '$file': @lst\n";
Michael Meeks434df162011-04-05 16:16:33 +0100103 return @lst;
Jan Holesovsky55d3dff2010-08-24 15:03:44 +0200104}
105
Stephan Bergmann4ecfc232017-05-17 10:24:00 +0200106sub show_distro_configs($$)
107{
108 my ($prefix, $path) = @_;
109 my $dirh;
110 opendir ($dirh, "$path");
111 while (($_ = readdir ($dirh))) {
112 if (-d "$path/$_") {
113 show_distro_configs(
114 $prefix eq "" ? "$_/" : "$prefix/$_/", "$path/$_")
115 unless $_ eq '.' || $_ eq '..';
116 next;
117 }
118 /(.*)\.conf$/ || next;
119 print STDERR "\t$prefix$1\n";
120 }
121 closedir ($dirh);
122}
123
Michael Meeks434df162011-04-05 16:16:33 +0100124sub invalid_distro($$)
125{
126 my ($config, $distro) = @_;
Stephan Bergmannd21f9762017-05-17 10:28:07 +0200127 print STDERR "Can't find distro option set: $config\n";
Tor Lillqvist47bca2f2011-04-08 13:28:48 +0300128 print STDERR "Distros with distro option sets are:\n";
Stephan Bergmann4ecfc232017-05-17 10:24:00 +0200129 show_distro_configs("", "$src_path/distro-configs");
Stephan Bergmannd21f9762017-05-17 10:28:07 +0200130 exit (1);
Michael Meeks434df162011-04-05 16:16:33 +0100131}
Jan Holesovsky55d3dff2010-08-24 15:03:44 +0200132
Miklos Vajnaaefc43b2015-03-08 16:58:35 +0100133# Avoid confusing "aclocal: error: non-option arguments are not accepted: '.../m4'." error message.
134die "\$src_path must not contain spaces, but it is '$src_path'." if ($src_path =~ / /);
135
Arnaud Versini6b114c22013-10-17 15:01:45 +0200136# Alloc $ACLOCAL to specify which aclocal to use
137$aclocal = $ENV{ACLOCAL} ? $ENV{ACLOCAL} : 'aclocal';
138
139my $system = `uname -s`;
140chomp $system;
141
142sanity_checks ($system) unless($system eq 'Darwin');
143
Norbert Thiebaud4c231842015-12-29 13:32:18 -0600144# If we are running in a LODE env, make sure we find the right aclocal
145# by making sure that LODE_HOME/opt/bin is in the PATH
146if (defined $ENV{LODE_HOME})
147{
148 my $lode_path = quotemeta "$ENV{LODE_HOME}/opt/bin";
149 if($ENV{PATH} !~ $lode_path)
150 {
151 $ENV{PATH}="$ENV{LODE_HOME}/opt/bin:$ENV{PATH}";
152 print STDERR "add LODE_HOME/opt/bin in PATH\n";
153 }
154}
155
Arnaud Versini6b114c22013-10-17 15:01:45 +0200156my $aclocal_flags = $ENV{ACLOCAL_FLAGS};
157
158$aclocal_flags .= " -I $src_path/m4";
159$aclocal_flags .= " -I $src_path/m4/mac" if ($system eq 'Darwin');
160$aclocal_flags .= " -I /opt/freeware/share/aclocal" if ($system eq 'AIX');
161
162$ENV{AUTOMAKE_EXTRA_FLAGS} = '--warnings=no-portability' if (!($system eq 'Darwin'));
163
164if ($src_path ne $build_path)
165{
166 system ("ln -sf $src_path/configure.ac configure.ac");
167 system ("ln -sf $src_path/g g");
Luboš Luňák2bf2bc22014-03-23 16:21:51 +0100168 my @modules = <$src_path/*/Makefile>;
169 foreach my $module (@modules)
170 {
171 my $dir = basename (dirname ($module));
172 mkdir ($dir);
173 system ("ln -sf $src_path/$dir/Makefile $dir/Makefile");
174 }
175 my @external_modules = <$src_path/external/*/Makefile>;
176 mkdir ("external");
177 system ("ln -sf $src_path/external/Module_external.mk external/");
178 foreach my $module (@external_modules)
179 {
180 my $dir = basename (dirname ($module));
181 mkdir ("external/$dir");
182 system ("ln -sf $src_path/external/$dir/Makefile external/$dir/Makefile");
183 }
Arnaud Versini6b114c22013-10-17 15:01:45 +0200184}
185system ("$aclocal $aclocal_flags") && die "Failed to run aclocal";
186unlink ("configure");
187system ("autoconf -I ${src_path}") && die "Failed to run autoconf";
188die "Failed to generate the configure script" if (! -f "configure");
189
Tor Lillqvistc32d54f2017-09-22 16:51:22 +0300190# Handle help arguments first, so we don't clobber autogen.lastrun
Josh Heidenreich66353372012-03-13 08:57:16 +1030191for my $arg (@ARGV) {
192 if ($arg =~ /^(--help|-h|-\?)$/) {
Mike Kaganskic10e82a2016-12-14 10:27:23 +0300193 print STDOUT "autogen.sh - libreoffice configuration helper\n";
194 print STDOUT " --clean forcibly re-generate configuration\n";
195 print STDOUT " --best-effort don't fail on un-known configure with/enable options\n";
196 print STDOUT "\nOther arguments passed directly to configure:\n\n";
Josh Heidenreich66353372012-03-13 08:57:16 +1030197 system ("./configure --help");
198 exit;
199 }
200}
201
Michael Meeks434df162011-04-05 16:16:33 +0100202my @cmdline_args = ();
Tor Lillqvistca0c54d2013-03-28 15:26:25 +0200203
204my $input = "autogen.input";
Tor Lillqvistc32d54f2017-09-22 16:51:22 +0300205my $lastrun = "autogen.lastrun";
Tor Lillqvistca0c54d2013-03-28 15:26:25 +0200206
Luboš Luňák68c314f2013-04-03 18:01:35 +0200207if (!@ARGV) {
208 if (-f $input) {
Tor Lillqvistc32d54f2017-09-22 16:51:22 +0300209 if (-f $lastrun) {
210 print STDERR <<WARNING;
211********************************************************************
212*
213* Reading $input and ignoring $lastrun!
214* Consider removing $lastrun to get rid of this warning.
215*
216********************************************************************
217WARNING
218 }
Luboš Luňák68c314f2013-04-03 18:01:35 +0200219 @cmdline_args = read_args ($input);
Tor Lillqvistc32d54f2017-09-22 16:51:22 +0300220 } elsif (-f $lastrun) {
221 print STDERR "Reading $lastrun. Please rename it to $input to avoid this message.\n";
222 @cmdline_args = read_args ($lastrun);
Luboš Luňák68c314f2013-04-03 18:01:35 +0200223 }
Michael Meeks434df162011-04-05 16:16:33 +0100224} else {
Jan-Marek Glogowski806f4d82014-03-04 11:49:46 +0000225 if (-f $input) {
226 print STDERR <<WARNING;
227********************************************************************
228*
229* Using commandline arguments and ignoring $input!
230*
231********************************************************************
232WARNING
233 }
Michael Meeks434df162011-04-05 16:16:33 +0100234 @cmdline_args = @ARGV;
235}
Jan Holesovsky55d3dff2010-08-24 15:03:44 +0200236
Enrico Weigelt, metux ITS695c1942012-11-17 11:12:31 +0100237my @args;
Norbert Thiebaudae4e3272012-12-11 07:49:24 -0600238my $default_config = "$src_path/distro-configs/default.conf";
Michael Meeks1e03a682014-11-13 16:27:30 +0000239my $option_checking = 'fatal';
240
Enrico Weigelt, metux ITSc1caa1d2012-11-17 11:12:31 +0100241if (-f $default_config) {
Tor Lillqvistca0c54d2013-03-28 15:26:25 +0200242 print STDERR "Reading default config file: $default_config.\n";
Enrico Weigelt, metux ITSc1caa1d2012-11-17 11:12:31 +0100243 push @args, read_args ($default_config);
244}
Michael Meeks434df162011-04-05 16:16:33 +0100245for my $arg (@cmdline_args) {
246 if ($arg eq '--clean') {
Tor Lillqvist471fd2e2011-05-31 10:00:39 +0300247 clean();
Michael Meeks434df162011-04-05 16:16:33 +0100248 } elsif ($arg =~ m/--with-distro=(.*)$/) {
Norbert Thiebaudae4e3272012-12-11 07:49:24 -0600249 my $config = "$src_path/distro-configs/$1.conf";
Tor Lillqvist471fd2e2011-05-31 10:00:39 +0300250 if (! -f $config) {
251 invalid_distro ($config, $1);
Stephan Bergmann1dfb9562012-06-05 11:57:31 +0200252 }
Stephan Bergmannd21f9762017-05-17 10:28:07 +0200253 push @args, read_args ($config);
Michael Meeks1e03a682014-11-13 16:27:30 +0000254 } elsif ($arg =~ m/--best-effort$/) {
255 $option_checking = 'warn';
Stephan Bergmann1dfb9562012-06-05 11:57:31 +0200256 } else {
Tor Lillqvist471fd2e2011-05-31 10:00:39 +0300257 push @args, $arg;
Michael Meeks434df162011-04-05 16:16:33 +0100258 }
259}
Tor Lillqviste3a07b82011-07-03 17:05:14 +0300260
Michael Meeks434df162011-04-05 16:16:33 +0100261if (defined $ENV{NOCONFIGURE}) {
262 print "Skipping configure process.";
263} else {
Tor Lillqvistc32d54f2017-09-22 16:51:22 +0300264 # Save autogen.lastrun only if we did get some arguments on the command-line
265 if (! -f $input && @ARGV) {
266 if (scalar(@cmdline_args) > 0) {
267 # if there's already an autogen.lastrun, make a backup first
268 if (-e $lastrun) {
269 open (my $fh, $lastrun) || warn "Can't open $lastrun.\n";
270 open (BAK, ">$lastrun.bak") || warn "Can't create backup file $lastrun.bak.\n";
271 while (<$fh>) {
272 print BAK;
273 }
274 close (BAK) && close ($fh);
275 }
276 # print "Saving command-line args to $lastrun\n";
277 my $fh;
278 open ($fh, ">autogen.lastrun") || die "Can't open autogen.lastrun: $!";
279 for my $arg (@cmdline_args) {
280 print $fh "$arg\n";
281 }
282 close ($fh);
283 }
284 }
Norbert Thiebaudae4e3272012-12-11 07:49:24 -0600285 push @args, "--srcdir=$src_path";
Michael Meeks1e03a682014-11-13 16:27:30 +0000286 push @args, "--enable-option-checking=$option_checking";
Norbert Thiebaudae4e3272012-12-11 07:49:24 -0600287
Samuel Mehrbrodt3526da12015-09-22 11:18:57 +0200288 print "Running ./configure with '" . join (" ", @args), "'\n";
Norbert Thiebaud2a9692a2011-08-18 00:25:58 -0500289 system ("./configure", @args) && die "Error running configure";
Michael Meeks434df162011-04-05 16:16:33 +0100290}
Tor Lillqvist98bbdc82011-05-29 19:41:15 +0300291
292# Local Variables:
Tor Lillqvist471fd2e2011-05-31 10:00:39 +0300293# mode: perl
294# cperl-indent-level: 4
Tor Lillqvist98bbdc82011-05-29 19:41:15 +0300295# tab-width: 4
296# indent-tabs-mode: nil
297# End:
298
Miklos Vajnaa36addc2012-01-09 22:29:10 +0100299# vim:set ft=perl shiftwidth=4 softtabstop=4 expandtab: #