cee5bb95c346a177c1059aa444af83f9e516dbbf
[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 # Override haddock generation for this package
8 HADDOCK_DOCS=NO
9
10 # We package libffi as Haskell package for two reasons: 
11
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
16 #    mode.
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
27 #    them naturally.
28
29 PACKAGE=ffi
30 # -----------------------------------------------------------------------------
31 #
32 # We use libffi's own configuration stuff.
33
34 PLATFORM := $(shell echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g')
35
36 # 2007-09-26
37 #     set -o igncr 
38 # is not a valid command on non-Cygwin-systems.
39 # Let it fail silently instead of aborting the build.
40 #
41 # 2007-07-05
42 # We do
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
47 # for more details.
48
49 # 2007-07-05
50 # Passing
51 #     as_ln_s='cp -p'
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.
55
56 LIBFFI_TARBALL := $(firstword $(wildcard libffi*.tar.gz))
57 LIBFFI_DIR := $(subst .tar.gz,,$(LIBFFI_TARBALL))
58
59 BINDIST_STAMPS = stamp.ffi.build stamp.ffi.configure
60
61 ifeq "$(BuildSharedLibs)" "YES"
62 STAMP_BUILD = stamp.ffi.build-shared
63 STAMP_CONFIGURE = stamp.ffi.configure-shared
64 else
65 STAMP_BUILD = stamp.ffi.build
66 STAMP_CONFIGURE = stamp.ffi.configure
67 endif
68
69 INSTALL_HEADERS += ffi.h
70 STATIC_LIB = libffi.a
71 INSTALL_LIBS += libHSffi.a libHSffi_p.a HSffi.o
72
73 # We have to add the GHC version to the name of our dynamic libs, because
74 # they will be residing in the system location along with dynamic libs from
75 # other GHC installations.
76
77 HS_DYN_LIB_NAME=libHSffi-ghc$(ProjectVersion)$(soext)
78
79 ifeq "$(Windows)" "YES"
80 DYNAMIC_PROG = $(HS_DYN_LIB_NAME).a
81 DYNAMIC_LIBS = $(HS_DYN_LIB_NAME)
82 else
83 DYNAMIC_PROG =
84 DYNAMIC_LIBS = libffi.so libffi.so.5 libffi.so.5.0.7
85 endif
86
87 ifeq "$(BuildSharedLibs)" "YES"
88 EnableShared=yes
89 else
90 EnableShared=no
91 endif
92
93 ifeq "$(BuildSharedLibs)" "YES"
94 INSTALL_LIBS  += $(HS_DYN_LIB_NAME)
95 ifeq "$(Windows)" "YES"
96 INSTALL_PROGS += $(HS_DYN_LIB_NAME).a
97 endif
98 endif
99
100 install all :: $(INSTALL_HEADERS) $(INSTALL_LIBS) $(INSTALL_PROGS)
101
102 # We have to fake a non-working ln for configure, so that the fallback
103 # option (cp -p) gets used instead.  Otherwise the libffi build system
104 # will use cygwin symbolic linkks which cannot be read by mingw gcc.
105 # The same trick is played by the GMP build in ../gmp.
106
107 $(STAMP_CONFIGURE):
108         $(RM) -rf $(LIBFFI_DIR) build
109         $(TAR) -zxf $(LIBFFI_TARBALL)
110         mv $(LIBFFI_DIR) build
111         chmod +x ln
112         patch -p0 < libffi-dllize-3.0.6.patch
113
114         # This patch is just the resulting delta from running automake, autoreconf, libtoolize --force --copy
115         patch -p0 < libffi-autotools-update.patch
116
117         (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
118             PATH=`pwd`:$$PATH; \
119             export PATH; \
120             cd build && \
121             CC=$(WhatGccIsCalled) $(SHELL) configure \
122                   --enable-static=yes \
123                   --enable-shared=$(EnableShared) \
124                   --host=$(PLATFORM) --build=$(PLATFORM)
125
126         # libffi.so needs to be built with the correct soname.
127         # NOTE: this builds libffi_convience.so with the incorrect
128         # soname, but we don't need that anyway!
129         $(CP) build/libtool build/libtool.orig
130         sed -e s/soname_spec=.*/soname_spec="$(HS_DYN_LIB_NAME)"/ build/libtool.orig > build/libtool
131
132         # We don't want libtool's cygwin hacks
133         $(CP) build/libtool build/libtool.orig
134         sed -e s/dlname=\'\$$tdlname\'/dlname=\'\$$dlname\'/ build/libtool.orig > build/libtool
135
136         touch $@
137
138 ffi.h: $(STAMP_CONFIGURE)
139         $(CP) build/include/ffi.h .
140
141 $(STAMP_BUILD): $(STAMP_CONFIGURE)
142         $(MAKE) -C build MAKEFLAGS=
143         (cd build; ./libtool --mode=install cp libffi.la $(FPTOOLS_TOP_ABS)/libffi)
144         $(CP) $(STATIC_LIB) libHSffi.a
145         $(CP) $(STATIC_LIB) libHSffi_p.a
146         touch $@
147
148 libHSffi.a libHSffi_p.a: $(STAMP_BUILD)
149
150 all :: libHSffi.a libHSffi_p.a
151
152 # The GHCi import lib isn't needed as compiler/ghci/Linker.lhs + rts/Linker.c
153 # link the interpreted references to FFI to the compiled FFI.
154 # Instead of adding libffi to the list preloaded packages (see
155 # compiler/ghci/Linker.lhs:emptyPLS) we generate an empty HSffi.o
156
157 HSffi.o: libHSffi.a
158         touch empty.c
159         $(CC) -c empty.c -o HSffi.o
160
161 all :: HSffi.o
162
163 ifeq "$(BuildSharedLibs)" "YES"
164 ifeq "$(Windows)" "YES"
165 # Windows libtool creates <soname>.dll, and as we already patched that
166 # there is no need to copy from libffi.dll to libHSffi...dll.
167 # However, the renaming is still required for the import library
168 # libffi.dll.a.
169 $(HS_DYN_LIB_NAME).a: $(STAMP_BUILD)
170         $(CP) libffi.dll.a $(HS_DYN_LIB_NAME).a
171 all :: $(HS_DYN_LIB_NAME).a
172
173 else
174 # Rename libffi.so to libHSffi...so
175 $(HS_DYN_LIB_NAME): $(DYNAMIC_LIBS)
176         $(CP) $(word 1,$(DYNAMIC_LIBS)) $(HS_DYN_LIB_NAME)
177
178 all :: $(HS_DYN_LIB_NAME)
179 endif
180 endif
181
182 clean distclean maintainer-clean ::
183         $(RM) -f stamp.ffi.* ffi.h empty.c
184         $(RM) -f libffi.a libffi.la $(DYNAMIC_PROG) $(DYNAMIC_LIBS) $(HS_DYN_LIB_NAME) $(HS_DYN_LIB_NAME).a
185         $(RM) -rf build
186
187 #-----------------------------------------------------------------------------
188 #
189 # binary-dist
190
191 include $(TOP)/mk/target.mk
192
193 BINDIST_EXTRAS += package.conf.in
194 BINDIST_EXTRAS += $(BINDIST_STAMPS)
195 BINDIST_EXTRAS += $(INSTALL_PROGS)
196 BINDIST_EXTRAS += $(INSTALL_LIBS)
197 BINDIST_EXTRAS += $(INSTALL_HEADERS)
198 include $(TOP)/mk/bindist.mk
199