1 # -----------------------------------------------------------------------------
3 # (c) 2009 The University of Glasgow
5 # This file is part of the GHC build system.
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
11 # -----------------------------------------------------------------------------
14 # We package libffi as Haskell package for two reasons:
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
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
33 # -----------------------------------------------------------------------------
35 # We use libffi's own configuration stuff.
37 PLATFORM := $(shell echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g')
41 # is not a valid command on non-Cygwin-systems.
42 # Let it fail silently instead of aborting the build.
46 # set -o igncr; export SHELLOPTS
47 # here as otherwise checking the size of limbs
48 # makes the build fall over on Cygwin. See the thread
49 # http://www.cygwin.com/ml/cygwin/2006-12/msg00011.html
55 # isn't sufficient to stop cygwin using symlinks the mingw gcc can't
56 # follow, as it isn't used consistently. Instead we put an ln.bat in
57 # path that always fails.
59 ifeq "$(BuildSharedLibs)" "YES"
60 libffi_STAMP_CONFIGURE = libffi/stamp.ffi.configure-shared
62 libffi_STAMP_CONFIGURE = libffi/stamp.ffi.configure
65 BINDIST_STAMPS = libffi/stamp.ffi.build libfii/stamp.ffi.configure
67 INSTALL_HEADERS += libffi/ffi.h
68 libffi_STATIC_LIB = libffi/libffi.a
69 INSTALL_LIBS += libffi/libHSffi.a libffi/HSffi.o
71 # We have to add the GHC version to the name of our dynamic libs, because
72 # they will be residing in the system location along with dynamic libs from
73 # other GHC installations.
75 libffi_HS_DYN_LIB_NAME = libHSffi$(dyn_libsuf)
76 libffi_HS_DYN_LIB = libffi/$(libffi_HS_DYN_LIB_NAME)
78 ifeq "$(Windows)" "YES"
79 libffi_DYNAMIC_PROG = $(libffi_HS_DYN_LIB).a
80 libffi_DYNAMIC_LIBS = $(libffi_HS_DYN_LIB)
83 libffi_DYNAMIC_LIBS = libffi/libffi.so libffi/libffi.so.5 libffi/libffi.so.5.0.7
86 ifeq "$(BuildSharedLibs)" "YES"
87 libffi_EnableShared=yes
89 libffi_EnableShared=no
92 ifeq "$(BuildSharedLibs)" "YES"
93 INSTALL_LIBS += $(libffi_HS_DYN_LIB)
94 ifeq "$(Windows)" "YES"
95 INSTALL_PROGS += $(libffi_HS_DYN_LIB).a
99 # We have to fake a non-working ln for configure, so that the fallback
100 # option (cp -p) gets used instead. Otherwise the libffi build system
101 # will use cygwin symbolic linkks which cannot be read by mingw gcc.
102 # The same trick is played by the GMP build in ../gmp.
104 ifneq "$(BINDIST)" "YES"
105 $(libffi_STAMP_CONFIGURE):
106 $(RM) -rf $(LIBFFI_DIR) libffi/build
107 cd libffi && $(TAR) -zxf tarball/libffi*.tar.gz
108 mv libffi/libffi-* libffi/build
110 cd libffi && $(PATCH) -p0 < libffi.dllize-3.0.6.patch
112 # This patch is just the resulting delta from running automake, autoreconf, libtoolize --force --copy
113 cd libffi && $(PATCH) -p0 < libffi.autotools-update.patch
116 (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
120 CC=$(WhatGccIsCalled) $(SHELL) configure \
121 --enable-static=yes \
122 --enable-shared=$(libffi_EnableShared) \
123 --host=$(PLATFORM) --build=$(PLATFORM)
125 # libffi.so needs to be built with the correct soname.
126 # NOTE: this builds libffi_convience.so with the incorrect
127 # soname, but we don't need that anyway!
129 $(CP) build/libtool build/libtool.orig; \
130 sed -e s/soname_spec=.*/soname_spec="$(libffi_HS_DYN_LIB_NAME)"/ build/libtool.orig > build/libtool
132 # We don't want libtool's cygwin hacks
134 $(CP) build/libtool build/libtool.orig; \
135 sed -e s/dlname=\'\$$tdlname\'/dlname=\'\$$dlname\'/ build/libtool.orig > build/libtool
139 libffi/ffi.h: $(libffi_STAMP_CONFIGURE)
140 $(CP) libffi/build/include/ffi.h $@
142 # All the libs that libffi's own build will generate
143 libffi_ALL_LIBS = $(libffi_STATIC_LIB)
144 ifeq "$(BuildSharedLibs)" "YES"
145 libffi_ALL_LIBS += $(libffi_DYNAMIC_LIBS)
147 ifeq "$(Windows)" "YES"
148 libffi_ALL_LIBS += libffi/libffi.dll.a $(libffi_HS_DYN_LIB).a
151 $(libffi_ALL_LIBS): $(libffi_STAMP_CONFIGURE)
153 $(MAKE) -C build MAKEFLAGS=; \
154 (cd build; ./libtool --mode=install cp libffi.la $(TOP)/libffi)
156 # Rename libffi.a to libHSffi.a
157 libffi/libHSffi.a libffi/libHSffi_p.a: $(libffi_STATIC_LIB)
158 $(CP) $(libffi_STATIC_LIB) libffi/libHSffi.a
159 $(CP) $(libffi_STATIC_LIB) libffi/libHSffi_p.a
161 $(eval $(call all-target,libffi,libffi/libHSffi.a libffi/libHSffi_p.a))
163 # The GHCi import lib isn't needed as compiler/ghci/Linker.lhs + rts/Linker.c
164 # link the interpreted references to FFI to the compiled FFI.
165 # Instead of adding libffi to the list preloaded packages (see
166 # compiler/ghci/Linker.lhs:emptyPLS) we generate an empty HSffi.o
168 libffi/HSffi.o: libffi/libHSffi.a
171 $(CC) -c empty.c -o HSffi.o
173 $(eval $(call all-target,libffi,libffi/HSffi.o))
175 ifeq "$(BuildSharedLibs)" "YES"
176 ifeq "$(Windows)" "YES"
177 # Windows libtool creates <soname>.dll, and as we already patched that
178 # there is no need to copy from libffi.dll to libHSffi...dll.
179 # However, the renaming is still required for the import library
181 $(libffi_HS_DYN_LIB).a: libffi/libffi.dll.a
182 $(CP) libffi/libffi.dll.a $(libffi_HS_DYN_LIB).a
184 $(eval $(call all-target,libffi,$(libffi_HS_DYN_LIB).a))
187 # Rename libffi.so to libHSffi...so
188 $(libffi_HS_DYN_LIB): $(libffi_DYNAMIC_LIBS)
189 $(CP) $(word 1,$(libffi_DYNAMIC_LIBS)) $(libffi_HS_DYN_LIB)
191 $(eval $(call all-target,libffi,$(libffi_HS_DYN_LIB)))
195 $(eval $(call clean-target,libffi,, \
196 libffi/build libffi/stamp.ffi.* libffi/ffi.h libffi/empty.c \
197 libffi/libffi.a libffi/libffi.la \
198 libffi/HSffi.o libffi/libHSffi.a libffi/libHSffi_p.a \
199 $(libffi_DYNAMIC_PROG) $(libffi_DYNAMIC_LIBS) \
200 $(libffi_HS_DYN_LIB) $(libffi_HS_DYN_LIB).a))
203 #-----------------------------------------------------------------------------
204 # Do the package config
206 $(eval $(call manual-package-config,libffi))
208 #-----------------------------------------------------------------------------
212 BINDIST_EXTRAS += libffi/package.conf.in