Add a header to all build system files:
[ghc-hetmet.git] / libffi / ghc.mk
1 # -----------------------------------------------------------------------------
2 #
3 # (c) 2009 The University of Glasgow
4 #
5 # This file is part of the GHC build system.
6 #
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
10 #
11 # -----------------------------------------------------------------------------
12
13
14 # We package libffi as Haskell package for two reasons: 
15
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
20 #    mode.
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
31 #    them naturally.
32
33 # -----------------------------------------------------------------------------
34 #
35 # We use libffi's own configuration stuff.
36
37 PLATFORM := $(shell echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g')
38
39 # 2007-09-26
40 #     set -o igncr 
41 # is not a valid command on non-Cygwin-systems.
42 # Let it fail silently instead of aborting the build.
43 #
44 # 2007-07-05
45 # We do
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
50 # for more details.
51
52 # 2007-07-05
53 # Passing
54 #     as_ln_s='cp -p'
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.
58
59 ifeq "$(BuildSharedLibs)" "YES"
60 libffi_STAMP_BUILD     = libffi/stamp.ffi.build-shared
61 libffi_STAMP_CONFIGURE = libffi/stamp.ffi.configure-shared
62 else
63 libffi_STAMP_BUILD     = libffi/stamp.ffi.build
64 libffi_STAMP_CONFIGURE = libffi/stamp.ffi.configure
65 endif
66
67 BINDIST_STAMPS = libffi/stamp.ffi.build libfii/stamp.ffi.configure
68
69 INSTALL_HEADERS   += libffi/ffi.h
70 libffi_STATIC_LIB  = libffi/libffi.a
71 INSTALL_LIBS      += libffi/libHSffi.a libffi/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 libffi_HS_DYN_LIB_NAME=libHSffi-ghc$(ProjectVersion)$(soext)
78 libffi_HS_DYN_LIB_PATH=libffi/$(libffi_HS_DYN_LIB_NAME)
79
80 ifeq "$(Windows)" "YES"
81 libffi_DYNAMIC_PROG = $(libffi_HS_DYN_LIB_PATH).a
82 libffi_DYNAMIC_LIBS = $(libffi_HS_DYN_LIB_PATH)
83 else
84 libffi_DYNAMIC_PROG =
85 libffi_DYNAMIC_LIBS = libffi/libffi.so libffi/libffi.so.5 libffi/libffi.so.5.0.7
86 endif
87
88 ifeq "$(BuildSharedLibs)" "YES"
89 libffi_EnableShared=yes
90 else
91 libffi_EnableShared=no
92 endif
93
94 ifeq "$(BuildSharedLibs)" "YES"
95 INSTALL_LIBS  += $(libffi_HS_DYN_LIB_PATH)
96 ifeq "$(Windows)" "YES"
97 INSTALL_PROGS += $(libffi_HS_DYN_LIB_PATH).a
98 endif
99 endif
100
101 # We have to fake a non-working ln for configure, so that the fallback
102 # option (cp -p) gets used instead.  Otherwise the libffi build system
103 # will use cygwin symbolic linkks which cannot be read by mingw gcc.
104 # The same trick is played by the GMP build in ../gmp.
105
106 ifneq "$(BINDIST)" "YES"
107 $(libffi_STAMP_CONFIGURE):
108         $(RM) -rf $(LIBFFI_DIR) libffi/build
109         cd libffi && $(TAR) -zxf tarball/libffi*.tar.gz
110         mv libffi/libffi-* libffi/build
111         chmod +x libffi/ln
112         cd libffi && $(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         cd libffi && $(PATCH) -p0 < libffi.autotools-update.patch
116
117         cd libffi && \
118           (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
119             PATH=`pwd`:$$PATH; \
120             export PATH; \
121             cd build && \
122             CC=$(WhatGccIsCalled) $(SHELL) configure \
123                   --enable-static=yes \
124                   --enable-shared=$(libffi_EnableShared) \
125                   --host=$(PLATFORM) --build=$(PLATFORM)
126
127         # libffi.so needs to be built with the correct soname.
128         # NOTE: this builds libffi_convience.so with the incorrect
129         # soname, but we don't need that anyway!
130         cd libffi && \
131           $(CP) build/libtool build/libtool.orig; \
132           sed -e s/soname_spec=.*/soname_spec="$(libffi_HS_DYN_LIB_NAME)"/ build/libtool.orig > build/libtool
133
134         # We don't want libtool's cygwin hacks
135         cd libffi && \
136           $(CP) build/libtool build/libtool.orig; \
137           sed -e s/dlname=\'\$$tdlname\'/dlname=\'\$$dlname\'/ build/libtool.orig > build/libtool
138
139         touch $@
140
141 libffi/ffi.h: $(libffi_STAMP_CONFIGURE)
142         $(CP) libffi/build/include/ffi.h $@
143
144 $(libffi_STAMP_BUILD): $(libffi_STAMP_CONFIGURE)
145         cd libffi && \
146           $(MAKE) -C build MAKEFLAGS=; \
147           (cd build; ./libtool --mode=install cp libffi.la $(TOP)/libffi)
148         $(CP) $(libffi_STATIC_LIB) libffi/libHSffi.a
149         $(CP) $(libffi_STATIC_LIB) libffi/libHSffi_p.a
150         touch $@
151
152 libffi/libHSffi.a libffi/libHSffi_p.a: $(libffi_STAMP_BUILD)
153
154 all_libffi : libffi/libHSffi.a libffi/libHSffi_p.a
155
156 # The GHCi import lib isn't needed as compiler/ghci/Linker.lhs + rts/Linker.c
157 # link the interpreted references to FFI to the compiled FFI.
158 # Instead of adding libffi to the list preloaded packages (see
159 # compiler/ghci/Linker.lhs:emptyPLS) we generate an empty HSffi.o
160
161 libffi/HSffi.o: libffi/libHSffi.a
162         cd libffi && \
163           touch empty.c; \
164           $(CC) -c empty.c -o HSffi.o
165
166 all_libffi : libffi/HSffi.o
167
168 ifeq "$(BuildSharedLibs)" "YES"
169 ifeq "$(Windows)" "YES"
170 # Windows libtool creates <soname>.dll, and as we already patched that
171 # there is no need to copy from libffi.dll to libHSffi...dll.
172 # However, the renaming is still required for the import library
173 # libffi.dll.a.
174 $(libffi_HS_DYN_LIB_PATH).a: $(libffi_STAMP_BUILD)
175         $(CP) libffi/libffi.dll.a $(libffi_HS_DYN_LIB_PATH).a
176 all_libffi : $(libffi_HS_DYN_LIB_PATH).a
177
178 else
179 # Rename libffi.so to libHSffi...so
180 $(libffi_HS_DYN_LIB_PATH): $(libffi_DYNAMIC_LIBS)
181         $(CP) $(word 1,$(libffi_DYNAMIC_LIBS)) $(libffi_HS_DYN_LIB_PATH)
182
183 all_libffi : $(libffi_HS_DYN_LIB_PATH)
184 endif
185 endif
186
187 $(eval $(call clean-target,libffi,, \
188    libffi/build libffi/stamp.ffi.* libffi/ffi.h libffi/empty.c \
189    libffi/libffi.a libffi/libffi.la \
190    libffi/HSffi.o libffi/libHSffi.a libffi/libHSffi_p.a \
191    $(libffi_DYNAMIC_PROG) $(libffi_DYNAMIC_LIBS) \
192    $(libffi_HS_DYN_LIB_NAME) $(libffi_HS_DYN_LIB_NAME).a))
193 endif
194
195 #-----------------------------------------------------------------------------
196 # Do the package config
197
198 $(eval $(call manual-package-config,libffi))
199
200 #-----------------------------------------------------------------------------
201 #
202 # binary-dist
203
204 BINDIST_EXTRAS += libffi/package.conf.in
205