Merge branch 'master' of win:c:/ghc/git/cygwin/.
[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://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
9 # http://hackage.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_NAME = libHS$$($1_PACKAGE)-$$($1_$2_VERSION)$$($3_libsuf)
27 $1_$2_$3_LIB = $1/$2/build/$$($1_$2_$3_LIB_NAME)
28 $$($1_PACKAGE)-$$($1_$2_VERSION)_$2_$3_LIB = $$($1_$2_$3_LIB)
29
30 ifeq "$3" "dyn"
31 ifeq "$$(HostOS_CPP)" "mingw32"
32 ifneq "$$($1_$2_dll0_HS_OBJS)" ""
33 $1_$2_$3_LIB0_ROOT = HS$$($1_PACKAGE)-$$($1_$2_VERSION)-0$$($3_libsuf)
34 $1_$2_$3_LIB0_NAME = lib$$($1_$2_$3_LIB0_ROOT)
35 $1_$2_$3_LIB0 = $1/$2/build/$$($1_$2_$3_LIB0_NAME)
36 endif
37 endif
38 endif
39
40 # Note [inconsistent distdirs]
41 # hack: the DEPS_LIBS mechanism assumes that the distdirs for packages
42 # that depend on each other are the same, but that is not the case for
43 # ghc where we use stage1/stage2 rather than dist/dist-install.
44 # Really we should use a consistent scheme for distdirs, but in the
45 # meantime we work around it by defining ghc-<ver>_dist-install_way_LIB:
46 ifeq "$$($1_PACKAGE) $2" "ghc stage2"
47 $$($1_PACKAGE)-$$($1_$2_VERSION)_dist-install_$3_LIB = $$($1_$2_$3_LIB)
48 endif
49
50 # All the .a/.so library file dependencies for this library.
51 #
52 # The $(subst stage2,dist-install,..) is needed due to Note
53 # [inconsistent distdirs].
54 $1_$2_$3_DEPS_LIBS=$$(foreach dep,$$($1_$2_DEPS),$$($$(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 # Link a dynamic library
62 # On windows we have to supply the extra libs this one links to when building it.
63 ifeq "$$(HostOS_CPP)" "mingw32"
64 $$($1_$2_$3_LIB) : $$($1_$2_$3_ALL_OBJS) $$(ALL_RTS_LIBS) $$($1_$2_$3_DEPS_LIBS)
65 ifneq "$$($1_$2_$3_LIB0)" ""
66 $$(call build-dll,$1,$2,$3,,$$($1_$2_dll0_HS_OBJS) $$($1_$2_$3_NON_HS_OBJS),$$($1_$2_$3_LIB0))
67 $$(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),$$@)
68 else
69 $$(call build-dll,$1,$2,$3,,$$($1_$2_$3_HS_OBJS) $$($1_$2_$3_NON_HS_OBJS),$$@)
70 endif
71 else
72 $$($1_$2_$3_LIB) : $$($1_$2_$3_ALL_OBJS) $$(ALL_RTS_LIBS) $$($1_$2_$3_DEPS_LIBS)
73 $$(call cmd,$1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) $$($1_$2_$3_GHC_LD_OPTS) $$($1_$2_$3_ALL_OBJS) \
74 -shared -dynamic -dynload deploy \
75 $$(addprefix -l,$$($1_$2_EXTRA_LIBRARIES)) $$(addprefix -L,$$($1_$2_EXTRA_LIBDIRS)) \
76 -no-auto-link-packages \
77 -o $$@
78 endif
79 else
80 # Build the ordinary .a library
81 $$($1_$2_$3_LIB) : $$($1_$2_$3_ALL_OBJS)
82 $$(call removeFiles,$$@ $$@.contents)
83 ifeq "$$($1_$2_SplitObjs)" "YES"
84 $$(FIND) $$(patsubst %.$$($3_osuf),%_$$($3_osuf)_split,$$($1_$2_$3_HS_OBJS)) -name '*.$$($3_osuf)' -print >> $$@.contents
85 echo $$($1_$2_$3_NON_HS_OBJS) >> $$@.contents
86 else
87 echo $$($1_$2_$3_ALL_OBJS) >> $$@.contents
88 endif
89 ifeq "$$($1_$2_ArSupportsAtFile)" "YES"
90 $$(call cmd,$1_$2_AR) $$($1_$2_AR_OPTS) $$($1_$2_EXTRA_AR_ARGS) $$@ @$$@.contents
91 else
92 "$$(XARGS)" $$(XARGS_OPTS) "$$($1_$2_AR)" $$($1_$2_AR_OPTS) $$($1_$2_EXTRA_AR_ARGS) $$@ < $$@.contents
93 endif
94 $$(call removeFiles,$$@.contents)
95 endif
96
97 $(call all-target,$1_$2,all_$1_$2_$3)
98 $(call all-target,$1_$2_$3,$$($1_$2_$3_LIB))
99
100 # Don't put bootstrapping packages in the bindist
101 ifneq "$4" "0"
102 BINDIST_HI += $$($1_$2_$3_HI)
103 BINDIST_LIBS += $$($1_$2_$3_LIB)
104 BINDIST_LIBS += $$($1_$2_$3_LIB0)
105 endif
106
107 # Build the GHCi library
108 ifeq "$$(DYNAMIC_BY_DEFAULT)" "YES"
109 $1_$2_GHCI_LIB = $$($1_$2_dyn_LIB)
110 else
111 ifeq "$3" "v"
112 $1_$2_GHCI_LIB = $1/$2/build/HS$$($1_PACKAGE)-$$($1_$2_VERSION).$$($3_osuf)
113 ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES"
114 # Don't put bootstrapping packages in the bindist
115 ifneq "$4" "0"
116 BINDIST_LIBS += $$($1_$2_GHCI_LIB)
117 endif
118 endif
119 $$($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)
120 $$(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)
121
122 ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES"
123 # Don't bother making ghci libs for bootstrapping packages
124 ifneq "$4" "0"
125 $(call all-target,$1_$2,$$($1_$2_GHCI_LIB))
126 endif
127 endif
128 endif
129 endif
130
131 $(call profEnd, build-package-way($1,$2,$3))
132 endef
133
134 # $1 = dir
135 # $2 = distdir
136 # $3 = way
137 # $4 = extra flags
138 # $5 = object files to link
139 # $6 = output filename
140 define build-dll
141 $(call cmd,$1_$2_HC) $($1_$2_$3_ALL_HC_OPTS) $($1_$2_$3_GHC_LD_OPTS) $4 $5 \
142 -shared -dynamic -dynload deploy \
143 $(addprefix -l,$($1_$2_EXTRA_LIBRARIES)) \
144 -no-auto-link-packages \
145 -o $6
146 # Now check that the DLL doesn't have too many symbols. See trac #5987.
147 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
148 endef
149