2 # We package libffi as Haskell package for two reasons:
4 # 1) GHC uses different names for shared and static libs, so it can
5 # choose the lib variant to link with on its own. With regular
6 # libtool styled shared lib names, the linker would interfer and
7 # link against the shared lib variant even when GHC runs in -static
9 # 2) The first issue isn't a problem when a shared lib of libffi would
10 # be installed in system locations, but we do not assume that. So,
11 # when running in -dynamic mode, we must either install libffi to
12 # system locations ourselves, or we must add its location to
13 # respective environment variable, (DY)LD_LIBRARY_PATH etc...before
14 # we call dynamically linked binaries. Especially, the latter is
15 # necessary as GHC calls binary it produced before its installation
16 # phase. However, both mechanism, installing to system locations or
17 # modifying (DY)LD_LIBRARY_PATH, are already in place for Haskell
18 # packages so with packaging libffi as Haskell package we reuse
21 # -----------------------------------------------------------------------------
23 # We use libffi's own configuration stuff.
25 PLATFORM := $(shell echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g')
29 # is not a valid command on non-Cygwin-systems.
30 # Let it fail silently instead of aborting the build.
34 # set -o igncr; export SHELLOPTS
35 # here as otherwise checking the size of limbs
36 # makes the build fall over on Cygwin. See the thread
37 # http://www.cygwin.com/ml/cygwin/2006-12/msg00011.html
43 # isn't sufficient to stop cygwin using symlinks the mingw gcc can't
44 # follow, as it isn't used consistently. Instead we put an ln.bat in
45 # path that always fails.
47 ifeq "$(BuildSharedLibs)" "YES"
48 libffi_STAMP_BUILD = libffi/stamp.ffi.build-shared
49 libffi_STAMP_CONFIGURE = libffi/stamp.ffi.configure-shared
51 libffi_STAMP_BUILD = libffi/stamp.ffi.build
52 libffi_STAMP_CONFIGURE = libffi/stamp.ffi.configure
55 BINDIST_STAMPS = libffi/stamp.ffi.build libfii/stamp.ffi.configure
57 INSTALL_HEADERS += libffi/ffi.h
58 libffi_STATIC_LIB = libffi/libffi.a
59 INSTALL_LIBS += libffi/libHSffi.a libffi/HSffi.o
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.
65 libffi_HS_DYN_LIB_NAME=libHSffi-ghc$(ProjectVersion)$(soext)
66 libffi_HS_DYN_LIB_PATH=libffi/$(libffi_HS_DYN_LIB_NAME)
68 ifeq "$(Windows)" "YES"
69 libffi_DYNAMIC_PROG = $(libffi_HS_DYN_LIB_PATH).a
70 libffi_DYNAMIC_LIBS = $(libffi_HS_DYN_LIB_PATH)
73 libffi_DYNAMIC_LIBS = libffi/libffi.so libffi/libffi.so.5 libffi/libffi.so.5.0.7
76 ifeq "$(BuildSharedLibs)" "YES"
77 libffi_EnableShared=yes
79 libffi_EnableShared=no
82 ifeq "$(BuildSharedLibs)" "YES"
83 INSTALL_LIBS += $(libffi_HS_DYN_LIB_PATH)
84 ifeq "$(Windows)" "YES"
85 INSTALL_PROGS += $(libffi_HS_DYN_LIB_PATH).a
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.
94 ifneq "$(BINDIST)" "YES"
95 $(libffi_STAMP_CONFIGURE):
96 $(RM) -rf $(LIBFFI_DIR) libffi/build
97 cd libffi && $(TAR) -zxf tarball/libffi*.tar.gz
98 mv libffi/libffi-* libffi/build
100 cd libffi && $(PATCH) -p0 < libffi.dllize-3.0.6.patch
102 # This patch is just the resulting delta from running automake, autoreconf, libtoolize --force --copy
103 cd libffi && $(PATCH) -p0 < libffi.autotools-update.patch
106 (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
110 CC=$(WhatGccIsCalled) $(SHELL) configure \
111 --enable-static=yes \
112 --enable-shared=$(libffi_EnableShared) \
113 --host=$(PLATFORM) --build=$(PLATFORM)
115 # libffi.so needs to be built with the correct soname.
116 # NOTE: this builds libffi_convience.so with the incorrect
117 # soname, but we don't need that anyway!
119 $(CP) build/libtool build/libtool.orig; \
120 sed -e s/soname_spec=.*/soname_spec="$(libffi_HS_DYN_LIB_NAME)"/ build/libtool.orig > build/libtool
122 # We don't want libtool's cygwin hacks
124 $(CP) build/libtool build/libtool.orig; \
125 sed -e s/dlname=\'\$$tdlname\'/dlname=\'\$$dlname\'/ build/libtool.orig > build/libtool
129 libffi/ffi.h: $(libffi_STAMP_CONFIGURE)
130 $(CP) libffi/build/include/ffi.h $@
132 $(libffi_STAMP_BUILD): $(libffi_STAMP_CONFIGURE)
134 $(MAKE) -C build MAKEFLAGS=; \
135 (cd build; ./libtool --mode=install cp libffi.la $(TOP)/libffi)
136 $(CP) $(libffi_STATIC_LIB) libffi/libHSffi.a
137 $(CP) $(libffi_STATIC_LIB) libffi/libHSffi_p.a
140 libffi/libHSffi.a libffi/libHSffi_p.a: $(libffi_STAMP_BUILD)
142 all_libffi : libffi/libHSffi.a libffi/libHSffi_p.a
144 # The GHCi import lib isn't needed as compiler/ghci/Linker.lhs + rts/Linker.c
145 # link the interpreted references to FFI to the compiled FFI.
146 # Instead of adding libffi to the list preloaded packages (see
147 # compiler/ghci/Linker.lhs:emptyPLS) we generate an empty HSffi.o
149 libffi/HSffi.o: libffi/libHSffi.a
152 $(CC) -c empty.c -o HSffi.o
154 all_libffi : libffi/HSffi.o
156 ifeq "$(BuildSharedLibs)" "YES"
157 ifeq "$(Windows)" "YES"
158 # Windows libtool creates <soname>.dll, and as we already patched that
159 # there is no need to copy from libffi.dll to libHSffi...dll.
160 # However, the renaming is still required for the import library
162 $(libffi_HS_DYN_LIB_PATH).a: $(libffi_STAMP_BUILD)
163 $(CP) libffi/libffi.dll.a $(libffi_HS_DYN_LIB_PATH).a
164 all_libffi : $(libffi_HS_DYN_LIB_PATH).a
167 # Rename libffi.so to libHSffi...so
168 $(libffi_HS_DYN_LIB_PATH): $(libffi_DYNAMIC_LIBS)
169 $(CP) $(word 1,$(libffi_DYNAMIC_LIBS)) $(libffi_HS_DYN_LIB_PATH)
171 all_libffi : $(libffi_HS_DYN_LIB_PATH)
175 $(eval $(call clean-target,libffi,, \
176 libffi/build libffi/stamp.ffi.* libffi/ffi.h libffi/empty.c \
177 libffi/libffi.a libffi/libffi.la \
178 libffi/HSffi.o libffi/libHSffi.a libffi/libHSffi_p.a \
179 $(libffi_DYNAMIC_PROG) $(libffi_DYNAMIC_LIBS) \
180 $(libffi_HS_DYN_LIB_NAME) $(libffi_HS_DYN_LIB_NAME).a))
183 #-----------------------------------------------------------------------------
184 # Do the package config
186 $(eval $(call manual-package-config,libffi))
188 #-----------------------------------------------------------------------------
192 BINDIST_EXTRAS += libffi/package.conf.in