1: 2# 3# This script checks various configure parameters and uses three files: 4# * autogen.input (ro) 5# * autogen.lastrun (rw) 6# * autogen.lastrun.bak (rw) 7# 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 13# 14# Run configure with checked args 15# 16 eval 'exec perl -S $0 ${1+"$@"}' 17 if 0; 18 19use strict; 20use Cwd ('cwd', 'realpath'); 21use File::Basename; 22 23my $src_path=dirname(realpath($0)); 24my $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 29chdir ($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; 33 34sub clean() 35{ 36 system ("rm -Rf autom4te.cache"); 37 system ("rm -f missing install-sh mkinstalldirs libtool ltmain.sh"); 38 print "Cleaned the build tree\n"; 39} 40 41my $aclocal; 42my $autoconf; 43 44# check we have various vital tools 45sub sanity_checks($) 46{ 47 my $system = shift; 48 my @path = split (':', $ENV{'PATH'}); 49 my %required = 50 ( 51 'pkg-config' => "pkg-config is required to be installed", 52 $autoconf => "autoconf is required", 53 $aclocal => "$aclocal is required", 54 ); 55 56 for my $elem (@path) { 57 for my $app (keys %required) { 58 if (-f "$elem/$app") { 59 delete $required{$app}; 60 } 61 } 62 } 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"; 67 } 68 exit (1); 69 } 70} 71 72# one argument per line 73sub read_args($) 74{ 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"; 92 } 93 } 94 } elsif ( substr($_, 0, 1) eq "#" ) { 95 # comment 96 } elsif ( length == 0 ) { 97 # empty line 98 } else { 99 push @lst, $_; 100 } 101 } 102 close ($fh); 103 # print "read args from file '$file': @lst\n"; 104 return @lst; 105} 106 107sub show_distro_configs($$) 108{ 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; 118 } 119 /(.*)\.conf$/ || next; 120 print STDERR "\t$prefix$1\n"; 121 } 122 closedir ($dirh); 123} 124 125sub invalid_distro($$) 126{ 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); 132} 133 134# Avoid confusing "aclocal: error: non-option arguments are not accepted: '.../m4'." error message. 135die "\$src_path must not contain spaces, but it is '$src_path'." if ($src_path =~ / /); 136 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'; 142 143my $system = `uname -s`; 144chomp $system; 145 146sanity_checks ($system) unless($system eq 'Darwin'); 147 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 150if (defined $ENV{LODE_HOME}) 151{ 152 my $lode_path = quotemeta "$ENV{LODE_HOME}/opt/bin"; 153 if($ENV{PATH} !~ $lode_path) 154 { 155 $ENV{PATH}="$ENV{LODE_HOME}/opt/bin:$ENV{PATH}"; 156 print STDERR "add LODE_HOME/opt/bin in PATH\n"; 157 } 158} 159 160my $aclocal_flags = $ENV{ACLOCAL_FLAGS}; 161 162$aclocal_flags .= " -I $src_path/m4"; 163$aclocal_flags .= " -I $src_path/m4/mac" if ($system eq 'Darwin'); 164$aclocal_flags .= " -I /opt/freeware/share/aclocal" if ($system eq 'AIX'); 165 166$ENV{AUTOMAKE_EXTRA_FLAGS} = '--warnings=no-portability' if (!($system eq 'Darwin')); 167 168if ($src_path ne $build_path) 169{ 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`; 175 chomp $src_path_win; 176 } 177 my @modules = <$src_path/*/Makefile>; 178 foreach my $module (@modules) 179 { 180 my $dir = basename (dirname ($module)); 181 mkdir ($dir); 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"); 184 } 185 my @external_modules = <$src_path/external/*/Makefile>; 186 mkdir ("external"); 187 system ("ln -sf $src_path/external/Module_external.mk external/"); 188 foreach my $module (@external_modules) 189 { 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"); 194 } 195} 196system ("$aclocal $aclocal_flags") && die "Failed to run aclocal"; 197unlink ("configure"); 198system ("$autoconf -I ${src_path}") && die "Failed to run autoconf"; 199die "Failed to generate the configure script" if (! -f "configure"); 200 201# Handle help arguments first, so we don't clobber autogen.lastrun 202for my $arg (@ARGV) { 203 if ($arg =~ /^(--help|-h|-\?)$/) { 204 print STDOUT "autogen.sh - libreoffice configuration helper\n"; 205 print STDOUT " --clean forcibly re-generate configuration\n"; 206 print STDOUT " --with-distro use a config from distro-configs/\n"; 207 print STDOUT " the name needs to be passed without extension\n"; 208 print STDOUT " --best-effort don't fail on un-known configure with/enable options\n"; 209 print STDOUT "\nOther arguments passed directly to configure:\n\n"; 210 system ("./configure --help"); 211 exit; 212 } 213} 214 215my @cmdline_args = (); 216 217my $input = "autogen.input"; 218my $lastrun = "autogen.lastrun"; 219 220if (!@ARGV) { 221 if (-f $input) { 222 if (-f $lastrun) { 223 print STDERR <<WARNING; 224******************************************************************** 225* 226* Reading $input and ignoring $lastrun! 227* Consider removing $lastrun to get rid of this warning. 228* 229******************************************************************** 230WARNING 231 } 232 @cmdline_args = read_args ($input); 233 } elsif (-f $lastrun) { 234 print STDERR "Reading $lastrun. Please rename it to $input to avoid this message.\n"; 235 @cmdline_args = read_args ($lastrun); 236 } 237} else { 238 if (-f $input) { 239 print STDERR <<WARNING; 240******************************************************************** 241* 242* Using commandline arguments and ignoring $input! 243* 244******************************************************************** 245WARNING 246 } 247 @cmdline_args = @ARGV; 248} 249 250my @args; 251my $default_config = "$src_path/distro-configs/default.conf"; 252my $option_checking = 'fatal'; 253 254if (-f $default_config) { 255 print STDERR "Reading default config file: $default_config.\n"; 256 push @args, read_args ($default_config); 257} 258for my $arg (@cmdline_args) { 259 if ($arg eq '--clean') { 260 clean(); 261 } elsif ($arg =~ m/--with-distro=(.*)$/) { 262 my $config = "$src_path/distro-configs/$1.conf"; 263 if (! -f $config) { 264 invalid_distro ($config, $1); 265 } 266 push @args, read_args ($config); 267 } elsif ($arg =~ m/--best-effort$/) { 268 $option_checking = 'warn'; 269 } else { 270 push @args, $arg; 271 } 272} 273 274if (defined $ENV{NOCONFIGURE}) { 275 print "Skipping configure process."; 276} else { 277 # Save autogen.lastrun only if we did get some arguments on the command-line 278 if (! -f $input && @ARGV) { 279 if (scalar(@cmdline_args) > 0) { 280 # if there's already an autogen.lastrun, make a backup first 281 if (-e $lastrun) { 282 open (my $fh, $lastrun) || warn "Can't open $lastrun.\n"; 283 open (BAK, ">$lastrun.bak") || warn "Can't create backup file $lastrun.bak.\n"; 284 while (<$fh>) { 285 print BAK; 286 } 287 close (BAK) && close ($fh); 288 } 289 # print "Saving command-line args to $lastrun\n"; 290 my $fh; 291 open ($fh, ">autogen.lastrun") || die "Can't open autogen.lastrun: $!"; 292 for my $arg (@cmdline_args) { 293 print $fh "$arg\n"; 294 } 295 close ($fh); 296 } 297 } 298 push @args, "--srcdir=$src_path"; 299 push @args, "--enable-option-checking=$option_checking"; 300 301 print "Running ./configure with '" . join (" ", @args), "'\n"; 302 system ("./configure", @args) && die "Error running configure"; 303} 304 305# Local Variables: 306# mode: perl 307# cperl-indent-level: 4 308# tab-width: 4 309# indent-tabs-mode: nil 310# End: 311 312# vim:set ft=perl shiftwidth=4 softtabstop=4 expandtab: # 313