gitlab-ci: Update bootstrap compiled used for Darwin builds
[ghc.git] / rules / build-package-way.mk
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 define build-package-way # $1 = dir, $2 = distdir, $3 = way, $4 = stage
15 $(call trace, build-package-way($1,$2,$3))
16 $(call profStart, build-package-way($1,$2,$3))
17
18 $(call distdir-way-opts,$1,$2,$3,$4)
19 $(call hs-suffix-way-rules,$1,$2,$3)
20
21 $(call hs-objs,$1,$2,$3)
22
23 # The .a/.so library file, indexed by two different sets of vars:
24 # the first is indexed by the dir, distdir and way
25 # the second is indexed by the package id, distdir and way
26 $1_$2_$3_LIB_FILE = libHS$$($1_$2_COMPONENT_ID)$(subst .,%,$$($3_libsuf))
27 $1_$2_$3_LIB = $1/$2/build/$$($1_$2_$3_LIB_FILE)
28 $$($1_$2_COMPONENT_ID)_$2_$3_LIB = $$($1_$2_$3_LIB)
29
30 # Note [inconsistent distdirs]
31 #
32 # hack: the DEPS_LIBS mechanism assumes that the distdirs for packages
33 # that depend on each other are the same, but that is not the case for
34 # ghc where we use stage1/stage2 rather than dist/dist-install.
35 # Really we should use a consistent scheme for distdirs, but in the
36 # meantime we work around it by defining ghc-<ver>_dist-install_way_LIB:
37 #
38 # A similar hack is applied to the PROGRAM_DEP_LIB mechanism in
39 # rules/build-package.mk.
40 ifeq "$$($1_PACKAGE) $2" "ghc stage2"
41 $$($1_$2_COMPONENT_ID)_dist-install_$3_LIB = $$($1_$2_$3_LIB)
42 endif
43
44 # All the .a/.so library file dependencies for this library.
45 #
46 # The $(subst stage2,dist-install,..) is needed due to Note
47 # [inconsistent distdirs].
48 #
49 # NB: Use DEP_COMPONENT_IDS for the /directory/ parameter.
50 $1_$2_$3_DEPS_LIBS=$$(foreach dep,$$($1_$2_DEP_COMPONENT_IDS),$$($$(dep)_$(subst stage2,dist-install,$2)_$3_LIB))
51
52 $1_$2_$3_NON_HS_OBJS = $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS)
53 $1_$2_$3_ALL_OBJS = $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_NON_HS_OBJS)
54
55 ifeq "$3" "dyn"
56
57 # Link a dynamic library
58 # On windows we have to supply the extra libs this one links to when building it.
59 ifeq "$$(TargetOS_CPP)" "mingw32"
60 $$($1_$2_$3_LIB) : $$($1_$2_$3_ALL_OBJS) $$(ALL_RTS_LIBS) $$($1_$2_$3_DEPS_LIBS)
61 $$(call build-dll,$1,$2,$3,-L$1/$2/build,,$$($1_$2_$3_HS_OBJS) $$($1_$2_$3_NON_HS_OBJS),"$$@","NO","$$($1_PACKAGE)","$$($1_$2_VERSION)")
62
63 else # ifneq "$$(TargetOS_CPP)" "mingw32"
64 $$($1_$2_$3_LIB) : $$($1_$2_$3_ALL_OBJS) $$(ALL_RTS_LIBS) $$($1_$2_$3_DEPS_LIBS)
65 $$(call cmd,$1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) $$($1_$2_$3_GHC_LD_OPTS) $$($1_$2_$3_ALL_OBJS) \
66 -shared -dynamic -dynload deploy \
67 $$(addprefix -l,$$($1_$2_EXTRA_LIBRARIES)) $$(addprefix -L,$$($1_$2_EXTRA_LIBDIRS)) \
68 -no-auto-link-packages \
69 -o $$@
70 endif # "$$(TargetOS_CPP)" "mingw32"
71
72 else # ifneq "$3" "dyn"
73
74 # Build the ordinary .a library
75 $$($1_$2_$3_LIB) : $$($1_$2_$3_ALL_OBJS)
76 $$(call removeFiles,$$@ $$@.contents)
77 echo $$($1_$2_$3_ALL_OBJS) >> $$@.contents
78 ifeq "$$($1_$2_ArSupportsAtFile)" "YES"
79 $$(call cmd,$1_$2_AR) $$($1_$2_AR_OPTS) $$($1_$2_EXTRA_AR_ARGS) $$@ @$$@.contents
80 else
81 "$$(XARGS)" $$(XARGS_OPTS) "$$($1_$2_AR)" $$($1_$2_AR_OPTS) $$($1_$2_EXTRA_AR_ARGS) $$@ < $$@.contents
82 endif
83 $$(call removeFiles,$$@.contents)
84
85 endif # "$3" "dyn"
86
87 $(call all-target,$1_$2,all_$1_$2_$3)
88 $(call all-target,$1_$2_$3,$$($1_$2_$3_LIB))
89
90 # Don't put bootstrapping packages in the bindist
91 ifneq "$4" "0"
92 BINDIST_HI += $$($1_$2_$3_HI)
93 BINDIST_LIBS += $$($1_$2_$3_LIB)
94 # Need to put the split libs and import libraries here
95 endif
96
97 ifeq "$$($1_$2_SplitSections)" "YES"
98 ifeq "$(LdIsGNULd)" "YES"
99 ifeq "$$(HostOS_CPP)" "mingw32"
100 $1_$2_LD_SCRIPT_CMD =
101 $1_$2_LD_SCRIPT = driver/utils/merge_sections_pe.ld
102 else
103 $1_$2_LD_SCRIPT_CMD = -T
104 $1_$2_LD_SCRIPT = driver/utils/merge_sections.ld
105 endif
106 endif
107 endif
108
109 # Build the GHCi library
110 ifneq "$(filter $3, v p)" ""
111 $1_$2_$3_GHCI_LIB = $1/$2/build/HS$$($1_$2_COMPONENT_ID).$$($3_osuf)
112 ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES"
113 # Don't put bootstrapping packages in the bindist
114 ifneq "$4" "0"
115 BINDIST_LIBS += $$($1_$2_$3_GHCI_LIB)
116 endif
117 endif
118 $$($1_$2_$3_GHCI_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) $$($1_$2_LD_SCRIPT)
119 $$(call cmd,LD_NO_GOLD) $$(CONF_LD_LINKER_OPTS_STAGE$4) -r $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS)
120 # NB. LD_NO_GOLD above: see #14328 (symptoms: #14675,#14291). At least
121 # some versions of ld.gold appear to have a bug that causes the
122 # generated GHCi library to have some bogus relocations. Performance
123 # isn't critical here, so we fall back to the ordinary ld.
124 ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES"
125 # Don't bother making ghci libs for bootstrapping packages
126 ifneq "$4" "0"
127 $(call all-target,$1_$2,$$($1_$2_$3_GHCI_LIB))
128 endif
129 endif # "$$($1_$2_BUILD_GHCI_LIB)" "YES"
130 endif # "$(filter $3, v p)" ""
131
132 $(call profEnd, build-package-way($1,$2,$3))
133 endef # build-package-way
134
135 define build-dll
136 # Call out to the shell script to decide how to build the util dll.
137 # 1 = dir
138 # 2 = distdir
139 # 3 = way
140 # 4 = extra flags
141 # 5 = extra libraries to link
142 # 6 = object files to link
143 # 7 = output filename
144 # 8 = link command
145 # 9 = create delay load import lib
146 # 10 = SxS Name
147 # 11 = SxS Version
148 $(gen-dll_INPLACE) link "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$(call cmd,$1_$2_HC) $(subst -no-hs-main,,$($1_$2_$3_ALL_HC_OPTS) $($1_$2_$3_GHC_LD_OPTS)) \
149 -shared -dynamic -dynload deploy \
150 $(addprefix -l,$($1_$2_EXTRA_LIBRARIES)) \
151 -no-auto-link-packages" "$8" \
152 "$9" "${10}"
153 endef
154