Remove dll-split.
[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) $$(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
126 ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES"
127 # Don't bother making ghci libs for bootstrapping packages
128 ifneq "$4" "0"
129 $(call all-target,$1_$2,$$($1_$2_GHCI_LIB))
130 endif
131 endif # "$$($1_$2_BUILD_GHCI_LIB)" "YES"
132 endif # "$3" "v"
133
134 $(call profEnd, build-package-way($1,$2,$3))
135 endef # build-package-way
136
137 # $1 = dir
138 # $2 = distdir
139 # $3 = way
140 # $4 = extra flags
141 # $5 = object files to link
142 # $6 = output filename
143 define build-dll
144 $(call cmd,$1_$2_HC) $($1_$2_$3_ALL_HC_OPTS) $($1_$2_$3_GHC_LD_OPTS) $4 $5 \
145 -shared -dynamic -dynload deploy \
146 $(addprefix -l,$($1_$2_EXTRA_LIBRARIES)) \
147 -no-auto-link-packages \
148 -o $6
149 # Now check that the DLL doesn't have too many symbols. See trac #5987.
150 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"
151 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
152 endef
153