Resurrect UseLibFFIForAdjustors from bitrot.
[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://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
9 # http://hackage.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 "$(OSTYPE)" "cygwin"
39 LIBFFI_PATH_MANGLE = PATH=$$(cygpath "$(TOP)")/libffi:$$PATH; export PATH;
40 endif
41
42 ifneq "$(BINDIST)" "YES"
43 $(libffi_STAMP_CONFIGURE): $(TOUCH_DEP)
44 $(call removeFiles,$(libffi_STAMP_STATIC_CONFIGURE))
45 $(call removeFiles,$(libffi_STAMP_STATIC_BUILD))
46 $(call removeFiles,$(libffi_STAMP_STATIC_INSTALL))
47 $(call removeFiles,$(libffi_STAMP_STATIC_SHARED_CONFIGURE))
48 $(call removeFiles,$(libffi_STAMP_STATIC_SHARED_BUILD))
49 $(call removeFiles,$(libffi_STAMP_STATIC_SHARED_INSTALL))
50 $(call removeTrees,$(LIBFFI_DIR) libffi/build)
51 cat ghc-tarballs/libffi/libffi*.tar.gz | $(GZIP_CMD) -d | { cd libffi && $(TAR_CMD) -xf - ; }
52 mv libffi/libffi-* libffi/build
53
54 # We have to fake a non-working ln for configure, so that the fallback
55 # option (cp -p) gets used instead. Otherwise the libffi build system
56 # will use cygwin symbolic links which cannot be read by mingw gcc.
57 chmod +x libffi/ln
58
59 # We need to use -MMD rather than -MD, as otherwise we get paths
60 # like c:/... in the dependency files on Windows, and the extra
61 # colons break make
62 mv libffi/build/Makefile.in libffi/build/Makefile.in.orig
63 sed "s/-MD/-MMD/" < libffi/build/Makefile.in.orig > libffi/build/Makefile.in
64
65 # Their cmd invocation only works on msys. On cygwin it starts
66 # a cmd interactive shell. The replacement works in both environments.
67 mv libffi/build/ltmain.sh libffi/build/ltmain.sh.orig
68 sed 's#cmd //c echo "\$$1"#cmd /c "echo $$1"#' < libffi/build/ltmain.sh.orig > libffi/build/ltmain.sh
69
70 # Because -Werror may be in SRC_CC_OPTS/SRC_LD_OPTS, we need to turn
71 # warnings off or the compilation of libffi might fail due to warnings
72 cd libffi && \
73 $(LIBFFI_PATH_MANGLE) \
74 cd build && \
75 CC=$(CC_STAGE1) \
76 LD=$(LD) \
77 AR=$(AR_STAGE1) \
78 NM=$(NM) \
79 CFLAGS="$(SRC_CC_OPTS) $(CONF_CC_OPTS_STAGE1) -w" \
80 LDFLAGS="$(SRC_LD_OPTS) $(CONF_GCC_LINKER_OPTS_STAGE1) -w" \
81 "$(SHELL)" configure \
82 --prefix=$(TOP)/libffi/build/inst \
83 --enable-static=yes \
84 --enable-shared=$(libffi_EnableShared) \
85 --host=$(HOSTPLATFORM) --build=$(BUILDPLATFORM)
86
87 # wc on OS X has spaces in its output, which libffi's Makefile
88 # doesn't expect, so we tweak it to sed them out
89 mv libffi/build/Makefile libffi/build/Makefile.orig
90 sed "s#wc -w#wc -w | sed 's/ //g'#" < libffi/build/Makefile.orig > libffi/build/Makefile
91
92 "$(TOUCH_CMD)" $@
93
94 $(libffi_STAMP_BUILD): $(libffi_STAMP_CONFIGURE) $(TOUCH_DEP)
95 $(MAKE) -C libffi/build MAKEFLAGS=
96 "$(TOUCH_CMD)" $@
97
98 $(libffi_STAMP_INSTALL): $(libffi_STAMP_BUILD) $(TOUCH_DEP)
99 $(MAKE) -C libffi/build MAKEFLAGS= install
100 "$(TOUCH_CMD)" $@
101
102 $(libffi_STATIC_LIB): $(libffi_STAMP_INSTALL)
103 @test -f $@ || { echo "$< exists, but $@ does not."; echo "Suggest removing $<."; exit 1; }
104
105 $(libffi_HEADERS): $(libffi_STAMP_INSTALL) | $$(dir $$@)/.
106 cp -f libffi/build/inst/lib/libffi-*/include/$(notdir $@) $@
107
108 $(eval $(call clean-target,libffi,, \
109 libffi/build $(wildcard libffi/stamp.ffi.*) libffi/dist-install))
110
111 endif
112