5 use File::Path 'rmtree';
9 my @tarballs = glob("libraries/tarballs/*");
15 for $tarball (@tarballs) {
17 $package =~ s#^libraries/tarballs/##;
18 $package =~ s/-[0-9.]*(-snapshot)?\.tar\.gz$//;
20 # Sanity check, so we don't rmtree the wrong thing below
21 if (($package eq "") || ($package =~ m#[/.\\]#)) {
22 die "Bad package name: $package";
25 if (-d "libraries/$package/_darcs") {
26 print "Ignoring libraries/$package as it looks like a darcs checkout\n"
28 elsif (-d "libraries/$package/.git") {
29 print "Ignoring libraries/$package as it looks like a git checkout\n"
32 if (! -d "libraries/stamp") {
33 mkdir "libraries/stamp";
35 $stamp = "libraries/stamp/$package";
36 if ((! -d "libraries/$package") || (! -f "$stamp")
37 || ((-M "libraries/stamp/$package") > (-M $tarball))) {
38 print "Unpacking $package\n";
39 if (-d "libraries/$package") {
40 &rmtree("libraries/$package")
41 or die "Can't remove libraries/$package: $!";
43 mkdir "libraries/$package"
44 or die "Can't create libraries/$package: $!";
45 system ("sh", "-c", "cd 'libraries/$package' && { cat ../../$tarball | gzip -d | tar xf - ; } && mv */* .") == 0
46 or die "Failed to unpack $package";
47 open STAMP, "> $stamp"
48 or die "Failed to open stamp file: $!";
50 or die "Failed to close stamp file: $!";
55 for $package (glob "libraries/*/") {
57 my $pkgs = "$package/ghc-packages";
60 or die "Failed to open $pkgs: $!";
65 push @library_dirs, "$package/$_";
70 push @library_dirs, $package;
74 for $package (@library_dirs) {
75 my $dir = &basename($package);
76 my @cabals = glob("$package/*.cabal");
78 die "Too many .cabal file in $package\n";
81 my $cabal = $cabals[0];
91 $dir =~ s#^libraries/##g;
93 print "Creating $package/ghc.mk\n";
94 open GHCMK, "> $package/ghc.mk"
95 or die "Opening $package/ghc.mk failed: $!";
96 print GHCMK "${package}_PACKAGE = ${pkg}\n";
97 print GHCMK "${package}_dist-install_GROUP = libraries\n";
98 print GHCMK "\$(eval \$(call build-package,${package},dist-install,\$(if \$(filter ${dir},\$(STAGE2_PACKAGES)),2,1)))\n";
100 or die "Closing $package/ghc.mk failed: $!";
102 print "Creating $package/GNUmakefile\n";
103 open GNUMAKEFILE, "> $package/GNUmakefile"
104 or die "Opening $package/GNUmakefile failed: $!";
105 print GNUMAKEFILE "dir = ${package}\n";
106 print GNUMAKEFILE "TOP = ${top}\n";
107 print GNUMAKEFILE "include \$(TOP)/mk/sub-makefile.mk\n";
108 print GNUMAKEFILE "FAST_MAKE_OPTS += stage=0\n";
110 or die "Closing $package/GNUmakefile failed: $!";