From 1c1ed8694bdd24b003fa5935d001a1835e9b0f4e Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Thu, 23 Sep 2010 09:56:42 +0000 Subject: [PATCH] Refactoring and tidy up in the build system Instead of the ghc-stage and ghc-stage2-package files in a package, we now have a list of these in ghc.mk. There are other similar lists (of boot-packages and non-installable packages), so this is not too bad, and is simpler. While poking around in the top-level ghc.mk file I spotted various opportunities to clean up and re-order some of the cruft that has accumulated over time. --- boot-pkgs | 15 +--- ghc.mk | 229 ++++++++++++++++++++++++----------------------- mk/validate-settings.mk | 4 + rules/build-package.mk | 2 - rules/extra-packages.mk | 4 - 5 files changed, 125 insertions(+), 129 deletions(-) diff --git a/boot-pkgs b/boot-pkgs index 677ae52..4552088 100644 --- a/boot-pkgs +++ b/boot-pkgs @@ -73,31 +73,22 @@ for $package (@library_dirs) { if ($#cabals eq 0) { my $cabal = $cabals[0]; my $pkg; - my $stage; my $top; if (-f $cabal) { $pkg = $cabal; $pkg =~ s#.*/##; $pkg =~ s/\.cabal$//; - if (-f "$package/ghc-stage") { - open STAGE, "< $package/ghc-stage" - or die "Can't open $package/ghc-stage: $!"; - $stage = int(); - close STAGE - or die "Failed closing $package/ghc-stage: $!"; - } - else { - $stage = 1; - } $top = $package; $top =~ s#[^/]+#..#g; + $dir = $package; + $dir =~ s#^libraries/##g; print "Creating $package/ghc.mk\n"; open GHCMK, "> $package/ghc.mk" or die "Opening $package/ghc.mk failed: $!"; print GHCMK "${package}_PACKAGE = ${pkg}\n"; print GHCMK "${package}_dist-install_GROUP = libraries\n"; - print GHCMK "\$(eval \$(call build-package,${package},dist-install,${stage}))\n"; + print GHCMK "\$(eval \$(call build-package,${package},dist-install,\$(if \$(filter ${dir},\$(STAGE2_PACKAGES)),2,1)))\n"; close GHCMK or die "Closing $package/ghc.mk failed: $!"; diff --git a/ghc.mk b/ghc.mk index 1a45caa..56ab990 100644 --- a/ghc.mk +++ b/ghc.mk @@ -12,12 +12,6 @@ # ToDo List. # -# * finish installation -# * Windows: should we have ghc-pkg-? -# * should we be stripping things? -# * install libgmp.a, gmp.h -# * need to fix Cabal for new Windows layout, see -# Distribution/Simple/GHC.configureToolchain. # * remove old Makefiles, add new stubs for building in subdirs # * docs/Makefile # * docs/docbook-cheat-sheet/Makefile @@ -27,13 +21,8 @@ # * docs/vh/Makefile # * rts/dotnet/Makefile # * utils/Makefile -# * optionally install stage3? # * add Makefiles for the rest of the utils/ programs that aren't built # by default (need to exclude them from 'make all' too) -# -# Tickets we can now close, or fix and close: -# -# * 1693 make distclean # Possible cleanups: # @@ -43,7 +32,7 @@ # then we don't have to use -osuf/-hisuf. We would have to install # them in different places too, so we'd need ghc-pkg support for packages # of different ways. -# * make PACKAGES generated by './configure' or 'perl boot'? +# * make PACKAGES generated by './configure' or './boot'? # * we should use a directory of package.conf files rather than a single # file for the inplace package database, so that we can express # dependencies more accurately. Otherwise it's possible to get into @@ -119,7 +108,8 @@ comma=, .SUFFIXES: # ----------------------------------------------------------------------------- -# Makefile debugging +# Makefile debugging +# # to see the effective value used for a Makefile variable, do # make show VALUE=MY_VALUE # @@ -186,14 +176,6 @@ NO_INCLUDE_DEPS = YES # We want package-data.mk for show endif -# We don't haddock the bootstrapping libraries -libraries/hpc_dist-boot_DO_HADDOCK = NO -libraries/Cabal_dist-boot_DO_HADDOCK = NO -libraries/extensible-exceptions_dist-boot_DO_HADDOCK = NO -libraries/filepath_dist-boot_DO_HADDOCK = NO -libraries/binary_dist-boot_DO_HADDOCK = NO -libraries/bin-package-db_dist-boot_DO_HADDOCK = NO - # ----------------------------------------------------------------------------- # Ways @@ -226,26 +208,15 @@ ifneq "$(CLEANING)" "YES" include rules/hs-suffix-rules-srcdir.mk include rules/hs-suffix-rules.mk - -# ----------------------------------------------------------------------------- -# Suffix rules for .hi files - include rules/hi-rule.mk $(foreach way,$(ALL_WAYS),\ $(eval $(call hi-rule,$(way)))) -#----------------------------------------------------------------------------- -# C-related suffix rules - include rules/c-suffix-rules.mk - -#----------------------------------------------------------------------------- -# CMM-related suffix rules - include rules/cmm-suffix-rules.mk -endif +endif # CLEANING=YES # ----------------------------------------------------------------------------- # Building package-data.mk files from .cabal files @@ -298,7 +269,52 @@ include rules/docbook.mk include rules/bindist.mk # ----------------------------------------------------------------------------- -# Building libraries +# Directories + +# Don't try to delete directories: +.PRECIOUS: %/. + +# Create build directories on demand. NB. the | below: this indicates +# that $(MKDIRHIER) is an order-only dependency, which means that this +# rule fires after building mkdirhier, but we won't try to recreate +# directories if mkdirhier changes. +%/. : | $(MKDIRHIER) + "$(MKDIRHIER)" $@ + +# ----------------------------------------------------------------------------- +# Packages + +# -------------------------------- +# Subsets of packages + +# Packages that are built but not installed +INTREE_ONLY_PACKAGES := haskeline mtl terminfo utf8-string xhtml + +# Packages that, if present, must be built by the stage2 compiler, +# because they use TH and/or annotations, or depend on other stage2 +# packages. +STAGE2_PACKAGES := dph/dph-base dph/dph-prim-interface dph/dph-prim-seq \ + dph/dph-common dph/dph-prim-par dph/dph-par dph/dph-seq + +# Packages that are built by stage0, in addition to stage1. These +# packages are dependencies of GHC, that we do not assume the stage0 +# compiler already has installed (or up-to-date enough). +# +# We assume that the stage0 compiler has a suitable bytestring package, +# so we don't have to include it below. +STAGE0_PACKAGES = Cabal hpc extensible-exceptions binary bin-package-db + +# -------------------------------- +# Building the lists of packages + +# We need to build two lists: +# +# $(PACKAGES) A list of directories relative to libraries/ containing +# packages that will be built by stage1, in dependency +# order. +# +# $(PACKAGES_STAGE2) Ditto, for stage2. +# define addPackageGeneral # args: $1 = PACKAGES variable, $2 = package, $3 = condition @@ -316,17 +332,13 @@ define addPackageGeneral endef define addPackage # args: $1 = package, $2 = condition -$(call addPackageGeneral,PACKAGES,$1,$2) -endef - -define addPackage2 # args: $1 = package, $2 = condition +ifeq "$(filter $1,$(STAGE2_PACKAGES))" "$1" $(call addPackageGeneral,PACKAGES_STAGE2,$1,$2) +else +$(call addPackageGeneral,PACKAGES,$1,$2) +endif endef -INTREE_ONLY_PACKAGES := haskeline mtl terminfo utf8-string xhtml - -$(foreach p,$(INTREE_ONLY_PACKAGES),$(eval libraries/$p_dist-install_HADDOCK_ME = NO)) - $(eval $(call addPackage,ghc-prim)) ifeq "$(CLEANING)" "YES" $(eval $(call addPackage,integer-gmp)) @@ -368,26 +380,8 @@ $(eval $(call addPackage,haskeline)) $(eval $(call extra-packages)) -# ------------------------------------------------------- - - -# We assume that the stage0 compiler has a suitable bytestring package, -# so we don't have to include it below. -BOOT_PKGS = Cabal hpc extensible-exceptions binary bin-package-db - -BOOT_PKG_CONSTRAINTS := $(foreach p,$(BOOT_PKGS),--constraint "$p == $(shell grep -i "^Version:" libraries/$p/$p.cabal | sed "s/[^0-9.]//g")") - -# The actual .a and .so/.dll files: needed for dependencies. -ALL_STAGE1_LIBS = $(foreach lib,$(PACKAGES),$(libraries/$(lib)_dist-install_v_LIB)) -ifeq "$(BuildSharedLibs)" "YES" -ALL_STAGE1_LIBS += $(foreach lib,$(PACKAGES),$(libraries/$(lib)_dist-install_dyn_LIB)) -endif -BOOT_LIBS = $(foreach lib,$(BOOT_PKGS),$(libraries/$(lib)_dist-boot_v_LIB)) - -OTHER_LIBS = libffi/dist-install/build/libHSffi$(v_libsuf) libffi/dist-install/build/HSffi.o -ifeq "$(BuildSharedLibs)" "YES" -OTHER_LIBS += libffi/dist-install/build/libHSffi$(dyn_libsuf) -endif +# ------------------------------------------- +# Dependencies between package-data.mk files # We cannot run ghc-cabal to configure a package until we have # configured and registered all of its dependencies. So the following @@ -431,20 +425,27 @@ libraries/ghc-prim/dist-install/package-data.mk : rts/package.conf.inplace rts/package.conf.inplace : libffi/package.conf.inplace endif -# ----------------------------------------------------------------------------- -# Directories +# -------------------------------- +# Misc package-related settings -# Don't try to delete directories: -.PRECIOUS: %/. +BOOT_PKG_CONSTRAINTS := $(foreach p,$(STAGE0_PACKAGES),--constraint "$p == $(shell grep -i "^Version:" libraries/$p/$p.cabal | sed "s/[^0-9.]//g")") -# Create build directories on demand. NB. the | below: this indicates -# that $(MKDIRHIER) is an order-only dependency, which means that this -# rule fires after building mkdirhier, but we won't try to recreate -# directories if mkdirhier changes. -%/. : | $(MKDIRHIER) - "$(MKDIRHIER)" $@ +# The actual .a and .so/.dll files: needed for dependencies. +ALL_STAGE1_LIBS = $(foreach lib,$(PACKAGES),$(libraries/$(lib)_dist-install_v_LIB)) +ifeq "$(BuildSharedLibs)" "YES" +ALL_STAGE1_LIBS += $(foreach lib,$(PACKAGES),$(libraries/$(lib)_dist-install_dyn_LIB)) +endif +BOOT_LIBS = $(foreach lib,$(STAGE0_PACKAGES),$(libraries/$(lib)_dist-boot_v_LIB)) +# A useful pseudo-target +.PHONY: stage1_libs +stage1_libs : $(ALL_STAGE1_LIBS) -# ----------------------------------------------------------------------------- +OTHER_LIBS = libffi/dist-install/build/libHSffi$(v_libsuf) libffi/dist-install/build/HSffi.o +ifeq "$(BuildSharedLibs)" "YES" +OTHER_LIBS += libffi/dist-install/build/libHSffi$(dyn_libsuf) +endif + +# ---------------------------------------- # Special magic for the ghc-prim package # We want the ghc-prim package to include the GHC.Prim module when it @@ -470,6 +471,21 @@ libraries/ghc-prim/dist-install/build/GHC/PrimopWrappers.hs : $(GENPRIMOP_INPLAC # Required so that Haddock documents the primops. libraries/ghc-prim_dist-install_EXTRA_HADDOCK_SRCS = libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs +# ---------------------------------------- +# Special magic for the integer package + +ifneq "$(CLEANING)" "YES" +ifeq "$(INTEGER_LIBRARY)" "integer-gmp" +libraries/base_dist-install_CONFIGURE_OPTS += --flags=-integer-simple +else + ifeq "$(INTEGER_LIBRARY)" "integer-simple" + libraries/base_dist-install_CONFIGURE_OPTS += --flags=integer-simple + else +$(error Unknown integer library: $(INTEGER_LIBRARY)) + endif +endif +endif + # ----------------------------------------------------------------------------- # Include build instructions from all subdirs @@ -592,7 +608,7 @@ endif # Note [lib-depends]. ifeq "$(phase)" "0" -$(foreach lib,$(BOOT_PKGS),$(eval \ +$(foreach lib,$(STAGE0_PACKAGES),$(eval \ libraries/$(lib)_dist-boot_DISABLE = YES)) endif @@ -623,32 +639,8 @@ $(foreach lib,$(PACKAGES) $(PACKAGES_STAGE2),$(eval \ libraries/$(lib)_dist-install_DISABLE = YES)) endif -ifneq "$(CLEANING)" "YES" -ifeq "$(INTEGER_LIBRARY)" "integer-gmp" -libraries/base_dist-install_CONFIGURE_OPTS += --flags=-integer-simple -else - ifeq "$(INTEGER_LIBRARY)" "integer-simple" - libraries/base_dist-install_CONFIGURE_OPTS += --flags=integer-simple - else -$(error Unknown integer library: $(INTEGER_LIBRARY)) - endif -endif -endif - -# These packages don't pass the Cabal checks because hs-source-dirs -# points outside the source directory. This isn't a real problem in -# these cases, so we just skip checking them. -CHECKED_libraries/dph/dph-seq = YES -CHECKED_libraries/dph/dph-par = YES -# In compiler's case, include-dirs points outside of the source tree -CHECKED_compiler = YES - include $(patsubst %, %/ghc.mk, $(BUILD_DIRS)) -# We need -fno-warn-deprecated-flags to avoid failure with -Werror -GhcLibHcOpts += -fno-warn-deprecated-flags -GhcBootLibHcOpts += -fno-warn-deprecated-flags - # ---------------------------------------------- # Per-package compiler flags # @@ -658,15 +650,36 @@ GhcBootLibHcOpts += -fno-warn-deprecated-flags # libraries/_dist-boot_HC_OPTS += -Wwarn # libraries/_dist-install_HC_OPTS += -Wwarn - -# Add $(GhcLibHcOpts) to all library builds +# Add $(GhcLibHcOpts) to all package builds $(foreach pkg,$(PACKAGES) $(PACKAGES_STAGE2),$(eval libraries/$(pkg)_dist-install_HC_OPTS += $$(GhcLibHcOpts))) +# Add $(GhcBootLibHcOpts) to all stage0 package builds +$(foreach pkg,$(STAGE0_PACKAGES),$(eval libraries/$(pkg)_dist-boot_HC_OPTS += $$(GhcBootLibHcOpts))) + # ---------------------------------------------- -# A useful pseudo-target -.PHONY: stage1_libs -stage1_libs : $(ALL_STAGE1_LIBS) +# Checking packages with 'cabal check' + +ifeq "$(CHECK_PACKAGES)" "YES" +all: check_packages +endif + +# These packages don't pass the Cabal checks because hs-source-dirs +# points outside the source directory. This isn't a real problem in +# these cases, so we just skip checking them. +CHECKED_libraries/dph/dph-seq = YES +CHECKED_libraries/dph/dph-par = YES +# In compiler's case, include-dirs points outside of the source tree +CHECKED_compiler = YES + +# ----------------------------------------------- +# Haddock-related bits +# Don't run Haddock for the package that will not be installed +$(foreach p,$(INTREE_ONLY_PACKAGES),$(eval libraries/$p_dist-install_DO_HADDOCK = NO)) +# We don't haddock the bootstrapping libraries +$(foreach p,$(STAGE0_PACKAGES),$(eval libraries/$p_dist-boot_DO_HADDOCK = NO)) + +# Build the Haddock contents and index ifeq "$(HADDOCK_DOCS)" "YES" libraries/index.html: $(ALL_HADDOCK_FILES) cd libraries && sh gen_contents_index --inplace @@ -676,10 +689,6 @@ CLEAN_FILES += libraries/doc-index* libraries/haddock*.css \ libraries/haddock*.js libraries/index*.html libraries/*.gif endif -ifeq "$(CHECK_PACKAGES)" "YES" -all: check_packages -endif - # ----------------------------------------------------------------------------- # Bootstrapping libraries @@ -709,7 +718,7 @@ $(eval $(call build-package,libraries/bin-package-db,dist-boot,0)) # multiple ghc-pkgs in parallel doesn't work (registrations may get # lost). fixed_pkg_prev= -$(foreach pkg,$(BOOT_PKGS),$(eval $(call fixed_pkg_dep,$(pkg),dist-boot))) +$(foreach pkg,$(STAGE0_PACKAGES),$(eval $(call fixed_pkg_dep,$(pkg),dist-boot))) compiler/stage1/package-data.mk : \ libraries/Cabal/dist-boot/package-data.mk \ @@ -731,8 +740,6 @@ $(ghc_stage1_depfile_haskell) : $(compiler_stage1_v_LIB) # libraries/bin-package-db/dist-boot/build/Distribution/InstalledPackageInfo/Binary.$(v_osuf) : libraries/binary/dist-boot/build/Data/Binary.$(v_hisuf) libraries/Cabal/dist-boot/build/Distribution/InstalledPackageInfo.$(v_hisuf) -$(foreach pkg,$(BOOT_PKGS),$(eval libraries/$(pkg)_dist-boot_HC_OPTS += $$(GhcBootLibHcOpts))) - # Make sure we have all the GHCi libs by the time we've built # ghc-stage2. DPH includes a bit of Template Haskell which needs the # GHCI libs, and we don't have a better way to express that dependency. @@ -1189,7 +1196,7 @@ endif .PHONY: clean_libraries clean_libraries: $(patsubst %,clean_libraries/%_dist-install,$(PACKAGES) $(PACKAGES_STAGE2)) -clean_libraries: $(patsubst %,clean_libraries/%_dist-boot,$(BOOT_PKGS)) +clean_libraries: $(patsubst %,clean_libraries/%_dist-boot,$(STAGE0_PACKAGES)) clean_libraries: "$(RM)" $(RM_OPTS_REC) $(patsubst %, libraries/%/dist, $(PACKAGES) $(PACKAGES_STAGE2)) diff --git a/mk/validate-settings.mk b/mk/validate-settings.mk index 48da7fa..8038501 100644 --- a/mk/validate-settings.mk +++ b/mk/validate-settings.mk @@ -60,3 +60,7 @@ libraries/dph/dph-prim-par_dist-install_EXTRA_HC_OPTS += -Wwarn libraries/dph/dph-seq_dist-install_EXTRA_HC_OPTS += -Wwarn libraries/dph/dph-par_dist-install_EXTRA_HC_OPTS += -Wwarn +# We need -fno-warn-deprecated-flags to avoid failure with -Werror +GhcLibHcOpts += -fno-warn-deprecated-flags +GhcBootLibHcOpts += -fno-warn-deprecated-flags + diff --git a/rules/build-package.mk b/rules/build-package.mk index fc3d0f7..7ce11fe 100644 --- a/rules/build-package.mk +++ b/rules/build-package.mk @@ -162,9 +162,7 @@ $$(foreach way,$$($1_$2_WAYS),$$(eval \ $$(call build-package-way,$1,$2,$$(way),$3) \ )) -ifneq "$$($1_$2_HADDOCK_ME)" "NO" $(call haddock,$1,$2) -endif endif # package-data.mk exists diff --git a/rules/extra-packages.mk b/rules/extra-packages.mk index 7218a6f..271bc6d 100644 --- a/rules/extra-packages.mk +++ b/rules/extra-packages.mk @@ -39,10 +39,6 @@ define extra-package # $1 = package root, $2 = package $(call trace, extra-package($1,$2)) EXTRA_PACKAGES += $2 -ifeq "$(wildcard libraries/$1/ghc-stage2-package)" "" $$(eval $$(call addPackage,$2)) -else -$$(eval $$(call addPackage2,$2)) -endif endef -- 1.7.10.4