Comments only
[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 ifeq "$(OSTYPE)" "cygwin"
46 LIBFFI_PATH_MANGLE = PATH=$$(cygpath "$(TOP)")/libffi:$$PATH; export PATH;
47 endif
48
49 ifneq "$(BINDIST)" "YES"
50 $(libffi_STAMP_CONFIGURE): $(TOUCH_DEP)
51 $(call removeFiles,$(libffi_STAMP_STATIC_CONFIGURE))
52 $(call removeFiles,$(libffi_STAMP_STATIC_BUILD))
53 $(call removeFiles,$(libffi_STAMP_STATIC_INSTALL))
54 $(call removeFiles,$(libffi_STAMP_STATIC_SHARED_CONFIGURE))
55 $(call removeFiles,$(libffi_STAMP_STATIC_SHARED_BUILD))
56 $(call removeFiles,$(libffi_STAMP_STATIC_SHARED_INSTALL))
57 $(call removeTrees,$(LIBFFI_DIR) libffi/build)
58 cat libffi-tarballs/libffi*.tar.gz | $(GZIP_CMD) -d | { cd libffi && $(TAR_CMD) -xf - ; }
59 mv libffi/libffi-* libffi/build
60
61 # update config.guess/config.sub
62 $(CP) "$(TOP)/config.guess" libffi/build/config.guess
63 $(CP) "$(TOP)/config.sub" libffi/build/config.sub
64
65 # We have to fake a non-working ln for configure, so that the fallback
66 # option (cp -p) gets used instead. Otherwise the libffi build system
67 # will use cygwin symbolic links which cannot be read by mingw gcc.
68 chmod +x libffi/ln
69
70 # don't report nonselinux systems as selinux
71 ( cd libffi/build && "$(PATCH_CMD)" -p0 < ../libffi.x86-execstack.patch; )
72
73 # We need to use -MMD rather than -MD, as otherwise we get paths
74 # like c:/... in the dependency files on Windows, and the extra
75 # colons break make
76 mv libffi/build/Makefile.in libffi/build/Makefile.in.orig
77 sed "s/-MD/-MMD/" < libffi/build/Makefile.in.orig > libffi/build/Makefile.in
78
79 # We attempt to specify the installation directory below with --libdir,
80 # but libffi installs into 'toolexeclibdir' instead, which may differ
81 # on systems where gcc has multilib support. Force libffi to use libdir.
82 # (https://sourceware.org/ml/libffi-discuss/2014/msg00016.html)
83 mv libffi/build/Makefile.in libffi/build/Makefile.in.orig
84 sed 's:@toolexeclibdir@:$$(libdir):g' < libffi/build/Makefile.in.orig > libffi/build/Makefile.in
85
86 # Their cmd invocation only works on msys. On cygwin it starts
87 # a cmd interactive shell. The replacement works in both environments.
88 mv libffi/build/ltmain.sh libffi/build/ltmain.sh.orig
89 sed 's#cmd //c echo "\$$1"#cmd /c "echo $$1"#' < libffi/build/ltmain.sh.orig > libffi/build/ltmain.sh
90
91 # * Because -Werror may be in SRC_CC_OPTS/SRC_LD_OPTS, we need to turn
92 # warnings off or the compilation of libffi might fail due to warnings;
93 # hence the -w flags.
94 # * We specify --libdir, as we need to know the path to libffi.a, but on
95 # some platforms it defaults to .../lib64/ rather than .../lib/.
96 cd libffi && \
97 $(LIBFFI_PATH_MANGLE) \
98 cd build && \
99 CC=$(CC_STAGE1) \
100 CXX=$(CC_STAGE1) \
101 LD=$(LD) \
102 AR=$(AR_STAGE1) \
103 NM=$(NM) \
104 RANLIB=$(REAL_RANLIB_CMD) \
105 CFLAGS="$(SRC_CC_OPTS) $(CONF_CC_OPTS_STAGE1) -w" \
106 LDFLAGS="$(SRC_LD_OPTS) -w" \
107 "$(SHELL)" ./configure \
108 --prefix=$(TOP)/libffi/build/inst \
109 --libdir=$(TOP)/libffi/build/inst/lib \
110 --enable-static=yes \
111 --enable-shared=$(libffi_EnableShared) \
112 --host=$(TargetPlatformFull)
113
114 # wc on OS X has spaces in its output, which libffi's Makefile
115 # doesn't expect, so we tweak it to sed them out
116 mv libffi/build/Makefile libffi/build/Makefile.orig
117 sed "s#wc -w#wc -w | sed 's/ //g'#" < libffi/build/Makefile.orig > libffi/build/Makefile
118
119 "$(TOUCH_CMD)" $@
120
121 $(libffi_STAMP_BUILD): $(libffi_STAMP_CONFIGURE) $(TOUCH_DEP)
122 $(MAKE) -C libffi/build MAKEFLAGS=
123 "$(TOUCH_CMD)" $@
124
125 $(libffi_STAMP_INSTALL): $(libffi_STAMP_BUILD) $(TOUCH_DEP)
126 $(MAKE) -C libffi/build MAKEFLAGS= install
127 "$(TOUCH_CMD)" $@
128
129 $(libffi_STATIC_LIB): $(libffi_STAMP_INSTALL)
130 @test -f $@ || { echo "$< exists, but $@ does not."; echo "Suggest removing $<."; exit 1; }
131
132 $(libffi_HEADERS): $(libffi_STAMP_INSTALL) | $$(dir $$@)/.
133 cp -f libffi/build/inst/lib/libffi-*/include/$(notdir $@) $@
134
135 $(eval $(call clean-target,libffi,, \
136 libffi/build $(wildcard libffi/stamp.ffi.*) libffi/dist-install))
137
138 endif
139