Anti-alias toolbar button drop-downs.
[LibreOffice.git] / autogen.sh
blob8c0bb0ade4bae54f30a007c6f7dcebc62965b3f8
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 sub clean()
36 system ("rm -Rf autom4te.cache");
37 system ("rm -f missing install-sh mkinstalldirs libtool ltmain.sh");
38 print "Cleaned the build tree\n";
41 my $aclocal;
43 # check we have various vital tools
44 sub sanity_checks($)
46 my $system = shift;
47 my @path = split (':', $ENV{'PATH'});
48 my %required =
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";
67 exit (1);
71 # one argument per line
72 sub read_args($)
74 my $file = shift;
75 my $fh;
76 my @lst;
77 open ($fh, $file) || die "can't open file: $file";
78 while (<$fh>) {
79 chomp();
80 s/^\s+//;
81 s/\s+$//;
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";
85 my @opts;
86 @opts = split(/'/);
87 foreach my $opt (@opts) {
88 if ( substr($opt, 0, 1) eq "-" ) {
89 push @lst, $opt;
90 print STDERR " $opt\n";
93 } elsif ( substr($_, 0, 1) eq "#" ) {
94 # comment
95 } elsif ( length == 0 ) {
96 # empty line
97 } else {
98 push @lst, $_;
101 close ($fh);
102 # print "read args from file '$file': @lst\n";
103 return @lst;
106 sub show_distro_configs($$)
108 my ($prefix, $path) = @_;
109 my $dirh;
110 opendir ($dirh, "$path");
111 while (($_ = readdir ($dirh))) {
112 if (-d "$path/$_") {
113 show_distro_configs(
114 $prefix eq "" ? "$_/" : "$prefix/$_/", "$path/$_")
115 unless $_ eq '.' || $_ eq '..';
116 next;
118 /(.*)\.conf$/ || next;
119 print STDERR "\t$prefix$1\n";
121 closedir ($dirh);
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");
130 exit (1);
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`;
140 chomp $system;
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/m4/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`;
171 chomp $src_path_win;
173 my @modules = <$src_path/*/Makefile>;
174 foreach my $module (@modules)
176 my $dir = basename (dirname ($module));
177 mkdir ($dir);
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>;
182 mkdir ("external");
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");
205 exit;
209 my @cmdline_args = ();
211 my $input = "autogen.input";
212 my $lastrun = "autogen.lastrun";
214 if (!@ARGV) {
215 if (-f $input) {
216 if (-f $lastrun) {
217 print STDERR <<WARNING;
218 ********************************************************************
220 * Reading $input and ignoring $lastrun!
221 * Consider removing $lastrun to get rid of this warning.
223 ********************************************************************
224 WARNING
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);
231 } else {
232 if (-f $input) {
233 print STDERR <<WARNING;
234 ********************************************************************
236 * Using commandline arguments and ignoring $input!
238 ********************************************************************
239 WARNING
241 @cmdline_args = @ARGV;
244 my @args;
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') {
254 clean();
255 } elsif ($arg =~ m/--with-distro=(.*)$/) {
256 my $config = "$src_path/distro-configs/$1.conf";
257 if (! -f $config) {
258 invalid_distro ($config, $1);
260 push @args, read_args ($config);
261 } elsif ($arg =~ m/--best-effort$/) {
262 $option_checking = 'warn';
263 } else {
264 push @args, $arg;
268 if (defined $ENV{NOCONFIGURE}) {
269 print "Skipping configure process.";
270 } else {
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
275 if (-e $lastrun) {
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";
278 while (<$fh>) {
279 print BAK;
281 close (BAK) && close ($fh);
283 # print "Saving command-line args to $lastrun\n";
284 my $fh;
285 open ($fh, ">autogen.lastrun") || die "Can't open autogen.lastrun: $!";
286 for my $arg (@cmdline_args) {
287 print $fh "$arg\n";
289 close ($fh);
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";
299 # Local Variables:
300 # mode: perl
301 # cperl-indent-level: 4
302 # tab-width: 4
303 # indent-tabs-mode: nil
304 # End:
306 # vim:set ft=perl shiftwidth=4 softtabstop=4 expandtab: #