Build fixes for OS X amd64 following libffi update
[ghc.git] / libffi / ghc.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 # We package libffi as Haskell package for two reasons:
15
16 # 1) GHC uses different names for shared and static libs, so it can
17 # choose the lib variant to link with on its own. With regular
18 # libtool styled shared lib names, the linker would interfer and
19 # link against the shared lib variant even when GHC runs in -static
20 # mode.
21 # 2) The first issue isn't a problem when a shared lib of libffi would
22 # be installed in system locations, but we do not assume that. So,
23 # when running in -dynamic mode, we must either install libffi to
24 # system locations ourselves, or we must add its location to
25 # respective environment variable, (DY)LD_LIBRARY_PATH etc...before
26 # we call dynamically linked binaries. Especially, the latter is
27 # necessary as GHC calls binary it produced before its installation
28 # phase. However, both mechanism, installing to system locations or
29 # modifying (DY)LD_LIBRARY_PATH, are already in place for Haskell
30 # packages so with packaging libffi as Haskell package we reuse
31 # them naturally.
32
33 # -----------------------------------------------------------------------------
34 #
35 # We use libffi's own configuration stuff.
36
37 # 2007-07-05
38 # Passing
39 # as_ln_s='cp -p'
40 # isn't sufficient to stop cygwin using symlinks the mingw gcc can't
41 # follow, as it isn't used consistently. Instead we put an ln.bat in
42 # path that always fails.
43
44 ifeq "$(BuildSharedLibs)" "YES"
45 libffi_STAMP_CONFIGURE = libffi/stamp.ffi.configure-shared
46 libffi_STAMP_BUILD = libffi/stamp.ffi.build-shared
47 else
48 libffi_STAMP_CONFIGURE = libffi/stamp.ffi.configure
49 libffi_STAMP_BUILD = libffi/stamp.ffi.build
50 endif
51
52 BINDIST_STAMPS = libffi/stamp.ffi.build libfii/stamp.ffi.configure
53
54 INSTALL_HEADERS += libffi/dist-install/build/ffi.h \
55 libffi/dist-install/build/ffitarget.h
56 libffi_STATIC_LIB = libffi/dist-install/build/libffi.a
57 INSTALL_LIBS += libffi/dist-install/build/libHSffi.a \
58 libffi/dist-install/build/libHSffi_p.a \
59 libffi/dist-install/build/HSffi.o
60
61 # We have to add the GHC version to the name of our dynamic libs, because
62 # they will be residing in the system location along with dynamic libs from
63 # other GHC installations.
64
65 libffi_HS_DYN_LIB_NAME = libHSffi$(dyn_libsuf)
66 libffi_HS_DYN_LIB = libffi/dist-install/build/$(libffi_HS_DYN_LIB_NAME)
67
68 ifeq "$(Windows)" "YES"
69 libffi_DYNAMIC_PROG = $(libffi_HS_DYN_LIB).a
70 libffi_DYNAMIC_LIBS = $(libffi_HS_DYN_LIB)
71 else
72 libffi_DYNAMIC_PROG =
73 ifeq "$(darwin_TARGET_OS)" "1"
74 libffi_DYNAMIC_LIBS = libffi/dist-install/build/libffi$(soext) \
75 libffi/dist-install/build/libffi.5$(soext)
76 else ifeq "$(openbsd_TARGET_OS)" "1"
77 libffi_DYNAMIC_LIBS = libffi/dist-install/build/libffi.so.5.10
78 else
79 libffi_DYNAMIC_LIBS = libffi/dist-install/build/libffi.so \
80 libffi/dist-install/build/libffi.so.5
81 endif
82 endif
83
84 ifeq "$(BuildSharedLibs)" "YES"
85 libffi_EnableShared=yes
86 else
87 libffi_EnableShared=no
88 endif
89
90 ifeq "$(BuildSharedLibs)" "YES"
91 INSTALL_LIBS += $(libffi_HS_DYN_LIB)
92 ifeq "$(Windows)" "YES"
93 INSTALL_PROGS += $(libffi_HS_DYN_LIB).a
94 endif
95 endif
96
97 # We have to fake a non-working ln for configure, so that the fallback
98 # option (cp -p) gets used instead. Otherwise the libffi build system
99 # will use cygwin symbolic linkks which cannot be read by mingw gcc.
100 # The same trick is played by the GMP build in ../gmp.
101
102 ifneq "$(BINDIST)" "YES"
103 $(libffi_STAMP_CONFIGURE):
104 "$(RM)" $(RM_OPTS_REC) $(LIBFFI_DIR) libffi/build
105 cat ghc-tarballs/libffi/libffi*.tar.gz | $(GZIP_CMD) -d | { cd libffi && $(TAR_CMD) -xf - ; }
106 mv libffi/libffi-* libffi/build
107 chmod +x libffi/ln
108
109 # Because -Werror may be in SRC_CC_OPTS/SRC_LD_OPTS, we need to turn
110 # warnings off or the compilation of libffi might fail due to warnings
111 cd libffi && \
112 PATH=`pwd`:$$PATH; \
113 export PATH; \
114 cd build && \
115 CC=$(CC_STAGE1) \
116 LD=$(LD) \
117 AR=$(AR_STAGE1) \
118 NM=$(NM) \
119 CFLAGS="$(SRC_CC_OPTS) $(CONF_CC_OPTS_STAGE1) -w" \
120 LDFLAGS="$(SRC_LD_OPTS) $(CONF_GCC_LINKER_OPTS_STAGE1) -w" \
121 "$(SHELL)" configure \
122 --enable-static=yes \
123 --enable-shared=$(libffi_EnableShared) \
124 --host=$(HOSTPLATFORM) --build=$(BUILDPLATFORM)
125
126 cp libffi/build/*/libtool libffi/build
127
128 # libffi.so needs to be built with the correct soname.
129 # NOTE: this builds libffi_convience.so with the incorrect
130 # soname, but we don't need that anyway!
131 cd libffi && \
132 "$(CP)" build/libtool build/libtool.orig && \
133 sed -e s/soname_spec=.*/soname_spec="$(libffi_HS_DYN_LIB_NAME)"/ build/libtool.orig > build/libtool
134
135 # We don't want libtool's cygwin hacks
136 cd libffi && \
137 "$(CP)" build/libtool build/libtool.orig && \
138 sed -e s/dlname=\'\$$tdlname\'/dlname=\'\$$dlname\'/ build/libtool.orig > build/libtool
139
140 # wc on OS X has spaces in its output, which libffi's Makefile
141 # doesn't expect, so we tweak it to sed them out
142 mv libffi/build/Makefile libffi/build/Makefile.orig
143 sed "s#wc -w#wc -w | sed 's/ //g'#" < libffi/build/Makefile.orig > libffi/build/Makefile
144
145 touch $@
146
147 libffi/dist-install/build/ffi.h: $(libffi_STAMP_CONFIGURE) libffi/dist-install/build/ffitarget.h | $$(dir $$@)/.
148 "$(CP)" libffi/build/*/include/ffi.h $@
149
150 libffi/dist-install/build/ffitarget.h: $(libffi_STAMP_CONFIGURE) | $$(dir $$@)/.
151 "$(CP)" libffi/build/*/include/ffitarget.h $@
152
153 $(libffi_STAMP_BUILD): $(libffi_STAMP_CONFIGURE) | libffi/dist-install/build/.
154 $(MAKE) -C libffi/build MAKEFLAGS=
155 cd libffi/build && ./libtool --mode=install cp */libffi.la $(TOP)/libffi/dist-install/build
156
157 # We actually want both static and dllized libraries, because we build
158 # the runtime system both ways. libffi_convenience.a is the static version.
159 ifeq "$(Windows)" "YES"
160 cp libffi/build/.libs/libffi_convenience.a $(libffi_STATIC_LIB)
161 endif
162
163 touch $@
164
165 $(libffi_STATIC_LIB): $(libffi_STAMP_BUILD)
166 @test -f $@ || { echo "$< exits, but $@ does not."; echo "Suggest removing $<."; exit 1; }
167
168 # Rename libffi.a to libHSffi.a
169 libffi/dist-install/build/libHSffi.a: $(libffi_STATIC_LIB)
170 "$(CP)" $(libffi_STATIC_LIB) libffi/dist-install/build/libHSffi.a
171
172 libffi/dist-install/build/libHSffi_p.a: $(libffi_STATIC_LIB)
173 "$(CP)" $(libffi_STATIC_LIB) libffi/dist-install/build/libHSffi_p.a
174
175 $(eval $(call all-target,libffi,$(INSTALL_HEADERS) $(INSTALL_LIBS)))
176
177 # The GHCi import lib isn't needed as compiler/ghci/Linker.lhs + rts/Linker.c
178 # link the interpreted references to FFI to the compiled FFI.
179 # Instead of adding libffi to the list preloaded packages (see
180 # compiler/ghci/Linker.lhs:emptyPLS) we generate an empty HSffi.o
181
182 libffi/dist-install/build/HSffi.o: libffi/dist-install/build/libHSffi.a
183 cd libffi/dist-install/build && \
184 touch empty.c && \
185 "$(CC_STAGE1)" $(SRC_CC_OPTS) $(CONF_CC_OPTS_STAGE1) -c empty.c -o HSffi.o
186
187 $(eval $(call all-target,libffi,libffi/dist-install/build/HSffi.o))
188
189 ifeq "$(BuildSharedLibs)" "YES"
190 ifeq "$(Windows)" "YES"
191 libffi/dist-install/build/libffi.dll.a $(libffi_HS_DYN_LIB): $(libffi_STAMP_BUILD)
192 @test -f $@ || { echo "$< exits, but $@ does not."; echo "Suggest removing $<."; exit 1; }
193
194 # Windows libtool creates <soname>.dll, and as we already patched that
195 # there is no need to copy from libffi.dll to libHSffi...dll.
196 # However, the renaming is still required for the import library
197 # libffi.dll.a.
198 $(libffi_HS_DYN_LIB).a: libffi/dist-install/build/libffi.dll.a | $$(dir $$@)/.
199 "$(CP)" $< $@
200
201 $(eval $(call all-target,libffi,$(libffi_HS_DYN_LIB).a))
202
203 else
204 $(libffi_DYNAMIC_LIBS): $(libffi_STAMP_BUILD)
205 @test -f $@ || { echo "$< exits, but $@ does not."; echo "Suggest removing $<."; exit 1; }
206
207 # Rename libffi.so to libHSffi...so
208 $(libffi_HS_DYN_LIB): $(libffi_DYNAMIC_LIBS) | $$(dir $$@)/.
209 "$(CP)" $(word 1,$(libffi_DYNAMIC_LIBS)) $(libffi_HS_DYN_LIB)
210 ifeq "$(darwin_TARGET_OS)" "1"
211 # Ensure library's install name is correct before anyone links with it.
212 install_name_tool -id $(ghclibdir)/$(libffi_HS_DYN_LIB_NAME) $(libffi_HS_DYN_LIB)
213 endif
214
215 $(eval $(call all-target,libffi,$(libffi_HS_DYN_LIB)))
216 endif
217 endif
218
219 $(eval $(call clean-target,libffi,, \
220 libffi/build libffi/stamp.ffi.* libffi/dist-install))
221 endif
222
223 #-----------------------------------------------------------------------------
224 # Do the package config
225
226 $(eval $(call manual-package-config,libffi))
227
228 #-----------------------------------------------------------------------------
229 #
230 # binary-dist
231
232 BINDIST_EXTRAS += libffi/package.conf.in