Don't use /dev/null trick to create empty object files in libffi/Makefile
[ghc.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 += $(STATIC_LIB)
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 += $(DYNAMIC_LIBS)
84 INSTALL_PROGS += $(DYNAMIC_PROGS)
85 endif
86
87 install all :: $(INSTALL_HEADERS) $(INSTALL_LIBS) $(INSTALL_PROGS)
88
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.
93
94 stamp.ffi.configure:
95 $(RM) -rf $(LIBFFI_DIR) build
96 $(TAR) -zxf $(LIBFFI_TARBALL)
97 mv $(LIBFFI_DIR) build
98 chmod +x ln
99 (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
100 PATH=`pwd`:$$PATH; \
101 export PATH; \
102 cd build && \
103 CC=$(WhatGccIsCalled) $(SHELL) configure \
104 --enable-static=yes \
105 --enable-shared=$(EnableShared) \
106 --host=$(PLATFORM) --build=$(PLATFORM)
107
108 # libffi.so needs to be built with the correct soname.
109 # NOTE: this builds libffi_convience.so with the incorrect
110 # soname, but we don't need that anyway!
111 sed -i -e s/soname_spec=.*/soname_spec="$(HS_DYN_LIB_NAME)"/ build/libtool
112 touch $@
113
114 ffi.h: stamp.ffi.configure
115 $(CP) build/include/ffi.h .
116
117 stamp.ffi.build: stamp.ffi.configure
118 $(MAKE) -C build MAKEFLAGS=
119 (cd build; ./libtool --mode=install cp libffi.la $(FPTOOLS_TOP_ABS)/libffi)
120 touch $@
121
122 $(STATIC_LIB) $(DYNAMIC_LIBS) $(DYNAMIC_PROG): stamp.ffi.build
123
124 libHSffi.a libHSffi_p.a: $(STATIC_LIB)
125 cp $(STATIC_LIB) $@
126
127 all :: libHSffi.a libHSffi_p.a
128
129 # The GHCi import lib isn't needed as compiler/ghci/Linker.lhs + rts/Linker.c
130 # link the interpreted references to FFI to the compiled FFI.
131 # Instead of adding libffi to the list preloaded packages (see
132 # compiler/ghci/Linker.lhs:emptyPLS) we generate an empty HSffi.o
133
134 HSffi.o: libHSffi.a
135 touch empty.c
136 $(CC) -c empty.c -o HSffi.o
137
138 all :: HSffi.o
139
140 ifeq "$(BuildSharedLibs)" "YES"
141 $(HS_DYN_LIB_NAME): $(DYNAMIC_LIBS)
142 cp $(word 1,$(DYNAMIC_LIBS)) $(HS_DYN_LIB_NAME)
143
144 all :: $(HS_DYN_LIB_NAME)
145 endif
146
147 clean distclean maintainer-clean ::
148 $(RM) -f stamp.ffi.configure stamp.ffi.build ffi.h empty.c
149 $(RM) -f libffi.a libffi.la $(DYNAMIC_PROG) $(DYNAMIC_LIBS) $(ORIG_DYNAMIC_LIBS)
150 $(RM) -rf build
151
152 #-----------------------------------------------------------------------------
153 #
154 # binary-dist
155
156 include $(TOP)/mk/target.mk
157
158 BINDIST_EXTRAS += $(BINDIST_STAMPS)
159 BINDIST_EXTRAS += $(INSTALL_PROGS)
160 BINDIST_EXTRAS += $(INSTALL_LIBS)
161 BINDIST_EXTRAS += $(INSTALL_HEADERS)
162 include $(TOP)/mk/bindist.mk
163