3 DONT_WANT_STD_GHCI_LIB_RULE=YES
4 DONT_WANT_STD_LIBRARY=YES
6 include $(TOP)/mk/boilerplate.mk
8 # We package libffi as Haskell package for two reasons:
10 # 1) GHC uses different names for shared and static libs, so it can
11 # choose the lib variant to link with on its own. With regular
12 # libtool styled shared lib names, the linker would interfer and
13 # link against the shared lib variant even when GHC runs in -static
15 # 2) The first issue isn't a problem when a shared lib of libffi would
16 # be installed in system locations, but we do not assume that. So,
17 # when running in -dynamic mode, we must either install libffi to
18 # system locations ourselves, or we must add its location to
19 # respective environment variable, (DY)LD_LIBRARY_PATH etc...before
20 # we call dynamically linked binaries. Especially, the latter is
21 # necessary as GHC calls binary it produced before its installation
22 # phase. However, both mechanism, installing to system locations or
23 # modifying (DY)LD_LIBRARY_PATH, are already in place for Haskell
24 # packages so with packaging libffi as Haskell package we reuse
28 # -----------------------------------------------------------------------------
30 # We use libffi's own configuration stuff.
32 PLATFORM := $(shell echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g')
36 # is not a valid command on non-Cygwin-systems.
37 # Let it fail silently instead of aborting the build.
41 # set -o igncr; export SHELLOPTS
42 # here as otherwise checking the size of limbs
43 # makes the build fall over on Cygwin. See the thread
44 # http://www.cygwin.com/ml/cygwin/2006-12/msg00011.html
50 # isn't sufficient to stop cygwin using symlinks the mingw gcc can't
51 # follow, as it isn't used consistently. Instead we put an ln.bat in
52 # path that always fails.
54 LIBFFI_TARBALL := $(firstword $(wildcard libffi*.tar.gz))
55 LIBFFI_DIR := $(subst .tar.gz,,$(LIBFFI_TARBALL))
57 BINDIST_STAMPS = stamp.ffi
58 INSTALL_HEADERS += ffi.h
60 INSTALL_LIBS += $(STATIC_LIB)
62 # We have to add the GHC version to the name of our dynamic libs, because
63 # they will be residing in the system location along with dynamic libs from
64 # other GHC installations.
65 ifeq "$(Windows)" "YES"
66 DYNAMIC_PROG = libffi.dll.a
67 DYNAMIC_LIBS = libffi-3.dll
71 DYNAMIC_LIBS = libffi.so libffi.so.5 libffi.so.5.0.5
74 HS_DYN_LIB_NAME=libHSffi-ghc$(ProjectVersion)$(soext)
76 ifeq "$(BuildSharedLibs)" "YES"
82 ifeq "$(BuildSharedLibs)" "YES"
83 INSTALL_LIBS += $(DYNAMIC_LIBS)
84 INSTALL_PROGS += $(DYNAMIC_PROGS)
87 install all :: $(INSTALL_HEADERS) $(INSTALL_LIBS) $(INSTALL_PROGS)
89 # We have to fake a non-working ln for configure, so that the fallback
90 # option (cp -p) gets used instead. Otherwise the libffi build system
91 # will use cygwin symbolic linkks which cannot be read by mingw gcc.
92 # The same trick is played by the GMP build in ../gmp.
95 $(RM) -rf $(LIBFFI_DIR) build
96 $(TAR) -zxf $(LIBFFI_TARBALL)
97 mv $(LIBFFI_DIR) build
99 (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
103 CC=$(WhatGccIsCalled) $(SHELL) configure \
104 --enable-static=yes \
105 --enable-shared=$(EnableShared) \
106 --host=$(PLATFORM) --build=$(PLATFORM)
108 # libffi.so needs to be built with the correct soname.
109 # NOTE: this builds libffi_convience.so with the incorrect
110 # soname, but we don't need that anyway!
111 sed -i -e s/soname_spec=.*/soname_spec="$(HS_DYN_LIB_NAME)"/ build/libtool
114 ffi.h: stamp.ffi.configure
115 $(CP) build/include/ffi.h .
117 stamp.ffi.build: stamp.ffi.configure
118 $(MAKE) -C build MAKEFLAGS=
119 (cd build; ./libtool --mode=install cp libffi.la $(FPTOOLS_TOP_ABS)/libffi)
122 $(STATIC_LIB) $(DYNAMIC_LIBS) $(DYNAMIC_PROG): stamp.ffi.build
124 libHSffi.a libHSffi_p.a: $(STATIC_LIB)
127 all :: libHSffi.a libHSffi_p.a
129 # The GHCi import lib isn't needed as compiler/ghci/Linker.lhs + rts/Linker.c
130 # link the interpreted references to FFI to the compiled FFI.
131 # Instead of adding libffi to the list preloaded packages (see
132 # compiler/ghci/Linker.lhs:emptyPLS) we generate an empty HSffi.o
135 ld -r -o HSffi.o /dev/null # this is intentional
137 # (mkdir unpack; cd unpack; ar x ../libHSffi.a; ld -r -o ../HSffi.o *.o)
142 ifeq "$(BuildSharedLibs)" "YES"
143 $(HS_DYN_LIB_NAME): $(DYNAMIC_LIBS)
144 cp $(word 1,$(DYNAMIC_LIBS)) $(HS_DYN_LIB_NAME)
146 all :: $(HS_DYN_LIB_NAME)
149 clean distclean maintainer-clean ::
150 $(RM) -f stamp.ffi.configure stamp.ffi.build ffi.h
151 $(RM) -f libffi.a libffi.la $(DYNAMIC_PROG) $(DYNAMIC_LIBS) $(ORIG_DYNAMIC_LIBS)
154 #-----------------------------------------------------------------------------
158 include $(TOP)/mk/target.mk
160 BINDIST_EXTRAS += $(BINDIST_STAMPS)
161 BINDIST_EXTRAS += $(INSTALL_PROGS)
162 BINDIST_EXTRAS += $(INSTALL_LIBS)
163 BINDIST_EXTRAS += $(INSTALL_HEADERS)
164 include $(TOP)/mk/bindist.mk