08f5e4d40a944a589f954475dcc306ca91d29ca9
[ghc.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://ghc.haskell.org/trac/ghc/wiki/Building/Architecture
9 # http://ghc.haskell.org/trac/ghc/wiki/Building/Modifying
10 #
11 # -----------------------------------------------------------------------------
12
13
14 libffi_STAMP_STATIC_CONFIGURE = libffi/stamp.ffi.static.configure
15 libffi_STAMP_STATIC_BUILD = libffi/stamp.ffi.static.build
16 libffi_STAMP_STATIC_INSTALL = libffi/stamp.ffi.static.install
17
18 libffi_STAMP_STATIC_SHARED_CONFIGURE = libffi/stamp.ffi.static-shared.configure
19 libffi_STAMP_STATIC_SHARED_BUILD = libffi/stamp.ffi.static-shared.build
20 libffi_STAMP_STATIC_SHARED_INSTALL = libffi/stamp.ffi.static-shared.install
21
22 ifeq "$(BuildSharedLibs)" "YES"
23 libffi_STAMP_CONFIGURE = $(libffi_STAMP_STATIC_SHARED_CONFIGURE)
24 libffi_STAMP_BUILD = $(libffi_STAMP_STATIC_SHARED_BUILD)
25 libffi_STAMP_INSTALL = $(libffi_STAMP_STATIC_SHARED_INSTALL)
26 libffi_EnableShared = yes
27 else
28 libffi_STAMP_CONFIGURE = $(libffi_STAMP_STATIC_CONFIGURE)
29 libffi_STAMP_BUILD = $(libffi_STAMP_STATIC_BUILD)
30 libffi_STAMP_INSTALL = $(libffi_STAMP_STATIC_INSTALL)
31 libffi_EnableShared = no
32 endif
33
34 libffi_STATIC_LIB = libffi/build/inst/lib/libffi.a
35 libffi_HEADERS = rts/dist/build/ffi.h \
36 rts/dist/build/ffitarget.h
37
38 ifeq "$(HostOS_CPP)" "mingw32"
39 LIBFFI_NAME = ffi-6
40 else
41 LIBFFI_NAME = ffi
42 endif
43 LIBFFI_DLL = lib$(LIBFFI_NAME).dll
44
45 ifneq "$(BINDIST)" "YES"
46 $(libffi_STAMP_CONFIGURE): $(TOUCH_DEP)
47 $(call removeFiles,$(libffi_STAMP_STATIC_CONFIGURE))
48 $(call removeFiles,$(libffi_STAMP_STATIC_BUILD))
49 $(call removeFiles,$(libffi_STAMP_STATIC_INSTALL))
50 $(call removeFiles,$(libffi_STAMP_STATIC_SHARED_CONFIGURE))
51 $(call removeFiles,$(libffi_STAMP_STATIC_SHARED_BUILD))
52 $(call removeFiles,$(libffi_STAMP_STATIC_SHARED_INSTALL))
53 git clean -x -f -d libffi/build
54 cd libffi/build && ./autogen.sh
55
56 # update config.guess/config.sub
57 $(CP) "$(TOP)/config.guess" libffi/build/config.guess
58 $(CP) "$(TOP)/config.sub" libffi/build/config.sub
59
60 # We have to fake a non-working ln for configure, so that the fallback
61 # option (cp -p) gets used instead. Otherwise the libffi build system
62 # will use cygwin symbolic links which cannot be read by mingw gcc.
63 chmod +x libffi/ln
64
65 # We need to use -MMD rather than -MD, as otherwise we get paths
66 # like c:/... in the dependency files on Windows, and the extra
67 # colons break make
68 mv libffi/build/Makefile.in libffi/build/Makefile.in.orig
69 sed "s/-MD/-MMD/" < libffi/build/Makefile.in.orig > libffi/build/Makefile.in
70
71 # We attempt to specify the installation directory below with --libdir,
72 # but libffi installs into 'toolexeclibdir' instead, which may differ
73 # on systems where gcc has multilib support. Force libffi to use libdir.
74 # (https://sourceware.org/ml/libffi-discuss/2014/msg00016.html)
75 mv libffi/build/Makefile.in libffi/build/Makefile.in.orig
76 sed 's:@toolexeclibdir@:$$(libdir):g' < libffi/build/Makefile.in.orig > libffi/build/Makefile.in
77
78 # install-sh is used when /usr/bin/install is missing; ensure its
79 # path in libffi's Makefile is correct. See GHC #11109.
80 mv libffi/build/Makefile.in libffi/build/Makefile.in.orig
81 sed 's|@INSTALL@|$$(subst ../install-sh,$(TOP)/install-sh,@INSTALL@)|g' < libffi/build/Makefile.in.orig > libffi/build/Makefile.in
82
83 # * Because -Werror may be in SRC_CC_OPTS/SRC_LD_OPTS, we need to turn
84 # warnings off or the compilation of libffi might fail due to warnings;
85 # hence the -w flags.
86 # * We specify --libdir, as we need to know the path to libffi.a, but on
87 # some platforms it defaults to .../lib64/ rather than .../lib/.
88 cd libffi && \
89 cd build && \
90 CC=$(CC_STAGE1) \
91 CXX=$(CC_STAGE1) \
92 LD=$(LD) \
93 AR=$(AR_STAGE1) \
94 NM=$(NM) \
95 RANLIB=$(REAL_RANLIB_CMD) \
96 CFLAGS="$(SRC_CC_OPTS) $(CONF_CC_OPTS_STAGE1) -w" \
97 LDFLAGS="$(SRC_LD_OPTS) -w" \
98 "$(SHELL)" ./configure \
99 --prefix=$(TOP)/libffi/build/inst \
100 --libdir=$(TOP)/libffi/build/inst/lib \
101 --enable-static=yes \
102 --enable-shared=$(libffi_EnableShared) \
103 --host=$(TargetPlatformFull)
104
105 # wc on OS X has spaces in its output, which libffi's Makefile
106 # doesn't expect, so we tweak it to sed them out
107 mv libffi/build/Makefile libffi/build/Makefile.orig
108 sed "s#wc -w#wc -w | sed 's/ //g'#" < libffi/build/Makefile.orig > libffi/build/Makefile
109
110 "$(TOUCH_CMD)" $@
111
112 $(libffi_STAMP_BUILD): $(libffi_STAMP_CONFIGURE) $(TOUCH_DEP)
113 # Use 'sync' as a temporary solution for #11960 (parallelisation bug).
114 sync; $(MAKE) -C libffi/build MAKEFLAGS=
115 "$(TOUCH_CMD)" $@
116
117 $(libffi_STAMP_INSTALL): $(libffi_STAMP_BUILD) $(TOUCH_DEP)
118 $(MAKE) -C libffi/build MAKEFLAGS= install
119 "$(TOUCH_CMD)" $@
120
121 $(libffi_STATIC_LIB): $(libffi_STAMP_INSTALL)
122 @test -f $@ || { echo "$< exists, but $@ does not."; echo "Suggest removing $<."; exit 1; }
123
124 $(libffi_HEADERS): $(libffi_STAMP_INSTALL) | $$(dir $$@)/.
125 cp -f libffi/build/inst/include/$(notdir $@) $@
126
127 $(eval $(call clean-target,libffi,, \
128 $(wildcard libffi/stamp.ffi.*) libffi/dist-install))
129
130 endif
131