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 = ();
91 for $package (glob "libraries/*/") {
93 my $pkgs = "$package/ghc-packages";
96 or die "Failed to open $pkgs: $!";
101 push @library_dirs, "$package/$_";
106 push @library_dirs, $package;
110 for $package (@library_dirs) {
111 my $dir = &basename($package);
112 my @cabals = glob("$package/*.cabal");
114 die "Too many .cabal file in $package\n";
117 my $cabal = $cabals[0];
123 $pkg =~ s/\.cabal$//;
125 $top =~ s#[^/]+#..#g;
127 $dir =~ s#^libraries/##g;
129 print "Creating $package/ghc.mk\n";
130 open GHCMK, "> $package/ghc.mk"
131 or die "Opening $package/ghc.mk failed: $!";
132 print GHCMK "${package}_PACKAGE = ${pkg}\n";
133 print GHCMK "${package}_dist-install_GROUP = libraries\n";
134 print GHCMK "\$(if \$(filter ${dir},\$(PACKAGES_STAGE0)),\$(eval \$(call build-package,${package},dist-boot,0)))\n";
135 print GHCMK "\$(if \$(filter ${dir},\$(PACKAGES_STAGE1)),\$(eval \$(call build-package,${package},dist-install,1)))\n";
136 print GHCMK "\$(if \$(filter ${dir},\$(PACKAGES_STAGE2)),\$(eval \$(call build-package,${package},dist-install,2)))\n";
138 or die "Closing $package/ghc.mk failed: $!";
140 print "Creating $package/GNUmakefile\n";
141 open GNUMAKEFILE, "> $package/GNUmakefile"
142 or die "Opening $package/GNUmakefile failed: $!";
143 print GNUMAKEFILE "dir = ${package}\n";
144 print GNUMAKEFILE "TOP = ${top}\n";
145 print GNUMAKEFILE "include \$(TOP)/mk/sub-makefile.mk\n";
146 print GNUMAKEFILE "FAST_MAKE_OPTS += stage=0\n";
148 or die "Closing $package/GNUmakefile failed: $!";
154 # autoreconf everything that needs it.
158 foreach $dir (".", glob("libraries/*/")) {
159 if (-f "$dir/configure.ac") {
160 print "Booting $dir\n";
161 chdir $dir or die "can't change to $dir: $!";
162 system("autoreconf") == 0
163 or die "Running autoreconf failed with exitcode $?";
164 chdir $curdir or die "can't change to $curdir: $!";
170 if ($validate eq 0 && ! -f "mk/build.mk") {
173 WARNING: You don't have a mk/build.mk file.
175 By default a standard GHC build will be done, which uses optimisation
176 and builds the profiling libraries. This will take a long time, so may
177 not be what you want if you are developing GHC or the libraries, rather
178 than simply building it to use it.
180 For information on creating a mk/build.mk file, please see:
181 http://ghc.haskell.org/trac/ghc/wiki/Building/Using#Buildconfiguration
187 &sanity_check_line_endings();
188 &sanity_check_tree();