CircleCI: More cleanup
[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 # http://ghc.haskell.org/trac/ghc/wiki/Building/Architecture
9 # http://ghc.haskell.org/trac/ghc/wiki/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 ifeq "$$($1_$2_SplitObjs)" "YES"
78 $$(FIND) $$(patsubst %.$$($3_osuf),%_$$($3_osuf)_split,$$($1_$2_$3_HS_OBJS)) -name '*.$$($3_osuf)' -print >> $$@.contents
79 echo $$($1_$2_$3_NON_HS_OBJS) >> $$@.contents
80 else
81 echo $$($1_$2_$3_ALL_OBJS) >> $$@.contents
82 endif
83 ifeq "$$($1_$2_ArSupportsAtFile)" "YES"
84 $$(call cmd,$1_$2_AR) $$($1_$2_AR_OPTS) $$($1_$2_EXTRA_AR_ARGS) $$@ @$$@.contents
85 else
86 "$$(XARGS)" $$(XARGS_OPTS) "$$($1_$2_AR)" $$($1_$2_AR_OPTS) $$($1_$2_EXTRA_AR_ARGS) $$@ < $$@.contents
87 endif
88 $$(call removeFiles,$$@.contents)
89
90 endif # "$3" "dyn"
91
92 $(call all-target,$1_$2,all_$1_$2_$3)
93 $(call all-target,$1_$2_$3,$$($1_$2_$3_LIB))
94
95 # Don't put bootstrapping packages in the bindist
96 ifneq "$4" "0"
97 BINDIST_HI += $$($1_$2_$3_HI)
98 BINDIST_LIBS += $$($1_$2_$3_LIB)
99 # Need to put the split libs and import libraries here
100 endif
101
102 ifeq "$$($1_$2_SplitSections)" "YES"
103 ifeq "$(LdIsGNULd)" "YES"
104 ifeq "$$(HostOS_CPP)" "mingw32"
105 $1_$2_LD_SCRIPT_CMD =
106 $1_$2_LD_SCRIPT = driver/utils/merge_sections_pe.ld
107 else
108 $1_$2_LD_SCRIPT_CMD = -T
109 $1_$2_LD_SCRIPT = driver/utils/merge_sections.ld
110 endif
111 endif
112 endif
113
114 # Build the GHCi library
115 ifeq "$3" "v"
116 $1_$2_GHCI_LIB = $1/$2/build/HS$$($1_$2_COMPONENT_ID).$$($3_osuf)
117 ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES"
118 # Don't put bootstrapping packages in the bindist
119 ifneq "$4" "0"
120 BINDIST_LIBS += $$($1_$2_GHCI_LIB)
121 endif
122 endif
123 $$($1_$2_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)
124 $$(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)
125 # NB. LD_NO_GOLD above: see #14328 (symptoms: #14675,#14291). At least
126 # some versions of ld.gold appear to have a bug that causes the
127 # generated GHCi library to have some bogus relocations. Performance
128 # isn't critical here, so we fall back to the ordinary ld.
129 ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES"
130 # Don't bother making ghci libs for bootstrapping packages
131 ifneq "$4" "0"
132 $(call all-target,$1_$2,$$($1_$2_GHCI_LIB))
133 endif
134 endif # "$$($1_$2_BUILD_GHCI_LIB)" "YES"
135 endif # "$3" "v"
136
137 $(call profEnd, build-package-way($1,$2,$3))
138 endef # build-package-way
139
140 define build-dll
141 # Call out to the shell script to decide how to build the util dll.
142 # 1 = dir
143 # 2 = distdir
144 # 3 = way
145 # 4 = extra flags
146 # 5 = extra libraries to link
147 # 6 = object files to link
148 # 7 = output filename
149 # 8 = link command
150 # 9 = create delay load import lib
151 # 10 = SxS Name
152 # 11 = SxS Version
153 $(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)) \
154 -shared -dynamic -dynload deploy \
155 $(addprefix -l,$($1_$2_EXTRA_LIBRARIES)) \
156 -no-auto-link-packages" "$8" \
157 "$9" "${10}"
158 endef
159