Rename PACKAGE_KEY and LIB_NAME in build system.
[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)$$($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 ifeq "$$(HostOS_CPP)" "mingw32"
31 ifneq "$$($1_$2_dll0_HS_OBJS)" ""
32 $1_$2_$3_LIB0_ROOT = HS$$($1_$2_COMPONENT_ID)-0$$($3_libsuf)
33 $1_$2_$3_LIB0_NAME = lib$$($1_$2_$3_LIB0_ROOT)
34 $1_$2_$3_LIB0 = $1/$2/build/$$($1_$2_$3_LIB0_NAME)
35 endif
36 endif
37
38 # Note [inconsistent distdirs]
39 # hack: the DEPS_LIBS mechanism assumes that the distdirs for packages
40 # that depend on each other are the same, but that is not the case for
41 # ghc where we use stage1/stage2 rather than dist/dist-install.
42 # Really we should use a consistent scheme for distdirs, but in the
43 # meantime we work around it by defining ghc-<ver>_dist-install_way_LIB:
44 ifeq "$$($1_PACKAGE) $2" "ghc stage2"
45 $$($1_$2_COMPONENT_ID)_dist-install_$3_LIB = $$($1_$2_$3_LIB)
46 endif
47
48 # All the .a/.so library file dependencies for this library.
49 #
50 # The $(subst stage2,dist-install,..) is needed due to Note
51 # [inconsistent distdirs].
52 #
53 # NB: Use DEP_COMPONENT_IDS for the /directory/ parameter.
54 $1_$2_$3_DEPS_LIBS=$$(foreach dep,$$($1_$2_DEP_COMPONENT_IDS),$$($$(dep)_$(subst stage2,dist-install,$2)_$3_LIB))
55
56 $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)
57 $1_$2_$3_ALL_OBJS = $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_NON_HS_OBJS)
58
59 ifeq "$3" "dyn"
60
61 ifneq "$$($1_$2_dll0_MODULES)" ""
62 $$($1_$2_$3_LIB) : $1/$2/dll-split.stamp
63 ifneq "$$($1_$2_$3_LIB0)" ""
64 $$($1_$2_$3_LIB0) : $1/$2/dll-split.stamp
65 endif
66 endif
67
68 $1/$2/dll-split.stamp: $$($1_$2_depfile_haskell) $$$$(dll-split_INPLACE)
69 $$(dll-split_INPLACE) $$< "$$($1_$2_dll0_START_MODULE)" "$$($1_$2_dll0_MODULES)"
70 touch $$@
71
72 # Link a dynamic library
73 # On windows we have to supply the extra libs this one links to when building it.
74 ifeq "$$(HostOS_CPP)" "mingw32"
75 $$($1_$2_$3_LIB) : $$($1_$2_$3_ALL_OBJS) $$(ALL_RTS_LIBS) $$($1_$2_$3_DEPS_LIBS)
76 ifneq "$$($1_$2_$3_LIB0)" ""
77 $$(call build-dll,$1,$2,$3,-L$1/$2/build -l$$($1_$2_$3_LIB0_ROOT),$$(filter-out $$($1_$2_dll0_HS_OBJS),$$($1_$2_$3_HS_OBJS)) $$($1_$2_$3_NON_HS_OBJS),$$@)
78 else
79 $$(call build-dll,$1,$2,$3,,$$($1_$2_$3_HS_OBJS) $$($1_$2_$3_NON_HS_OBJS),$$@)
80 endif
81
82 ifneq "$$($1_$2_$3_LIB0)" ""
83 $$($1_$2_$3_LIB) : $$($1_$2_$3_LIB0)
84 $$($1_$2_$3_LIB0) : $$($1_$2_$3_ALL_OBJS) $$(ALL_RTS_LIBS) $$($1_$2_$3_DEPS_LIBS)
85 $$(call build-dll,$1,$2,$3,,$$($1_$2_dll0_HS_OBJS) $$($1_$2_$3_NON_HS_OBJS),$$($1_$2_$3_LIB0))
86 endif
87
88 else
89
90 $$($1_$2_$3_LIB) : $$($1_$2_$3_ALL_OBJS) $$(ALL_RTS_LIBS) $$($1_$2_$3_DEPS_LIBS)
91 $$(call cmd,$1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) $$($1_$2_$3_GHC_LD_OPTS) $$($1_$2_$3_ALL_OBJS) \
92 -shared -dynamic -dynload deploy \
93 $$(addprefix -l,$$($1_$2_EXTRA_LIBRARIES)) $$(addprefix -L,$$($1_$2_EXTRA_LIBDIRS)) \
94 -no-auto-link-packages \
95 -o $$@
96 endif
97 else
98 # Build the ordinary .a library
99 $$($1_$2_$3_LIB) : $$($1_$2_$3_ALL_OBJS)
100 $$(call removeFiles,$$@ $$@.contents)
101 ifeq "$$($1_$2_SplitObjs)" "YES"
102 $$(FIND) $$(patsubst %.$$($3_osuf),%_$$($3_osuf)_split,$$($1_$2_$3_HS_OBJS)) -name '*.$$($3_osuf)' -print >> $$@.contents
103 echo $$($1_$2_$3_NON_HS_OBJS) >> $$@.contents
104 else
105 echo $$($1_$2_$3_ALL_OBJS) >> $$@.contents
106 endif
107 ifeq "$$($1_$2_ArSupportsAtFile)" "YES"
108 $$(call cmd,$1_$2_AR) $$($1_$2_AR_OPTS) $$($1_$2_EXTRA_AR_ARGS) $$@ @$$@.contents
109 else
110 "$$(XARGS)" $$(XARGS_OPTS) "$$($1_$2_AR)" $$($1_$2_AR_OPTS) $$($1_$2_EXTRA_AR_ARGS) $$@ < $$@.contents
111 endif
112 $$(call removeFiles,$$@.contents)
113
114 ifeq "$$(HostOS_CPP)" "mingw32"
115 ifneq "$$($1_$2_$3_LIB0)" ""
116 $$($1_$2_$3_LIB) : $$($1_$2_$3_LIB0)
117 $$($1_$2_$3_LIB0) :
118 $$(call cmd,$1_$2_AR) $$($1_$2_AR_OPTS) $$($1_$2_EXTRA_AR_ARGS) $$@
119 endif
120 endif
121
122 endif
123
124 $(call all-target,$1_$2,all_$1_$2_$3)
125 $(call all-target,$1_$2_$3,$$($1_$2_$3_LIB))
126
127 # Don't put bootstrapping packages in the bindist
128 ifneq "$4" "0"
129 BINDIST_HI += $$($1_$2_$3_HI)
130 BINDIST_LIBS += $$($1_$2_$3_LIB)
131 BINDIST_LIBS += $$($1_$2_$3_LIB0)
132 endif
133
134 # Build the GHCi library
135 ifeq "$$(DYNAMIC_GHC_PROGRAMS)" "YES"
136 $1_$2_GHCI_LIB = $$($1_$2_dyn_LIB)
137 else
138 ifeq "$3" "v"
139 $1_$2_GHCI_LIB = $1/$2/build/HS$$($1_$2_COMPONENT_ID).$$($3_osuf)
140 ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES"
141 # Don't put bootstrapping packages in the bindist
142 ifneq "$4" "0"
143 BINDIST_LIBS += $$($1_$2_GHCI_LIB)
144 endif
145 endif
146 $$($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)
147 $$(call cmd,LD) $$(CONF_LD_LINKER_OPTS_STAGE$4) -r -o $$@ $$(EXTRA_LD_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)
148
149 ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES"
150 # Don't bother making ghci libs for bootstrapping packages
151 ifneq "$4" "0"
152 $(call all-target,$1_$2,$$($1_$2_GHCI_LIB))
153 endif
154 endif
155 endif
156 endif
157
158 $(call profEnd, build-package-way($1,$2,$3))
159 endef
160
161 # $1 = dir
162 # $2 = distdir
163 # $3 = way
164 # $4 = extra flags
165 # $5 = object files to link
166 # $6 = output filename
167 define build-dll
168 $(call cmd,$1_$2_HC) $($1_$2_$3_ALL_HC_OPTS) $($1_$2_$3_GHC_LD_OPTS) $4 $5 \
169 -shared -dynamic -dynload deploy \
170 $(addprefix -l,$($1_$2_EXTRA_LIBRARIES)) \
171 -no-auto-link-packages \
172 -o $6
173 # Now check that the DLL doesn't have too many symbols. See trac #5987.
174 SYMBOLS=`$(OBJDUMP) -p $6 | sed -n "1,/^.Ordinal\/Name Pointer/ D; p; /^$$/ q" | tail -n +2 | wc -l`; echo "Number of symbols in $6: $$SYMBOLS"
175 case `$(OBJDUMP) -p $6 | sed -n "1,/^.Ordinal\/Name Pointer/ D; p; /^$$/ q" | grep "\[ *0\]" | wc -l` in 1) echo DLL $6 OK;; 0) echo No symbols in DLL $6; exit 1;; [0-9]*) echo Too many symbols in DLL $6; $(OBJDUMP) -p $6 | sed -n "1,/^.Ordinal\/Name Pointer/ D; p; /^$$/ q" | tail; exit 1;; *) echo bad DLL $6; exit 1;; esac
176 endef
177