Pass --enable-shared and --with-hscolour to ghc-cabal configure
[ghc-hetmet.git] / darcs-all
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 # Usage:
6 #
7 # ./darcs-all [-q] [-s] [--nofib] [--testsuite] get [darcs get flags]
8 #   This gets the GHC core repos, if they do not already exist.
9 #   -q says to be quite, and -s to be silent.
10 #   --nofib, --testsuite also get the nofib and testsuite repos respectively
11 #   The darcs get flag you are most likely to want is --complete. By
12 #   default we pass darcs the --partial flag.
13 #
14 # ./darcs-all [-q] [-s] cmd [darcs cmd flags]
15 #   This runs the darcs "cmd" command, with any flags you give, in all
16 #   of the repos you have checked out. e.g.
17 #       ./darcs-all pull
18 #       ./darcs-all -q send --dry-run
19 #   -q says to be quite, and -s to be silent.
20
21 $| = 1; # autoflush stdout after each print, to avoid output after die
22
23 # Figure out where to get the other repositories from,
24 # based on where this GHC repo came from.
25 my $defaultrepo = `cat _darcs/prefs/defaultrepo`;
26 chomp $defaultrepo;
27 my $defaultrepo_base;
28 my $checked_out_tree;
29
30 if ($defaultrepo =~ /^...*:/) {
31     # HTTP or SSH
32     # Above regex says "at least two chars before the :", to avoid
33     # catching Win32 drives ("C:\").
34     $defaultrepo_base = $defaultrepo;
35     $defaultrepo_base =~ s#/[^/]+/?$##;
36     $checked_out_tree = 0;
37 }
38 elsif ($defaultrepo =~ /^\/|\.\.\/|.:(\/|\\)/) {
39     # Local filesystem, either absolute or relative path
40     # (assumes a checked-out tree):
41     $defaultrepo_base = $defaultrepo;
42     $checked_out_tree = 1;
43 }
44 else {
45     die "Couldn't work out defaultrepo";
46 }
47
48 my $verbose = 2;
49 my $ignore_failure = 0;
50
51 my %tags;
52
53 sub message {
54     if ($verbose >= 2) {
55         print "@_\n";
56     }
57 }
58
59 sub warning {
60     if ($verbose >= 1) {
61         print "warning: @_\n";
62     }
63 }
64
65 sub darcs {
66     message "== running darcs @_";
67     system ("darcs", @_) == 0
68         or $ignore_failure
69         or die "darcs failed: $?";
70 }
71
72 sub darcsall {
73     my $localpath;
74     my $path;
75     my $tag;
76     my @repos;
77
78     open IN, "< packages" or die "Can't open packages file";
79     @repos = <IN>;
80     close IN;
81
82     foreach (@repos) {
83         chomp;
84         if (/^([^# ]+) +(?:([^ ]+) +)?([^ ]+) +([^ ]+)$/) {
85             $localpath = $1;
86             $tag = defined($2) ? $2 : "";
87
88             if (-d "$localpath/_darcs") {
89                 darcs (@_, "--repodir", $localpath);
90             }
91             elsif ($tag eq "") {
92                 message "== Required repo $localpath is missing! Skipping";
93             }
94             else {
95                 message "== $localpath repo not present; skipping";
96             }
97         }
98         elsif (! /^(#.*)?$/) {
99             die "Bad line: $_";
100         }
101     }
102 }
103
104 sub darcsget {
105     my $r_flags;
106     my $localpath;
107     my $remotepath;
108     my $path;
109     my $tag;
110     my @repos;
111
112     if (! grep /(?:--complete|--partial)/, @_) {
113         warning("adding --partial, to override use --complete");
114         $r_flags = [@_, "--partial"];
115     }
116     else {
117         $r_flags = \@_;
118     }
119
120     open IN, "< packages" or die "Can't open packages file";
121     @repos = <IN>;
122     close IN;
123
124     foreach (@repos) {
125         chomp;
126         if (/^([^ ]+) +(?:([^ ]+) +)?([^ ]+) +([^ ]+)$/) {
127             $localpath = $1;
128             $tag = defined($2) ? $2 : "";
129             $remotepath = $3;
130
131             if ($checked_out_tree) {
132                 $path = "$defaultrepo_base/$localpath";
133             }
134             else {
135                 if ($remotepath =~ /^http:/) {
136                     $path = $remotepath;
137                 }
138                 else {
139                     $path = "$defaultrepo_base/$remotepath";
140                 }
141             }
142
143             if (($tag eq "") || defined($tags{$tag})) {
144                 if (-d $localpath) {
145                     warning("$localpath already present; omitting");
146                 }
147                 else {
148                     darcs (@$r_flags, $path, $localpath);
149                 }
150             }
151         }
152         elsif (! /^(#.*)?$/) {
153             die "Bad line: $_";
154         }
155     }
156 }
157
158 sub main {
159     if (! -d "_darcs" || ! -d "compiler") {
160         die "error: darcs-all must be run from the top level of the ghc tree."
161     }
162
163     while ($#_ ne -1) {
164         my $arg = shift;
165         # We handle -q here as well as lower down as we need to skip over it
166         # if it comes before the darcs command
167         if ($arg eq "-q") {
168             $verbose = 1;
169         }
170         elsif ($arg eq "-s") {
171             $verbose = 0;
172         }
173         # --nofib tells get to also grab the nofib repo.
174         # It has no effect on the other commands.
175         elsif ($arg eq "--nofib") {
176             $tags{"nofib"} = 1;
177         }
178         # --testsuite tells get to also grab the testsuite repo.
179         # It has no effect on the other commands.
180         elsif ($arg eq "--testsuite") {
181             $tags{"testsuite"} = 1;
182         }
183         else {
184             unshift @_, $arg;
185             if (grep /^-q$/, @_) {
186                 $verbose = 1;
187             }
188             last;
189         }
190     }
191
192     if ($#_ eq -1) {
193         die "What do you want to do?";
194     }
195     my $command = $_[0];
196     if ($command eq "get") {
197         darcsget @_;
198     }
199     else {
200         if ($command =~ /^(?:w|wh|wha|what|whats|whatsn|whatsne|whatsnew)$/) {
201             # Hack around whatsnew failing if there are no changes
202             $ignore_failure = 1;
203         }
204         darcsall @_;
205     }
206 }
207
208 main(@ARGV);
209