Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / autogen.sh
blob20976ce66d3fda892ac3917dd2829f310d72cac7
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 s/\s+$//;
82 # migrate from the old system
83 if ( substr($_, 0, 1) eq "'" ) {
84 print STDERR "Migrating options from the old autogen.lastrun format, using:\n";
85 my @opts;
86 @opts = split(/'/);
87 foreach my $opt (@opts) {
88 if ( substr($opt, 0, 1) eq "-" ) {
89 push @lst, $opt;
90 print STDERR " $opt\n";
93 } elsif ( substr($_, 0, 1) eq "#" ) {
94 # comment
95 } elsif ( length == 0 ) {
96 # empty line
97 } else {
98 push @lst, $_;
101 close ($fh);
102 # print "read args from file '$file': @lst\n";
103 return @lst;
106 sub show_distro_configs($$)
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;
118 /(.*)\.conf$/ || next;
119 print STDERR "\t$prefix$1\n";
121 closedir ($dirh);
124 sub invalid_distro($$)
126 my ($config, $distro) = @_;
127 print STDERR "Can't find distro option set: $config\n";
128 print STDERR "Distros with distro option sets are:\n";
129 show_distro_configs("", "$src_path/distro-configs");
130 exit (1);
133 # Avoid confusing "aclocal: error: non-option arguments are not accepted: '.../m4'." error message.
134 die "\$src_path must not contain spaces, but it is '$src_path'." if ($src_path =~ / /);
136 # Alloc $ACLOCAL to specify which aclocal to use
137 $aclocal = $ENV{ACLOCAL} ? $ENV{ACLOCAL} : 'aclocal';
139 my $system = `uname -s`;
140 chomp $system;
142 sanity_checks ($system) unless($system eq 'Darwin');
144 # 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
146 if (defined $ENV{LODE_HOME})
148 my $lode_path = quotemeta "$ENV{LODE_HOME}/opt/bin";
149 if($ENV{PATH} !~ $lode_path)
151 $ENV{PATH}="$ENV{LODE_HOME}/opt/bin:$ENV{PATH}";
152 print STDERR "add LODE_HOME/opt/bin in PATH\n";
156 my $aclocal_flags = $ENV{ACLOCAL_FLAGS};
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');
162 $ENV{AUTOMAKE_EXTRA_FLAGS} = '--warnings=no-portability' if (!($system eq 'Darwin'));
164 if ($src_path ne $build_path)
166 system ("ln -sf $src_path/configure.ac configure.ac");
167 system ("ln -sf $src_path/g g");
168 my @modules = <$src_path/*/Makefile>;
169 foreach my $module (@modules)
171 my $dir = basename (dirname ($module));
172 mkdir ($dir);
173 system ("ln -sf $src_path/$dir/Makefile $dir/Makefile");
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)
180 my $dir = basename (dirname ($module));
181 mkdir ("external/$dir");
182 system ("ln -sf $src_path/external/$dir/Makefile external/$dir/Makefile");
185 system ("$aclocal $aclocal_flags") && die "Failed to run aclocal";
186 unlink ("configure");
187 system ("autoconf -I ${src_path}") && die "Failed to run autoconf";
188 die "Failed to generate the configure script" if (! -f "configure");
190 # Handle help arguments first, so we don't clobber autogen.lastrun
191 for my $arg (@ARGV) {
192 if ($arg =~ /^(--help|-h|-\?)$/) {
193 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";
197 system ("./configure --help");
198 exit;
202 my @cmdline_args = ();
204 my $input = "autogen.input";
205 my $lastrun = "autogen.lastrun";
207 if (!@ARGV) {
208 if (-f $input) {
209 if (-f $lastrun) {
210 print STDERR <<WARNING;
211 ********************************************************************
213 * Reading $input and ignoring $lastrun!
214 * Consider removing $lastrun to get rid of this warning.
216 ********************************************************************
217 WARNING
219 @cmdline_args = read_args ($input);
220 } elsif (-f $lastrun) {
221 print STDERR "Reading $lastrun. Please rename it to $input to avoid this message.\n";
222 @cmdline_args = read_args ($lastrun);
224 } else {
225 if (-f $input) {
226 print STDERR <<WARNING;
227 ********************************************************************
229 * Using commandline arguments and ignoring $input!
231 ********************************************************************
232 WARNING
234 @cmdline_args = @ARGV;
237 my @args;
238 my $default_config = "$src_path/distro-configs/default.conf";
239 my $option_checking = 'fatal';
241 if (-f $default_config) {
242 print STDERR "Reading default config file: $default_config.\n";
243 push @args, read_args ($default_config);
245 for my $arg (@cmdline_args) {
246 if ($arg eq '--clean') {
247 clean();
248 } elsif ($arg =~ m/--with-distro=(.*)$/) {
249 my $config = "$src_path/distro-configs/$1.conf";
250 if (! -f $config) {
251 invalid_distro ($config, $1);
253 push @args, read_args ($config);
254 } elsif ($arg =~ m/--best-effort$/) {
255 $option_checking = 'warn';
256 } else {
257 push @args, $arg;
261 if (defined $ENV{NOCONFIGURE}) {
262 print "Skipping configure process.";
263 } else {
264 # 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;
274 close (BAK) && close ($fh);
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";
282 close ($fh);
285 push @args, "--srcdir=$src_path";
286 push @args, "--enable-option-checking=$option_checking";
288 print "Running ./configure with '" . join (" ", @args), "'\n";
289 system ("./configure", @args) && die "Error running configure";
292 # Local Variables:
293 # mode: perl
294 # cperl-indent-level: 4
295 # tab-width: 4
296 # indent-tabs-mode: nil
297 # End:
299 # vim:set ft=perl shiftwidth=4 softtabstop=4 expandtab: #