Bump version to 4.3-4
[LibreOffice.git] / autogen.sh
blob6894a8ee9c7c6ea2d686f18533bb144970ce7076
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_ parmeters:
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 # migrate from the old system
81 if ( substr($_, 0, 1) eq "'" ) {
82 print STDERR "Migrating options from the old autogen.lastrun format, using:\n";
83 my @opts;
84 @opts = split(/'/);
85 foreach my $opt (@opts) {
86 if ( substr($opt, 0, 1) eq "-" ) {
87 push @lst, $opt;
88 print STDERR " $opt\n";
91 } elsif ( substr($_, 0, 1) eq "#" ) {
92 # comment
93 } elsif ( length == 0 ) {
94 # empty line
95 } else {
96 push @lst, $_;
99 close ($fh);
100 # print "read args from file '$file': @lst\n";
101 return @lst;
104 sub invalid_distro($$)
106 my ($config, $distro) = @_;
107 print STDERR "Can't find distro option set: $config\nThis is not necessarily a problem.\n";
108 print STDERR "Distros with distro option sets are:\n";
109 my $dirh;
110 opendir ($dirh, "$src_path/distro-configs");
111 while (($_ = readdir ($dirh))) {
112 /(.*)\.conf$/ || next;
113 print STDERR "\t$1\n";
115 closedir ($dirh);
118 # Alloc $ACLOCAL to specify which aclocal to use
119 $aclocal = $ENV{ACLOCAL} ? $ENV{ACLOCAL} : 'aclocal';
121 my $system = `uname -s`;
122 chomp $system;
124 sanity_checks ($system) unless($system eq 'Darwin');
126 my $aclocal_flags = $ENV{ACLOCAL_FLAGS};
128 $aclocal_flags .= " -I $src_path/m4";
129 $aclocal_flags .= " -I $src_path/m4/mac" if ($system eq 'Darwin');
130 $aclocal_flags .= " -I /opt/freeware/share/aclocal" if ($system eq 'AIX');
132 $ENV{AUTOMAKE_EXTRA_FLAGS} = '--warnings=no-portability' if (!($system eq 'Darwin'));
134 if ($src_path ne $build_path)
136 system ("ln -sf $src_path/configure.ac configure.ac");
137 system ("ln -sf $src_path/g g");
138 my @modules = <$src_path/*/Makefile>;
139 foreach my $module (@modules)
141 my $dir = basename (dirname ($module));
142 mkdir ($dir);
143 system ("ln -sf $src_path/$dir/Makefile $dir/Makefile");
145 my @external_modules = <$src_path/external/*/Makefile>;
146 mkdir ("external");
147 system ("ln -sf $src_path/external/Module_external.mk external/");
148 foreach my $module (@external_modules)
150 my $dir = basename (dirname ($module));
151 mkdir ("external/$dir");
152 system ("ln -sf $src_path/external/$dir/Makefile external/$dir/Makefile");
155 system ("$aclocal $aclocal_flags") && die "Failed to run aclocal";
156 unlink ("configure");
157 system ("autoconf -I ${src_path}") && die "Failed to run autoconf";
158 die "Failed to generate the configure script" if (! -f "configure");
160 # Handle help arguments first, so we don't clobber autogen.lastrun
161 for my $arg (@ARGV) {
162 if ($arg =~ /^(--help|-h|-\?)$/) {
163 system ("./configure --help");
164 exit;
168 my @cmdline_args = ();
170 my $input = "autogen.input";
171 my $lastrun = "autogen.lastrun";
173 if (!@ARGV) {
174 if (-f $input) {
175 if (-f $lastrun) {
176 print STDERR <<WARNING;
177 ********************************************************************
179 * Reading $input and ignoring $lastrun!
180 * Consider removing $lastrun to get rid of this warning.
182 ********************************************************************
183 WARNING
185 @cmdline_args = read_args ($input);
186 } elsif (-f $lastrun) {
187 print STDERR "Reading $lastrun. Please rename it to $input to avoid this message.\n";
188 @cmdline_args = read_args ($lastrun);
190 } else {
191 if (-f $input) {
192 print STDERR <<WARNING;
193 ********************************************************************
195 * Using commandline arguments and ignoring $input!
197 ********************************************************************
198 WARNING
200 @cmdline_args = @ARGV;
203 my @args;
204 my $default_config = "$src_path/distro-configs/default.conf";
205 if (-f $default_config) {
206 print STDERR "Reading default config file: $default_config.\n";
207 push @args, read_args ($default_config);
209 for my $arg (@cmdline_args) {
210 if ($arg eq '--clean') {
211 clean();
212 } elsif ($arg =~ m/--with-distro=(.*)$/) {
213 my $config = "$src_path/distro-configs/$1.conf";
214 if (! -f $config) {
215 invalid_distro ($config, $1);
216 } else {
217 push @args, read_args ($config);
219 } else {
220 push @args, $arg;
223 for my $arg (@args) {
224 if ($arg =~ /^([A-Z]+)=(.*)/) {
225 $ENV{$1} = $2;
229 if (defined $ENV{NOCONFIGURE}) {
230 print "Skipping configure process.";
231 } else {
232 # Save autogen.lastrun only if we did get some arguments on the command-line
233 if (! -f $input && @ARGV) {
234 if (scalar(@cmdline_args) > 0) {
235 # if there's already an autogen.lastrun, make a backup first
236 if (-e $lastrun) {
237 open (my $fh, $lastrun) || warn "Can't open $lastrun.\n";
238 open (BAK, ">$lastrun.bak") || warn "Can't create backup file $lastrun.bak.\n";
239 while (<$fh>) {
240 print BAK;
242 close (BAK) && close ($fh);
244 # print "Saving command-line args to $lastrun\n";
245 my $fh;
246 open ($fh, ">autogen.lastrun") || die "Can't open autogen.lastrun: $!";
247 for my $arg (@cmdline_args) {
248 print $fh "$arg\n";
250 close ($fh);
253 push @args, "--srcdir=$src_path";
254 push @args, "--enable-option-checking=fatal";
256 print "Running ./configure with '" . join ("' '", @args), "'\n";
257 system ("./configure", @args) && die "Error running configure";
260 # Local Variables:
261 # mode: perl
262 # cperl-indent-level: 4
263 # tab-width: 4
264 # indent-tabs-mode: nil
265 # End:
267 # vim:set ft=perl shiftwidth=4 softtabstop=4 expandtab: #