3 # This script checks various configure parameters and uses three files:
5 # * autogen.lastrun (rw)
6 # * autogen.lastrun.bak (rw)
9 # Read args from autogen.input or autogen.lastrun
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+"$@"}'
20 use Cwd
('cwd', 'realpath');
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
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;
37 # check we have various vital tools
41 my @path
= split (':', $ENV{'PATH'});
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";
65 # one argument per line
71 open
($fh, $file) || die
"can't open file: $file";
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";
81 foreach my $opt (@opts) {
82 if ( substr($opt, 0, 1) eq "-" ) {
84 print STDERR " $opt\n";
87 } elsif ( /^INCLUDE:(.*)/ ) {
88 # include another .conf into this one
89 my $config = "$src_path/distro-configs/$1.conf";
91 invalid_distro ($config, $1);
93 push @lst, read_args ($config);
94 } elsif ( substr($_, 0, 1) eq "#" ) {
96 } elsif ( length == 0 ) {
103 # print "read args from file '$file': @lst\n";
107 sub show_distro_configs($$)
109 my ($prefix, $path) = @_;
111 opendir ($dirh, "$path");
112 while (($_ = readdir ($dirh))) {
115 $prefix eq "" ? "$_/" : "$prefix/$_/", "$path/$_")
116 unless $_ eq '.
' || $_ eq '..
';
119 /(.*)\.conf$/ || next;
120 print STDERR "\t$prefix$1\n";
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
");
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`;
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/m
4/mac
" if ($system eq 'Darwin');
164 $aclocal_flags .= " -I /opt
/freeware
/share
/aclocal
" if ($system eq 'AIX');
166 $ENV{AUTOMAKE_EXTRA_FLAGS} = '--warnings=no-portability' if (!($system eq 'Darwin'));
168 if ($src_path ne $build_path)
170 system ("ln -sf $src_path/configure.ac configure.ac
");
171 system ("ln -sf $src_path/g g
");
172 my $src_path_win=$src_path;
173 if ($system =~ /CYGWIN.*/) {
174 $src_path_win=`cygpath -m $src_path`;
177 my @modules = <$src_path/*/Makefile>;
178 foreach my $module (@modules)
180 my $dir = basename (dirname ($module));
182 system ("rm -f $dir/Makefile
");
183 system ("printf 'module_directory:=$src_path_win/$dir/\ninclude \$(module_directory)/../solenv/gbuild/partial_build.mk\n' > $dir/Makefile
");
185 my @external_modules = <$src_path/external/*/Makefile>;
187 system ("ln -sf $src_path/external
/Module_external.mk external
/");
188 foreach my $module (@external_modules)
190 my $dir = basename (dirname ($module));
191 mkdir ("external
/$dir");
192 system ("rm -f external
/$dir/Makefile
");
193 system ("printf 'module_directory:=$src_path_win/external/$dir/\ninclude \$(module_directory)/../../solenv/gbuild/partial_build.mk\n' > external
/$dir/Makefile
");
196 system ("$aclocal $aclocal_flags") && die "Failed to run aclocal
";
197 unlink ("configure
");
198 system ("$autoconf -I ${src_path}") && die "Failed to run autoconf
";
199 die "Failed to generate the configure
script" if (! -f "configure
");
201 # Handle help arguments first, so we don't clobber autogen.lastrun
202 for my $arg (@ARGV) {
203 if ($arg =~ /^(--help|-h|-\?)$/) {
204 print STDOUT "autogen.sh
- libreoffice configuration helper
\n";
205 print STDOUT " --with-distro use a config from distro-configs
/\n";
206 print STDOUT " the name needs to be passed without extension
\n";
207 print STDOUT " --best-effort don
't fail on un-known configure with/enable options\n";
208 print STDOUT "\nOther arguments passed directly to configure:\n\n";
209 system ("./configure --help");
214 my @cmdline_args = ();
216 my $input = "autogen.input";
217 my $lastrun = "autogen.lastrun";
222 print STDERR <<WARNING;
223 ********************************************************************
225 * Reading $input and ignoring $lastrun!
226 * Consider removing $lastrun to get rid of this warning.
228 ********************************************************************
231 @cmdline_args = read_args ($input);
232 } elsif (-f $lastrun) {
233 print STDERR "Reading $lastrun. Please rename it to $input to avoid this message.\n";
234 @cmdline_args = read_args ($lastrun);
238 print STDERR <<WARNING;
239 ********************************************************************
241 * Using commandline arguments and ignoring $input!
243 ********************************************************************
246 @cmdline_args = @ARGV;
250 my $default_config = "$src_path/distro-configs/default.conf";
251 my $option_checking = 'fatal
';
253 if (-f $default_config) {
254 print STDERR "Reading default config file: $default_config.\n";
255 push @args, read_args ($default_config);
257 for my $arg (@cmdline_args) {
258 if ($arg =~ m/--with-distro=(.*)$/) {
259 my $config = "$src_path/distro-configs/$1.conf";
261 invalid_distro ($config, $1);
263 push @args, read_args ($config);
264 } elsif ($arg =~ m/--best-effort$/) {
265 $option_checking = 'warn
';
271 if (defined $ENV{NOCONFIGURE}) {
272 print "Skipping configure process.";
274 # Save autogen.lastrun only if we did get some arguments on the command-line
275 if (! -f $input && @ARGV) {
276 if (scalar(@cmdline_args) > 0) {
277 # if there's already an autogen.lastrun
, make a backup first
279 open
(my
$fh, $lastrun) || warn
"Can't open $lastrun.\n";
280 open
(BAK
, ">$lastrun.bak") || warn
"Can't create backup file $lastrun.bak.\n";
284 close
(BAK
) && close
($fh);
286 # print "Saving command-line args to $lastrun\n";
288 open
($fh, ">autogen.lastrun") || die
"Can't open autogen.lastrun: $!";
289 for my
$arg (@cmdline_args
) {
295 push @args
, "--srcdir=$src_path";
296 push @args
, "--enable-option-checking=$option_checking";
298 # When running a shell script from Perl on WSL, weirdly named
299 # environment variables like the "ProgramFiles(x86)" one don't get
300 # imported by the shell. So export it as PROGRAMFILESX86 instead.
301 my
$building_for_linux = 0;
302 my
$building_with_emscripten = 0;
303 foreach my
$arg (@args
) {
304 $building_for_linux = 1 if ($arg =~
/--host=x86_64.
*linux
/);
305 $building_with_emscripten = 1 if ($arg =~
/^
--host=wasm.
*-emscripten$
/);
308 unshift @args
, "./configure";
309 unshift @args
, "emconfigure" if ($building_with_emscripten);
311 print
"Running '" .
join (" ", @args
), "'\n";
313 if (`wslsys 2>/dev/null` ne
"" && !$building_for_linux) {
314 if (!$ENV{"ProgramFiles(x86)"}) {
315 print STDERR
"To build for Windows on WSL, you need to set the WSLENV environment variable in the Control Panel to 'ProgramFiles(x86)'\n";
316 print STDERR
"If you actually do want to build for WSL (Linux) on WSL, pass a --host=x86_64-pc-linux-gnu option\n";
319 $ENV{"PROGRAMFILESX86"} = $ENV{"ProgramFiles(x86)"};
322 system
(@args
) && die
"Error running configure";
327 # cperl-indent-level: 4
329 # indent-tabs-mode: nil
332 # vim:set ft=perl shiftwidth=4 softtabstop=4 expandtab: #