6 use File::Path 'rmtree';
13 $required_tag{"-"} = 1;
17 or die "Can't find current directory: $!";
19 while ($#ARGV ne -1) {
20 my $arg = shift @ARGV;
22 if ($arg =~ /^--required-tag=(.*)/) {
23 $required_tag{$1} = 1;
25 elsif ($arg =~ /^--validate$/) {
33 sub sanity_check_line_endings {
35 open FILE, "packages" or die "Couldn't open file: $!";
40 if ($string =~ /\r/) {
43 Perhaps you need to run
44 git config --global core.autocrlf false
45 and re-check out the tree?
51 sub sanity_check_tree {
55 # Check that we have all boot packages.
56 open PACKAGES, "< packages";
61 elsif (/^([a-zA-Z0-9\/.-]+) +([^ ]+) +[^ ]+ +[^ ]+ +[^ ]+$/) {
65 # If $tag is not "-" then it is an optional repository, so its
66 # absence isn't an error.
67 if (defined($required_tag{$tag})) {
68 # We would like to just check for a .git directory here,
69 # but in an lndir tree we avoid making .git directories,
70 # so it doesn't exist. We therefore require that every repo
71 # has a LICENSE file instead.
72 if (! -f "$dir/LICENSE") {
73 print STDERR "Error: $dir/LICENSE doesn't exist.\n";
74 die "Maybe you haven't done './sync-all get'?";
79 die "Bad line in packages file: $_";
85 # Create libraries/*/{ghc.mk,GNUmakefile}
87 my @library_dirs = ();
88 my @tarballs = glob("libraries/tarballs/*");
94 for $tarball (@tarballs) {
96 $package =~ s#^libraries/tarballs/##;
97 $package =~ s/-[0-9.]*(-snapshot)?\.tar\.gz$//;
99 # Sanity check, so we don't rmtree the wrong thing below
100 if (($package eq "") || ($package =~ m#[/.\\]#)) {
101 die "Bad package name: $package";
104 if (-d "libraries/$package/_darcs") {
105 print "Ignoring libraries/$package as it looks like a darcs checkout\n"
107 elsif (-d "libraries/$package/.git") {
108 print "Ignoring libraries/$package as it looks like a git checkout\n"
111 if (! -d "libraries/stamp") {
112 mkdir "libraries/stamp";
114 $stamp = "libraries/stamp/$package";
115 if ((! -d "libraries/$package") || (! -f "$stamp")
116 || ((-M "libraries/stamp/$package") > (-M $tarball))) {
117 print "Unpacking $package\n";
118 if (-d "libraries/$package") {
119 &rmtree("libraries/$package")
120 or die "Can't remove libraries/$package: $!";
122 mkdir "libraries/$package"
123 or die "Can't create libraries/$package: $!";
124 system ("sh", "-c", "cd 'libraries/$package' && { cat ../../$tarball | gzip -d | tar xf - ; } && mv */* .") == 0
125 or die "Failed to unpack $package";
126 open STAMP, "> $stamp"
127 or die "Failed to open stamp file: $!";
129 or die "Failed to close stamp file: $!";
134 for $package (glob "libraries/*/") {
136 my $pkgs = "$package/ghc-packages";
139 or die "Failed to open $pkgs: $!";
144 push @library_dirs, "$package/$_";
149 push @library_dirs, $package;
153 for $package (@library_dirs) {
154 my $dir = &basename($package);
155 my @cabals = glob("$package/*.cabal");
157 die "Too many .cabal file in $package\n";
160 my $cabal = $cabals[0];
166 $pkg =~ s/\.cabal$//;
168 $top =~ s#[^/]+#..#g;
170 $dir =~ s#^libraries/##g;
172 print "Creating $package/ghc.mk\n";
173 open GHCMK, "> $package/ghc.mk"
174 or die "Opening $package/ghc.mk failed: $!";
175 print GHCMK "${package}_PACKAGE = ${pkg}\n";
176 print GHCMK "${package}_dist-install_GROUP = libraries\n";
177 print GHCMK "\$(eval \$(call build-package,${package},dist-install,\$(if \$(filter ${dir},\$(STAGE2_PACKAGES)),2,1)))\n";
179 or die "Closing $package/ghc.mk failed: $!";
181 print "Creating $package/GNUmakefile\n";
182 open GNUMAKEFILE, "> $package/GNUmakefile"
183 or die "Opening $package/GNUmakefile failed: $!";
184 print GNUMAKEFILE "dir = ${package}\n";
185 print GNUMAKEFILE "TOP = ${top}\n";
186 print GNUMAKEFILE "include \$(TOP)/mk/sub-makefile.mk\n";
187 print GNUMAKEFILE "FAST_MAKE_OPTS += stage=0\n";
189 or die "Closing $package/GNUmakefile failed: $!";
195 # autoreconf everything that needs it.
199 foreach $dir (".", glob("libraries/*/")) {
200 if (-f "$dir/configure.ac") {
201 print "Booting $dir\n";
202 chdir $dir or die "can't change to $dir: $!";
203 system("autoreconf") == 0
204 or die "Running autoreconf failed with exitcode $?";
205 chdir $curdir or die "can't change to $curdir: $!";
211 if ($validate eq 0 && ! -f "mk/build.mk") {
214 WARNING: You don't have a mk/build.mk file.
216 By default a standard GHC build will be done, which uses optimisation
217 and builds the profiling libraries. This will take a long time, so may
218 not be what you want if you are developing GHC or the libraries, rather
219 than simply building it to use it.
221 For information on creating a mk/build.mk file, please see:
222 http://hackage.haskell.org/trac/ghc/wiki/Building/Using#Buildconfiguration
228 &sanity_check_line_endings();
229 &sanity_check_tree();