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";
43 # check we have various vital tools
47 my @path
= split (':', $ENV{'PATH'});
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";
71 # one argument per line
77 open
($fh, $file) || die
"can't open file: $file";
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";
87 foreach my $opt (@opts) {
88 if ( substr($opt, 0, 1) eq "-" ) {
90 print STDERR " $opt\n";
93 } elsif ( substr($_, 0, 1) eq "#" ) {
95 } elsif ( length == 0 ) {
102 # print "read args from file '$file': @lst\n";
106 sub show_distro_configs($$)
108 my ($prefix, $path) = @_;
110 opendir ($dirh, "$path");
111 while (($_ = readdir ($dirh))) {
114 $prefix eq "" ? "$_/" : "$prefix/$_/", "$path/$_")
115 unless $_ eq '.
' || $_ eq '..
';
118 /(.*)\.conf$/ || next;
119 print STDERR "\t$prefix$1\n";
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
");
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`;
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/m
4/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 $src_path_win=$src_path;
169 if ($system =~ /CYGWIN.*/) {
170 $src_path_win=`cygpath -m $src_path`;
173 my @modules = <$src_path/*/Makefile>;
174 foreach my $module (@modules)
176 my $dir = basename (dirname ($module));
178 system ("rm -f $dir/Makefile
");
179 system ("printf 'module_directory:=$src_path_win/$dir/\ninclude \$(module_directory)/../solenv/gbuild/partial_build.mk\n' > $dir/Makefile
");
181 my @external_modules = <$src_path/external/*/Makefile>;
183 system ("ln -sf $src_path/external
/Module_external.mk external
/");
184 foreach my $module (@external_modules)
186 my $dir = basename (dirname ($module));
187 mkdir ("external
/$dir");
188 system ("rm -f external
/$dir/Makefile
");
189 system ("printf 'module_directory:=$src_path_win/external/$dir/\ninclude \$(module_directory)/../../solenv/gbuild/partial_build.mk\n' > external
/$dir/Makefile
");
192 system ("$aclocal $aclocal_flags") && die "Failed to run aclocal
";
193 unlink ("configure
");
194 system ("autoconf
-I ${src_path}") && die "Failed to run autoconf
";
195 die "Failed to generate the configure
script" if (! -f "configure
");
197 # Handle help arguments first, so we don't clobber autogen.lastrun
198 for my $arg (@ARGV) {
199 if ($arg =~ /^(--help|-h|-\?)$/) {
200 print STDOUT "autogen.sh
- libreoffice configuration helper
\n";
201 print STDOUT " --clean forcibly re-generate configuration
\n";
202 print STDOUT " --best-effort don
't fail on un-known configure with/enable options\n";
203 print STDOUT "\nOther arguments passed directly to configure:\n\n";
204 system ("./configure --help");
209 my @cmdline_args = ();
211 my $input = "autogen.input";
212 my $lastrun = "autogen.lastrun";
217 print STDERR <<WARNING;
218 ********************************************************************
220 * Reading $input and ignoring $lastrun!
221 * Consider removing $lastrun to get rid of this warning.
223 ********************************************************************
226 @cmdline_args = read_args ($input);
227 } elsif (-f $lastrun) {
228 print STDERR "Reading $lastrun. Please rename it to $input to avoid this message.\n";
229 @cmdline_args = read_args ($lastrun);
233 print STDERR <<WARNING;
234 ********************************************************************
236 * Using commandline arguments and ignoring $input!
238 ********************************************************************
241 @cmdline_args = @ARGV;
245 my $default_config = "$src_path/distro-configs/default.conf";
246 my $option_checking = 'fatal
';
248 if (-f $default_config) {
249 print STDERR "Reading default config file: $default_config.\n";
250 push @args, read_args ($default_config);
252 for my $arg (@cmdline_args) {
253 if ($arg eq '--clean') {
255 } elsif ($arg =~ m/--with-distro=(.*)$/) {
256 my $config = "$src_path/distro-configs/$1.conf";
258 invalid_distro ($config, $1);
260 push @args, read_args ($config);
261 } elsif ($arg =~ m/--best-effort$/) {
262 $option_checking = 'warn
';
268 if (defined $ENV{NOCONFIGURE}) {
269 print "Skipping configure process.";
271 # Save autogen.lastrun only if we did get some arguments on the command-line
272 if (! -f $input && @ARGV) {
273 if (scalar(@cmdline_args) > 0) {
274 # if there's already an autogen.lastrun
, make a backup first
276 open
(my
$fh, $lastrun) || warn
"Can't open $lastrun.\n";
277 open
(BAK
, ">$lastrun.bak") || warn
"Can't create backup file $lastrun.bak.\n";
281 close
(BAK
) && close
($fh);
283 # print "Saving command-line args to $lastrun\n";
285 open
($fh, ">autogen.lastrun") || die
"Can't open autogen.lastrun: $!";
286 for my
$arg (@cmdline_args
) {
292 push @args
, "--srcdir=$src_path";
293 push @args
, "--enable-option-checking=$option_checking";
295 print
"Running ./configure with '" .
join (" ", @args
), "'\n";
296 system
("./configure", @args
) && die
"Error running configure";
301 # cperl-indent-level: 4
303 # indent-tabs-mode: nil
306 # vim:set ft=perl shiftwidth=4 softtabstop=4 expandtab: #