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