[cp] Collabora Office macOS packaging
[LibreOffice.git] / autogen.sh
blob4e950ff76baa337732e631035d2d73758bcc9359
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;
42 my $autoconf;
44 # check we have various vital tools
45 sub sanity_checks($)
47 my $system = shift;
48 my @path = split (':', $ENV{'PATH'});
49 my %required =
51 'pkg-config' => "pkg-config is required to be installed",
52 $autoconf => "autoconf is required",
53 $aclocal => "$aclocal is required",
56 for my $elem (@path) {
57 for my $app (keys %required) {
58 if (-f "$elem/$app") {
59 delete $required{$app};
63 if ((keys %required) > 0) {
64 print ("Various low-level dependencies are missing, please install them:\n");
65 for my $app (keys %required) {
66 print "\t $app: " . $required{$app} . "\n";
68 exit (1);
72 # one argument per line
73 sub read_args($)
75 my $file = shift;
76 my $fh;
77 my @lst;
78 open ($fh, $file) || die "can't open file: $file";
79 while (<$fh>) {
80 chomp();
81 s/^\s+//;
82 s/\s+$//;
83 # migrate from the old system
84 if ( substr($_, 0, 1) eq "'" ) {
85 print STDERR "Migrating options from the old autogen.lastrun format, using:\n";
86 my @opts;
87 @opts = split(/'/);
88 foreach my $opt (@opts) {
89 if ( substr($opt, 0, 1) eq "-" ) {
90 push @lst, $opt;
91 print STDERR " $opt\n";
94 } elsif ( /^INCLUDE:(.*)/ ) {
95 # include another .conf into this one
96 my $config = "$src_path/distro-configs/$1.conf";
97 if (! -f $config) {
98 invalid_distro ($config, $1);
100 push @lst, read_args ($config);
101 } elsif ( substr($_, 0, 1) eq "#" ) {
102 # comment
103 } elsif ( length == 0 ) {
104 # empty line
105 } else {
106 push @lst, $_;
109 close ($fh);
110 # print "read args from file '$file': @lst\n";
111 return @lst;
114 sub show_distro_configs($$)
116 my ($prefix, $path) = @_;
117 my $dirh;
118 opendir ($dirh, "$path");
119 while (($_ = readdir ($dirh))) {
120 if (-d "$path/$_") {
121 show_distro_configs(
122 $prefix eq "" ? "$_/" : "$prefix/$_/", "$path/$_")
123 unless $_ eq '.' || $_ eq '..';
124 next;
126 /(.*)\.conf$/ || next;
127 print STDERR "\t$prefix$1\n";
129 closedir ($dirh);
132 sub invalid_distro($$)
134 my ($config, $distro) = @_;
135 print STDERR "Can't find distro option set: $config\n";
136 print STDERR "Distros with distro option sets are:\n";
137 show_distro_configs("", "$src_path/distro-configs");
138 exit (1);
141 # Avoid confusing "aclocal: error: non-option arguments are not accepted: '.../m4'." error message.
142 die "\$src_path must not contain spaces, but it is '$src_path'." if ($src_path =~ / /);
144 # Alloc $ACLOCAL to specify which aclocal to use
145 $aclocal = $ENV{ACLOCAL} ? $ENV{ACLOCAL} : 'aclocal';
146 # Alloc $AUTOCONF to specify which autoconf to use
147 # (e.g. autoconf268 from a backports repo)
148 $autoconf = $ENV{AUTOCONF} ? $ENV{AUTOCONF} : 'autoconf';
150 my $system = `uname -s`;
151 chomp $system;
153 sanity_checks ($system) unless($system eq 'Darwin');
155 # If we are running in a LODE env, make sure we find the right aclocal
156 # by making sure that LODE_HOME/opt/bin is in the PATH
157 if (defined $ENV{LODE_HOME})
159 my $lode_path = quotemeta "$ENV{LODE_HOME}/opt/bin";
160 if($ENV{PATH} !~ $lode_path)
162 $ENV{PATH}="$ENV{LODE_HOME}/opt/bin:$ENV{PATH}";
163 print STDERR "add LODE_HOME/opt/bin in PATH\n";
167 my $aclocal_flags = $ENV{ACLOCAL_FLAGS};
169 $aclocal_flags .= " -I $src_path/m4";
170 $aclocal_flags .= " -I $src_path/m4/mac" if ($system eq 'Darwin');
171 $aclocal_flags .= " -I /opt/freeware/share/aclocal" if ($system eq 'AIX');
173 $ENV{AUTOMAKE_EXTRA_FLAGS} = '--warnings=no-portability' if (!($system eq 'Darwin'));
175 if ($src_path ne $build_path)
177 system ("ln -sf $src_path/configure.ac configure.ac");
178 system ("ln -sf $src_path/g g");
179 my $src_path_win=$src_path;
180 if ($system =~ /CYGWIN.*/) {
181 $src_path_win=`cygpath -m $src_path`;
182 chomp $src_path_win;
184 my @modules = <$src_path/*/Makefile>;
185 foreach my $module (@modules)
187 my $dir = basename (dirname ($module));
188 mkdir ($dir);
189 system ("rm -f $dir/Makefile");
190 system ("printf 'module_directory:=$src_path_win/$dir/\ninclude \$(module_directory)/../solenv/gbuild/partial_build.mk\n' > $dir/Makefile");
192 my @external_modules = <$src_path/external/*/Makefile>;
193 mkdir ("external");
194 system ("ln -sf $src_path/external/Module_external.mk external/");
195 foreach my $module (@external_modules)
197 my $dir = basename (dirname ($module));
198 mkdir ("external/$dir");
199 system ("rm -f external/$dir/Makefile");
200 system ("printf 'module_directory:=$src_path_win/external/$dir/\ninclude \$(module_directory)/../../solenv/gbuild/partial_build.mk\n' > external/$dir/Makefile");
203 system ("$aclocal $aclocal_flags") && die "Failed to run aclocal";
204 unlink ("configure");
205 system ("$autoconf -I ${src_path}") && die "Failed to run autoconf";
206 die "Failed to generate the configure script" if (! -f "configure");
208 # Handle help arguments first, so we don't clobber autogen.lastrun
209 for my $arg (@ARGV) {
210 if ($arg =~ /^(--help|-h|-\?)$/) {
211 print STDOUT "autogen.sh - libreoffice configuration helper\n";
212 print STDOUT " --clean forcibly re-generate configuration\n";
213 print STDOUT " --with-distro use a config from distro-configs/\n";
214 print STDOUT " the name needs to be passed without extension\n";
215 print STDOUT " --best-effort don't fail on un-known configure with/enable options\n";
216 print STDOUT "\nOther arguments passed directly to configure:\n\n";
217 system ("./configure --help");
218 exit;
222 my @cmdline_args = ();
224 my $input = "autogen.input";
225 my $lastrun = "autogen.lastrun";
227 if (!@ARGV) {
228 if (-f $input) {
229 if (-f $lastrun) {
230 print STDERR <<WARNING;
231 ********************************************************************
233 * Reading $input and ignoring $lastrun!
234 * Consider removing $lastrun to get rid of this warning.
236 ********************************************************************
237 WARNING
239 @cmdline_args = read_args ($input);
240 } elsif (-f $lastrun) {
241 print STDERR "Reading $lastrun. Please rename it to $input to avoid this message.\n";
242 @cmdline_args = read_args ($lastrun);
244 } else {
245 if (-f $input) {
246 print STDERR <<WARNING;
247 ********************************************************************
249 * Using commandline arguments and ignoring $input!
251 ********************************************************************
252 WARNING
254 @cmdline_args = @ARGV;
257 my @args;
258 my $default_config = "$src_path/distro-configs/default.conf";
259 my $option_checking = 'fatal';
261 if (-f $default_config) {
262 print STDERR "Reading default config file: $default_config.\n";
263 push @args, read_args ($default_config);
265 for my $arg (@cmdline_args) {
266 if ($arg eq '--clean') {
267 clean();
268 } elsif ($arg =~ m/--with-distro=(.*)$/) {
269 my $config = "$src_path/distro-configs/$1.conf";
270 if (! -f $config) {
271 invalid_distro ($config, $1);
273 push @args, read_args ($config);
274 } elsif ($arg =~ m/--best-effort$/) {
275 $option_checking = 'warn';
276 } else {
277 push @args, $arg;
281 if (defined $ENV{NOCONFIGURE}) {
282 print "Skipping configure process.";
283 } else {
284 # Save autogen.lastrun only if we did get some arguments on the command-line
285 if (! -f $input && @ARGV) {
286 if (scalar(@cmdline_args) > 0) {
287 # if there's already an autogen.lastrun, make a backup first
288 if (-e $lastrun) {
289 open (my $fh, $lastrun) || warn "Can't open $lastrun.\n";
290 open (BAK, ">$lastrun.bak") || warn "Can't create backup file $lastrun.bak.\n";
291 while (<$fh>) {
292 print BAK;
294 close (BAK) && close ($fh);
296 # print "Saving command-line args to $lastrun\n";
297 my $fh;
298 open ($fh, ">autogen.lastrun") || die "Can't open autogen.lastrun: $!";
299 for my $arg (@cmdline_args) {
300 print $fh "$arg\n";
302 close ($fh);
305 push @args, "--srcdir=$src_path";
306 push @args, "--enable-option-checking=$option_checking";
308 print "Running ./configure with '" . join (" ", @args), "'\n";
309 system ("./configure", @args) && die "Error running configure";
312 # Local Variables:
313 # mode: perl
314 # cperl-indent-level: 4
315 # tab-width: 4
316 # indent-tabs-mode: nil
317 # End:
319 # vim:set ft=perl shiftwidth=4 softtabstop=4 expandtab: #