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;
36 system
("rm -Rf autom4te.cache");
37 system
("rm -f missing install-sh mkinstalldirs libtool ltmain.sh");
38 print
"Cleaned the build tree\n";
44 # check we have various vital tools
48 my @path
= split (':', $ENV{'PATH'});
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";
72 # one argument per line
78 open
($fh, $file) || die
"can't open file: $file";
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";
88 foreach my $opt (@opts) {
89 if ( substr($opt, 0, 1) eq "-" ) {
91 print STDERR " $opt\n";
94 } elsif ( /^INCLUDE:(.*)/ ) {
95 # include another .conf into this one
96 my $config = "$src_path/distro-configs/$1.conf";
98 invalid_distro ($config, $1);
100 push @lst, read_args ($config);
101 } elsif ( substr($_, 0, 1) eq "#" ) {
103 } elsif ( length == 0 ) {
110 # print "read args from file '$file': @lst\n";
114 sub show_distro_configs($$)
116 my ($prefix, $path) = @_;
118 opendir ($dirh, "$path");
119 while (($_ = readdir ($dirh))) {
122 $prefix eq "" ? "$_/" : "$prefix/$_/", "$path/$_")
123 unless $_ eq '.
' || $_ eq '..
';
126 /(.*)\.conf$/ || next;
127 print STDERR "\t$prefix$1\n";
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
");
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`;
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/m
4/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`;
184 my @modules = <$src_path/*/Makefile>;
185 foreach my $module (@modules)
187 my $dir = basename (dirname ($module));
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>;
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");
222 my @cmdline_args = ();
224 my $input = "autogen.input";
225 my $lastrun = "autogen.lastrun";
230 print STDERR <<WARNING;
231 ********************************************************************
233 * Reading $input and ignoring $lastrun!
234 * Consider removing $lastrun to get rid of this warning.
236 ********************************************************************
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);
246 print STDERR <<WARNING;
247 ********************************************************************
249 * Using commandline arguments and ignoring $input!
251 ********************************************************************
254 @cmdline_args = @ARGV;
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') {
268 } elsif ($arg =~ m/--with-distro=(.*)$/) {
269 my $config = "$src_path/distro-configs/$1.conf";
271 invalid_distro ($config, $1);
273 push @args, read_args ($config);
274 } elsif ($arg =~ m/--best-effort$/) {
275 $option_checking = 'warn
';
281 if (defined $ENV{NOCONFIGURE}) {
282 print "Skipping configure process.";
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
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";
294 close
(BAK
) && close
($fh);
296 # print "Saving command-line args to $lastrun\n";
298 open
($fh, ">autogen.lastrun") || die
"Can't open autogen.lastrun: $!";
299 for my
$arg (@cmdline_args
) {
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";
314 # cperl-indent-level: 4
316 # indent-tabs-mode: nil
319 # vim:set ft=perl shiftwidth=4 softtabstop=4 expandtab: #