Fix typo
[LibreOffice.git] / autogen.sh
blob889bb463b830141ac4f8c63ffb7e60f8bd77a16d
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 ( /^INCLUDE:(.*)/ ) {
88 # include another .conf into this one
89 my $config = "$src_path/distro-configs/$1.conf";
90 if (! -f $config) {
91 invalid_distro ($config, $1);
93 push @lst, read_args ($config);
94 } elsif ( substr($_, 0, 1) eq "#" ) {
95 # comment
96 } elsif ( length == 0 ) {
97 # empty line
98 } else {
99 push @lst, $_;
102 close ($fh);
103 # print "read args from file '$file': @lst\n";
104 return @lst;
107 sub show_distro_configs($$)
109 my ($prefix, $path) = @_;
110 my $dirh;
111 opendir ($dirh, "$path");
112 while (($_ = readdir ($dirh))) {
113 if (-d "$path/$_") {
114 show_distro_configs(
115 $prefix eq "" ? "$_/" : "$prefix/$_/", "$path/$_")
116 unless $_ eq '.' || $_ eq '..';
117 next;
119 /(.*)\.conf$/ || next;
120 print STDERR "\t$prefix$1\n";
122 closedir ($dirh);
125 sub invalid_distro($$)
127 my ($config, $distro) = @_;
128 print STDERR "Can't find distro option set: $config\n";
129 print STDERR "Distros with distro option sets are:\n";
130 show_distro_configs("", "$src_path/distro-configs");
131 exit (1);
134 # Avoid confusing "aclocal: error: non-option arguments are not accepted: '.../m4'." error message.
135 die "\$src_path must not contain spaces, but it is '$src_path'." if ($src_path =~ / /);
137 # Alloc $ACLOCAL to specify which aclocal to use
138 $aclocal = $ENV{ACLOCAL} ? $ENV{ACLOCAL} : 'aclocal';
139 # Alloc $AUTOCONF to specify which autoconf to use
140 # (e.g. autoconf268 from a backports repo)
141 $autoconf = $ENV{AUTOCONF} ? $ENV{AUTOCONF} : 'autoconf';
143 my $system = `uname -s`;
144 chomp $system;
146 sanity_checks ($system) unless($system eq 'Darwin');
148 # If we are running in a LODE env, make sure we find the right aclocal
149 # by making sure that LODE_HOME/opt/bin is in the PATH
150 if (defined $ENV{LODE_HOME})
152 my $lode_path = quotemeta "$ENV{LODE_HOME}/opt/bin";
153 if($ENV{PATH} !~ $lode_path)
155 $ENV{PATH}="$ENV{LODE_HOME}/opt/bin:$ENV{PATH}";
156 print STDERR "add LODE_HOME/opt/bin in PATH\n";
160 my $aclocal_flags = $ENV{ACLOCAL_FLAGS};
162 $aclocal_flags .= " -I $src_path/m4";
163 $aclocal_flags .= " -I $src_path/m4/mac" if ($system eq 'Darwin');
165 $ENV{AUTOMAKE_EXTRA_FLAGS} = '--warnings=no-portability' if (!($system eq 'Darwin'));
167 if ($src_path ne $build_path)
169 system ("ln -sf $src_path/configure.ac configure.ac");
170 system ("ln -sf $src_path/g g");
171 my $src_path_win=$src_path;
172 if ($system =~ /CYGWIN.*/) {
173 $src_path_win=`cygpath -m $src_path`;
174 chomp $src_path_win;
176 # wsl-as-helper method: autogen.sh/configure runs within a wsl-container (WSL_DISTRO_NAME)
177 # and build is run from within git-bash (that adds .../Git/mingw64/bin to PATH)
178 if ($ENV{WSL_DISTRO_NAME} && $ENV{PATH} =~ /mingw64/) {
179 $src_path_win=`wslpath -m $src_path`;
180 chomp $src_path_win;
182 my @modules = <$src_path/*/Makefile>;
183 foreach my $module (@modules)
185 my $dir = basename (dirname ($module));
186 mkdir ($dir);
187 system ("rm -f $dir/Makefile");
188 system ("printf 'module_directory:=$src_path_win/$dir/\ninclude \$(module_directory)/../solenv/gbuild/partial_build.mk\n' > $dir/Makefile");
190 my @external_modules = <$src_path/external/*/Makefile>;
191 mkdir ("external");
192 system ("ln -sf $src_path/external/Module_external.mk external/");
193 foreach my $module (@external_modules)
195 my $dir = basename (dirname ($module));
196 mkdir ("external/$dir");
197 system ("rm -f external/$dir/Makefile");
198 system ("printf 'module_directory:=$src_path_win/external/$dir/\ninclude \$(module_directory)/../../solenv/gbuild/partial_build.mk\n' > external/$dir/Makefile");
201 system ("$aclocal $aclocal_flags") && die "Failed to run aclocal";
202 unlink ("configure");
203 system ("$autoconf -I ${src_path}") && die "Failed to run autoconf";
204 die "Failed to generate the configure script" if (! -f "configure");
206 # Handle help arguments first, so we don't clobber autogen.lastrun
207 for my $arg (@ARGV) {
208 if ($arg =~ /^(--help|-h|-\?)$/) {
209 print STDOUT "autogen.sh - libreoffice configuration helper\n";
210 print STDOUT "When called without arguments, arguments from autogen.input are used.\n";
211 print STDOUT "\nArguments processed in the helper:\n";
212 print STDOUT " --with-distro use a config from distro-configs/\n";
213 print STDOUT " the name needs to be passed without extension\n";
214 print STDOUT " --best-effort don't fail on un-known configure with/enable options\n";
215 print STDOUT "\nOther arguments passed directly to configure:\n\n";
216 system ("./configure --help");
217 exit;
221 my @cmdline_args = ();
223 my $input = "autogen.input";
224 my $lastrun = "autogen.lastrun";
226 if (!@ARGV) {
227 if (-f $input) {
228 if (-f $lastrun) {
229 print STDERR <<WARNING;
230 ********************************************************************
232 * Reading $input and ignoring $lastrun!
233 * Consider removing $lastrun to get rid of this warning.
235 ********************************************************************
236 WARNING
238 @cmdline_args = read_args ($input);
239 } elsif (-f $lastrun) {
240 print STDERR "Reading $lastrun. Please rename it to $input to avoid this message.\n";
241 @cmdline_args = read_args ($lastrun);
243 } else {
244 if (-f $input) {
245 print STDERR <<WARNING;
246 ********************************************************************
248 * Using commandline arguments and ignoring $input!
250 ********************************************************************
251 WARNING
253 @cmdline_args = @ARGV;
256 my @args;
257 my $default_config = "$src_path/distro-configs/default.conf";
258 my $option_checking = 'fatal';
260 if (-f $default_config) {
261 print STDERR "Reading default config file: $default_config.\n";
262 push @args, read_args ($default_config);
264 for my $arg (@cmdline_args) {
265 if ($arg =~ m/--with-distro=(.*)$/) {
266 my $config = "$src_path/distro-configs/$1.conf";
267 if (! -f $config) {
268 invalid_distro ($config, $1);
270 push @args, read_args ($config);
271 } elsif ($arg =~ m/--best-effort$/) {
272 $option_checking = 'warn';
273 } else {
274 push @args, $arg;
278 if (defined $ENV{NOCONFIGURE}) {
279 print "Skipping configure process.";
280 } else {
281 # Save autogen.lastrun only if we did get some arguments on the command-line
282 if (! -f $input && @ARGV) {
283 if (scalar(@cmdline_args) > 0) {
284 # if there's already an autogen.lastrun, make a backup first
285 if (-e $lastrun) {
286 open (my $fh, $lastrun) || warn "Can't open $lastrun.\n";
287 open (BAK, ">$lastrun.bak") || warn "Can't create backup file $lastrun.bak.\n";
288 while (<$fh>) {
289 print BAK;
291 close (BAK) && close ($fh);
293 # print "Saving command-line args to $lastrun\n";
294 my $fh;
295 open ($fh, ">autogen.lastrun") || die "Can't open autogen.lastrun: $!";
296 for my $arg (@cmdline_args) {
297 print $fh "$arg\n";
299 close ($fh);
302 push @args, "--srcdir=$src_path";
303 push @args, "--enable-option-checking=$option_checking";
305 # When running a shell script from Perl on WSL, weirdly named
306 # environment variables like the "ProgramFiles(x86)" one don't get
307 # imported by the shell. So export it as PROGRAMFILESX86 instead.
308 my $building_for_linux = 0;
309 my $building_with_emscripten = 0;
310 foreach my $arg (@args) {
311 $building_for_linux = 1 if ($arg =~ /--host=x86_64.*linux/);
312 $building_with_emscripten = 1 if ($arg =~ /^--host=wasm.*-emscripten$/);
315 unshift @args, "./configure";
316 unshift @args, "emconfigure" if ($building_with_emscripten);
318 print "Running '" . join (" ", @args), "'\n";
320 if (`wslsys 2>/dev/null` ne "" && !$building_for_linux) {
321 if (!$ENV{"ProgramFiles(x86)"}) {
322 print STDERR "To build for Windows on WSL, you need to set the WSLENV environment variable in the Control Panel to 'ProgramFiles(x86)'\n";
323 print STDERR "If you actually do want to build for WSL (Linux) on WSL, pass a --host=x86_64-pc-linux-gnu option\n";
324 exit (1);
326 $ENV{"PROGRAMFILESX86"} = $ENV{"ProgramFiles(x86)"};
329 system (@args) && die "Error running configure";
332 # Local Variables:
333 # mode: perl
334 # cperl-indent-level: 4
335 # tab-width: 4
336 # indent-tabs-mode: nil
337 # End:
339 # vim:set ft=perl shiftwidth=4 softtabstop=4 expandtab: #