1# ----------------------------------------------------------------------------- 2# 3# (c) 2009 The University of Glasgow 4# 5# This file is part of the GHC build system. 6# 7# To understand how the build system works and how to modify it, see 8# https://gitlab.haskell.org/ghc/ghc/wikis/building/architecture 9# https://gitlab.haskell.org/ghc/ghc/wikis/building/modifying 10# 11# ----------------------------------------------------------------------------- 12 13 14# Build a package with the stage-1 compiler, multiple ways. A typical 15# libraries/foo/ghc.mk will look like this: 16# 17# $(eval $(call build-package,libraries/base,dist-install)) 18# 19# The package metadata is generated from the .cabal file and placed in 20# package-data.mk. It will look something like this: 21# 22# libraries/base_dist_MODULES = GHC.Base Data.Tuple ... 23# libraries/base_dist_PACKAGE = base 24# libraries/base_dist_VERSION = 4.0.0.0 25# libraries/base_dist_HC_OPTS = -package ghc-prim-0.1.0.0 -XRank2Types ... 26# libraries/base_dist_C_SRCS = cbits/PrelIOUtils.c ... 27# libraries/base_dist_S_SRCS = cbits/foo.S ... 28# libraries/base_dist_CC_OPTS = -Iinclude ... 29# libraries/base_dist_LD_OPTS = -package ghc-prim-0.1.0.0 30 31define build-package 32$(call trace, build-package($1,$2,$3)) 33$(call profStart, build-package($1,$2,$3)) 34# $1 = dir 35# $2 = distdir 36# $3 = GHC stage to use (0 == bootstrapping compiler) 37 38ifeq "$$(findstring $3,0 1 2)" "" 39$$(error $1/$2: stage argument to build-package should be 0, 1, or 2) 40endif 41 42$(call clean-target,$1,$2,$1/$2) 43 44distclean : clean_$1_$2_config 45 46.PHONY: clean_$1_$2_config 47clean_$1_$2_config: 48 $$(call removeFiles,$1/config.log $1/config.status $(wildcard $1/include/Hs*Config.h)) 49 $$(call removeTrees,$1/autom4te.cache) 50 51ifneq "$$($1_$2_NOT_NEEDED)" "YES" 52$$(eval $$(call build-package-helper,$1,$2,$3)) 53endif 54$(call profEnd, build-package($1,$2,$3)) 55endef 56 57 58define build-package-helper 59# $1 = dir 60# $2 = distdir 61# $3 = GHC stage to use (0 == bootstrapping compiler) 62 63# --- CONFIGURATION 64 65$(call package-config,$1,$2,$3) 66 67ifeq "$3" "1" 68$$($1_PACKAGE)_INSTALL_INFO = $1_$2 69endif 70 71# Bootstrapping libs are only built one way 72ifeq "$3" "0" 73$1_$2_WAYS = v 74else 75$1_$2_WAYS = $$(filter-out $$($1_$2_EXCLUDED_WAYS),$$(GhcLibWays)) 76endif 77 78$1_$2_DYNAMIC_TOO = NO 79ifneq "$$(DYNAMIC_TOO)" "NO" 80ifneq "$$(filter v,$$($1_$2_WAYS))" "" 81ifneq "$$(filter dyn,$$($1_$2_WAYS))" "" 82$1_$2_DYNAMIC_TOO = YES 83endif 84endif 85endif 86 87# We must use a different dependency file if $(GhcLibWays) changes, so 88# encode the ways into the name of the file. 89$1_$2_WAYS_DASHED = $$(subst $$(space),,$$(patsubst %,-%,$$(strip $$($1_$2_WAYS)))) 90$1_$2_depfile_base = $1/$2/build/.depend$$($1_$2_WAYS_DASHED) 91 92$(call build-package-data,$1,$2,$3) 93ifneq "$$(NO_INCLUDE_PKGDATA)" "YES" 94ifeq "$3" "0" 95include $1/$2/package-data.mk 96else ifeq "$(phase)" "final" 97include $1/$2/package-data.mk 98endif 99# Each Haskell compilation in this package will depend on the 100# package-data.mk file because e.g. if the version of the package 101# changes we need to recompile everything in it. 102$1_$2_PKGDATA_DEP = $1/$2/package-data.mk 103endif 104 105$(call hs-sources,$1,$2) 106$(call c-sources,$1,$2) 107$(call includes-sources,$1,$2) 108$(call distdir-opts,$1,$2,$3) 109 110$(call dependencies,$1,$2,$3) 111 112# Now generate all the build rules for each way in this directory: 113$$(foreach way,$$($1_$2_WAYS),$$(eval \ 114 $$(call c-objs,$1,$2,$$(way)) \ 115 $$(call c-suffix-rules,$1,$2,$$(way),YES) \ 116 $$(call cmm-objs,$1,$2,$$(way)) \ 117 $$(call cmm-suffix-rules,$1,$2,$$(way)) \ 118 $$(call build-package-way,$1,$2,$$(way),$3) \ 119 )) 120 121# Programs will need to depend on either the vanilla lib (if -static 122# is the default) or the dyn lib (if -dynamic is the default). We 123# conservatively make them depend on both, to keep things simple. 124# If dyn libs are not being built then $$($1_$2_dyn_LIB) will just 125# expand to the empty string, and be ignored. 126$1_$2_PROGRAM_DEP_LIB = $$($1_$2_v_LIB) $$($1_$2_dyn_LIB) 127$$($1_$2_COMPONENT_ID)_$2_PROGRAM_DEP_LIB = $$($1_$2_PROGRAM_DEP_LIB) 128 129# See Note [inconsistent distdirs] in rules/build-package-way.mk. 130ifeq "$$($1_PACKAGE) $2" "ghc stage1" 131$$($1_$2_COMPONENT_ID)_dist-boot_PROGRAM_DEP_LIB = $$($1_$2_PROGRAM_DEP_LIB) 132endif 133ifeq "$$($1_PACKAGE) $2" "ghc stage2" 134$$($1_$2_COMPONENT_ID)_dist-install_PROGRAM_DEP_LIB = $$($1_$2_PROGRAM_DEP_LIB) 135endif 136 137# C and S files are possibly built the "dyn" way. 138ifeq "$$(BuildSharedLibs)" "YES" 139$(call c-objs,$1,$2,dyn) 140$(call c-suffix-rules,$1,$2,dyn,YES) 141endif 142$$(foreach dir,$$($1_$2_HS_SRC_DIRS),\ 143 $$(eval $$(call hs-suffix-rules-srcdir,$1,$2,$$(dir)))) 144 145$(call all-target,$1,all_$1_$2) 146# This give us things like 147# all_libraries: all_libraries/base_dist-install 148ifneq "$$($1_$2_GROUP)" "" 149all_$$($1_$2_GROUP): all_$1_$2 150endif 151 152ifneq "$3" "0" 153$(call haddock,$1,$2) 154endif 155 156# Don't put bootstrapping packages in the bindist 157ifneq "$3" "0" 158BINDIST_EXTRAS += $1/*.cabal $$(wildcard $1/*.buildinfo) $$(wildcard $1/dist-install/build/*.buildinfo) $1/$2/setup-config $1/LICENSE 159BINDIST_EXTRAS += $$($1_$2_INSTALL_INCLUDES_SRCS) 160endif 161 162endef 163 164