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