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 += libHSffi.a
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 += $(HS_DYN_LIB_NAME)
84 ifeq "$(Windows)" "YES"
85 INSTALL_PROGS += $(HS_DYN_LIB_NAME).a
89 install all :: $(INSTALL_HEADERS) $(INSTALL_LIBS) $(INSTALL_PROGS)
91 # We have to fake a non-working ln for configure, so that the fallback
92 # option (cp -p) gets used instead. Otherwise the libffi build system
93 # will use cygwin symbolic linkks which cannot be read by mingw gcc.
94 # The same trick is played by the GMP build in ../gmp.
97 $(RM) -rf $(LIBFFI_DIR) build
98 $(TAR) -zxf $(LIBFFI_TARBALL)
99 mv $(LIBFFI_DIR) build
101 (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
105 CC=$(WhatGccIsCalled) $(SHELL) configure \
106 --enable-static=yes \
107 --enable-shared=$(EnableShared) \
108 --host=$(PLATFORM) --build=$(PLATFORM)
110 # libffi.so needs to be built with the correct soname.
111 # NOTE: this builds libffi_convience.so with the incorrect
112 # soname, but we don't need that anyway!
113 $(CP) build/libtool build/libtool.orig
114 sed -e s/soname_spec=.*/soname_spec="$(HS_DYN_LIB_NAME)"/ build/libtool.orig > build/libtool
117 ffi.h: stamp.ffi.configure
118 $(CP) build/include/ffi.h .
120 stamp.ffi.build: stamp.ffi.configure
121 $(MAKE) -C build MAKEFLAGS=
122 (cd build; ./libtool --mode=install cp libffi.la $(FPTOOLS_TOP_ABS)/libffi)
125 $(STATIC_LIB) $(DYNAMIC_LIBS) $(DYNAMIC_PROG): stamp.ffi.build
127 libHSffi.a libHSffi_p.a: $(STATIC_LIB)
128 $(CP) $(STATIC_LIB) $@
130 all :: libHSffi.a libHSffi_p.a
132 # The GHCi import lib isn't needed as compiler/ghci/Linker.lhs + rts/Linker.c
133 # link the interpreted references to FFI to the compiled FFI.
134 # Instead of adding libffi to the list preloaded packages (see
135 # compiler/ghci/Linker.lhs:emptyPLS) we generate an empty HSffi.o
139 $(CC) -c empty.c -o HSffi.o
143 ifeq "$(BuildSharedLibs)" "YES"
144 $(HS_DYN_LIB_NAME): $(DYNAMIC_LIBS)
145 $(CP) $(word 1,$(DYNAMIC_LIBS)) $(HS_DYN_LIB_NAME)
147 all :: $(HS_DYN_LIB_NAME)
150 clean distclean maintainer-clean ::
151 $(RM) -f stamp.ffi.configure stamp.ffi.build ffi.h empty.c
152 $(RM) -f libffi.a libffi.la $(DYNAMIC_PROG) $(DYNAMIC_LIBS) $(ORIG_DYNAMIC_LIBS)
155 #-----------------------------------------------------------------------------
159 include $(TOP)/mk/target.mk
161 BINDIST_EXTRAS += $(BINDIST_STAMPS)
162 BINDIST_EXTRAS += $(INSTALL_PROGS)
163 BINDIST_EXTRAS += $(INSTALL_LIBS)
164 BINDIST_EXTRAS += $(INSTALL_HEADERS)
165 include $(TOP)/mk/bindist.mk