Delay building libffi until package.conf is created and fix bindist
[ghc-hetmet.git] / libffi / Makefile
1
2 TOP=..
3 DONT_WANT_STD_GHCI_LIB_RULE=YES
4 DONT_WANT_STD_LIBRARY=YES
5
6 include $(TOP)/mk/boilerplate.mk
7
8 # We package libffi as Haskell package for two reasons: 
9
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
14 #    mode.
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
25 #    them naturally.
26
27 PACKAGE=ffi
28 # -----------------------------------------------------------------------------
29 #
30 # We use libffi's own configuration stuff.
31
32 PLATFORM := $(shell echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g')
33
34 # 2007-09-26
35 #     set -o igncr 
36 # is not a valid command on non-Cygwin-systems.
37 # Let it fail silently instead of aborting the build.
38 #
39 # 2007-07-05
40 # We do
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
45 # for more details.
46
47 # 2007-07-05
48 # Passing
49 #     as_ln_s='cp -p'
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.
53
54 LIBFFI_TARBALL := $(firstword $(wildcard libffi*.tar.gz))
55 LIBFFI_DIR := $(subst .tar.gz,,$(LIBFFI_TARBALL))
56
57 BINDIST_STAMPS = stamp.ffi
58 INSTALL_HEADERS += ffi.h
59 STATIC_LIB = libffi.a
60 INSTALL_LIBS += libHSffi.a
61
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
68 RENAME_LIBS  =
69 else
70 DYNAMIC_PROG =
71 DYNAMIC_LIBS = libffi.so libffi.so.5 libffi.so.5.0.5
72 endif
73
74 HS_DYN_LIB_NAME=libHSffi-ghc$(ProjectVersion)$(soext)
75
76 ifeq "$(BuildSharedLibs)" "YES"
77 EnableShared=yes
78 else
79 EnableShared=no
80 endif
81
82 ifeq "$(BuildSharedLibs)" "YES"
83 INSTALL_LIBS  += $(HS_DYN_LIB_NAME)
84 ifeq "$(Windows)" "YES"
85 INSTALL_PROGS += $(HS_DYN_LIB_NAME).a
86 endif
87 endif
88
89 install all :: $(INSTALL_HEADERS) $(INSTALL_LIBS) $(INSTALL_PROGS)
90
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.
95
96 stamp.ffi.configure:
97         $(RM) -rf $(LIBFFI_DIR) build
98         $(TAR) -zxf $(LIBFFI_TARBALL)
99         mv $(LIBFFI_DIR) build
100         chmod +x ln
101         (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
102             PATH=`pwd`:$$PATH; \
103             export PATH; \
104             cd build && \
105             CC=$(WhatGccIsCalled) $(SHELL) configure \
106                   --enable-static=yes \
107                   --enable-shared=$(EnableShared) \
108                   --host=$(PLATFORM) --build=$(PLATFORM)
109
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
115         touch $@
116
117 ffi.h: stamp.ffi.configure
118         $(CP) build/include/ffi.h .
119
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)
123         touch $@
124
125 $(STATIC_LIB) $(DYNAMIC_LIBS) $(DYNAMIC_PROG): stamp.ffi.build
126
127 libHSffi.a libHSffi_p.a: $(STATIC_LIB)
128         $(CP) $(STATIC_LIB) $@
129
130 all :: libHSffi.a libHSffi_p.a
131
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
136
137 HSffi.o: libHSffi.a
138         touch empty.c
139         $(CC) -c empty.c -o HSffi.o
140
141 all :: HSffi.o
142
143 ifeq "$(BuildSharedLibs)" "YES"
144 $(HS_DYN_LIB_NAME): $(DYNAMIC_LIBS)
145         $(CP) $(word 1,$(DYNAMIC_LIBS)) $(HS_DYN_LIB_NAME)
146
147 all :: $(HS_DYN_LIB_NAME)
148 endif
149
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)
153         $(RM) -rf build
154
155 #-----------------------------------------------------------------------------
156 #
157 # binary-dist
158
159 include $(TOP)/mk/target.mk
160
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
166