Add more error checking to the boot script
[ghc-hetmet.git] / boot
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use Cwd;
6
7 # Create libraries/*/{ghc.mk,GNUmakefile}
8 system("/usr/bin/perl", "-w", "boot-pkgs") == 0
9     or die "Running boot-pkgs failed: $?";
10
11 my $dir;
12 my $curdir;
13
14 $curdir = &cwd()
15     or die "Can't find current directory: $!";
16
17 # Check that we have all boot packages.
18 open PACKAGES, "< packages";
19 while (<PACKAGES>) {
20     if (/^#/) {
21         # Comment; do nothing
22     }
23     elsif (/^([a-zA-Z0-9\/.-]+) *[^ ]+ *[^ ]+$/) {
24         $dir = $1;
25         
26         # We would like to just check for an _darcs directory here, but in
27         # an lndir tree we avoid making _darcs directories, so it doesn't
28         # exist. We therefore require that every repo has a LICENSE file
29         # instead.
30         if (! -f "$dir/LICENSE") {
31             print STDERR "Error: $dir/LICENSE doesn't exist.\n";
32             die "Maybe you haven't done './darcs-all get'?";
33         }
34     }
35     elsif (/^([a-zA-Z0-9\/.-]+) *[^ ]+ *[^ ]+ *[^ ]+$/) {
36         # These are lines which refer to optional repositories, so their
37         # absence isn't an error.
38     }
39     else {
40         die "Bad line in packages file: $_";
41     }
42 }
43 close PACKAGES;
44
45 # autoreconf everything that needs it.
46 foreach $dir (".", glob("libraries/*/")) {
47     if (-f "$dir/configure.ac") {
48         print "Booting $dir\n";
49         chdir $dir or die "can't change to $dir: $!";
50         system("autoreconf") == 0
51             or die "Running autoreconf failed with exitcode $?";
52         chdir $curdir or die "can't change to $curdir: $!";
53     }
54 }
55
56 # Alas, darcs doesn't handle file permissions, so fix a few of them.
57 for my $file ("boot", "darcs-all", "push-all", "validate") {
58     chmod 0755, $file if -f $file
59         or die "Can't chmod 0755 $file: $!";
60 }