Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / autogen.sh
blob04d87c0ea903b4090819337ea5a2e27dd35251ce
2 eval 'exec perl -S $0 ${1+"$@"}'
3 if 0;
5 use strict;
6 use Cwd ('cwd', 'realpath');
8 sub clean()
10 system ("rm -Rf autom4te.cache");
11 system ("rm -f missing install-sh mkinstalldirs libtool ltmain.sh");
12 print "cleaned the build tree\n";
15 my $aclocal;
17 # check we have various vital tools
18 sub sanity_checks($)
20 my $system = shift;
21 my @path = split (':', $ENV{'PATH'});
22 my %required =
24 'pkg-config' => "pkg-config is required to be installed",
25 'autoconf' => "autoconf is required",
26 $aclocal => "$aclocal is required",
29 for my $elem (@path) {
30 for my $app (keys %required) {
31 if (-f "$elem/$app") {
32 delete $required{$app};
36 if ((keys %required) > 0) {
37 print ("Various low-level dependencies are missing, please install them:\n");
38 for my $app (keys %required) {
39 print "\t $app: " . $required{$app} . "\n";
41 exit (1);
45 # one argument per line
46 sub read_args($)
48 my $file = shift;
49 my $fh;
50 my @lst;
51 open ($fh, $file) || die "can't open file: $file";
52 while (<$fh>) {
53 chomp();
54 # migrate from the old system
55 if ( substr($_, 0, 1) eq "'" ) {
56 print "Migrating options from the old autogen.lastrun format, using:\n";
57 my @opts;
58 @opts = split(/'/);
59 foreach my $opt (@opts) {
60 if ( substr($opt, 0, 1) eq "-" ) {
61 push @lst, $opt;
62 print " $opt\n";
65 } elsif ( substr($_, 0, 1) eq "#" ) {
66 # comment
67 } else {
68 push @lst, $_;
71 close ($fh);
72 # print "read args from file '$file': @lst\n";
73 return @lst;
76 sub invalid_distro($$)
78 my ($config, $distro) = @_;
79 print STDERR "Can't find distro option set: $config\nThis is not necessarily a problem.\n";
80 print STDERR "Distros with distro option sets are:\n";
81 my $dirh;
82 opendir ($dirh, "distro-configs");
83 while (($_ = readdir ($dirh))) {
84 /(.*)\.conf$/ || next;
85 print STDERR "\t$1\n";
87 closedir ($dirh);
90 # Handle help arguments first, so we don't clobber autogen.lastrun
91 for my $arg (@ARGV) {
92 if ($arg =~ /^(--help|-h|-\?)$/) {
93 system ("./configure --help");
94 exit;
98 my @cmdline_args = ();
99 if (!@ARGV) {
100 my $lastrun = "autogen.lastrun";
101 @cmdline_args = read_args ($lastrun) if (-f $lastrun);
102 } else {
103 @cmdline_args = @ARGV;
106 my @args;
107 my $default_config = "distro-configs/default.conf";
108 if (-f $default_config) {
109 print STDERR "Reading default config file: $default_config\n";
110 push @args, read_args ($default_config);
112 for my $arg (@cmdline_args) {
113 if ($arg eq '--clean') {
114 clean();
115 } elsif ($arg =~ m/--with-distro=(.*)$/) {
116 my $config = "distro-configs/$1.conf";
117 if (! -f $config) {
118 invalid_distro ($config, $1);
119 } else {
120 push @args, read_args ($config);
122 } else {
123 push @args, $arg;
126 for my $arg (@args) {
127 if ($arg =~ /^([A-Z]+)=(.*)/) {
128 $ENV{$1} = $2;
132 # Alloc $ACLOCAL to specify which aclocal to use
133 $aclocal = $ENV{ACLOCAL} ? $ENV{ACLOCAL} : 'aclocal';
135 my $system = `uname -s`;
136 chomp $system;
138 sanity_checks ($system) unless($system eq 'Darwin');
140 # since this looks crazy, if you have a symlink on a path up to and including
141 # the current directory, we need our configure to run in the realpath of that
142 # such that compiled (realpath'd) dependency filenames match the filenames
143 # used in our makefiles - ie. this gets dependencies right via SRC_ROOT
144 my $cwd_str = realpath(cwd());
145 chdir ($cwd_str);
146 # more amazingly, if you don't clobber 'PWD' shells will re-assert their
147 # old path from the environment, not cwd.
148 $ENV{PWD} = $cwd_str;
150 my $aclocal_flags = $ENV{ACLOCAL_FLAGS};
152 $aclocal_flags .= " -I ./m4";
153 $aclocal_flags .= " -I ./m4/mac" if ($system eq 'Darwin');
155 $ENV{AUTOMAKE_EXTRA_FLAGS} = '--warnings=no-portability' if (!($system eq 'Darwin'));
157 system ("$aclocal $aclocal_flags") && die "Failed to run aclocal";
158 unlink ("configure");
159 system ("autoconf") && die "Failed to run autoconf";
160 die "failed to generate configure" if (! -f "configure");
162 if (defined $ENV{NOCONFIGURE}) {
163 print "Skipping configure process.";
164 } else {
165 # Save autogen.lastrun only if we did get some arguments on the command-line
166 if (@ARGV) {
167 if (scalar(@cmdline_args) > 0) {
168 # if there's already an autogen.lastrun, make a backup first
169 if (-e "autogen.lastrun") {
170 open (my $fh, "autogen.lastrun") || warn "can't open autogen.lastrun. \n";
171 open (BAK, ">autogen.lastrun.bak") || warn "can't create backup file. \n";
172 while (<$fh>) {
173 print BAK;
175 close (BAK) && close ($fh);
177 # print "writing args to autogen.lastrun\n";
178 my $fh;
179 open ($fh, ">autogen.lastrun") || die "can't open autogen.lastrun: $!";
180 for my $arg (@cmdline_args) {
181 print $fh "$arg\n";
183 close ($fh);
186 elsif ( ! -e "autogen.lastrun")
188 open (my $fh, ">autogen.lastrun") || die "can't create autogen.lastrun";
189 close ($fh);
191 print "running ./configure with '" . join ("' '", @args), "'\n";
192 system ("./configure", @args) && die "Error running configure";
195 # Local Variables:
196 # mode: perl
197 # cperl-indent-level: 4
198 # tab-width: 4
199 # indent-tabs-mode: nil
200 # End:
202 # vim:set ft=perl shiftwidth=4 softtabstop=4 expandtab: #