Simplify the libffi build
[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 ifeq "$(BuildSharedLibs)" "YES"
15 libffi_STAMP_CONFIGURE = libffi/stamp.ffi.configure-shared
16 libffi_STAMP_BUILD = libffi/stamp.ffi.build-shared
17 libffi_STAMP_INSTALL = libffi/stamp.ffi.install-shared
18 else
19 libffi_STAMP_CONFIGURE = libffi/stamp.ffi.configure
20 libffi_STAMP_BUILD = libffi/stamp.ffi.build
21 libffi_STAMP_INSTALL = libffi/stamp.ffi.install
22 endif
23
24 libffi_STATIC_LIB = libffi/build/inst/lib/libffi.a
25 ffi_HEADER = rts/dist/build/ffi.h
26
27 ifeq "$(BuildSharedLibs)" "YES"
28 libffi_EnableShared=yes
29 else
30 libffi_EnableShared=no
31 endif
32
33 ifneq "$(BINDIST)" "YES"
34 $(libffi_STAMP_CONFIGURE):
35 "$(RM)" $(RM_OPTS_REC) $(LIBFFI_DIR) libffi/build
36 cat ghc-tarballs/libffi/libffi*.tar.gz | $(GZIP_CMD) -d | { cd libffi && $(TAR_CMD) -xf - ; }
37 mv libffi/libffi-* libffi/build
38
39 # We have to fake a non-working ln for configure, so that the fallback
40 # option (cp -p) gets used instead. Otherwise the libffi build system
41 # will use cygwin symbolic links which cannot be read by mingw gcc.
42 chmod +x libffi/ln
43
44 # Because -Werror may be in SRC_CC_OPTS/SRC_LD_OPTS, we need to turn
45 # warnings off or the compilation of libffi might fail due to warnings
46 cd libffi && \
47 PATH=$(TOP)/libffi:$$PATH; \
48 export PATH; \
49 cd build && \
50 CC=$(CC_STAGE1) \
51 LD=$(LD) \
52 AR=$(AR_STAGE1) \
53 NM=$(NM) \
54 CFLAGS="$(SRC_CC_OPTS) $(CONF_CC_OPTS_STAGE1) -w" \
55 LDFLAGS="$(SRC_LD_OPTS) $(CONF_GCC_LINKER_OPTS_STAGE1) -w" \
56 "$(SHELL)" configure \
57 --prefix=$(TOP)/libffi/build/inst \
58 --enable-static=yes \
59 --enable-shared=$(libffi_EnableShared) \
60 --host=$(HOSTPLATFORM) --build=$(BUILDPLATFORM)
61
62 # wc on OS X has spaces in its output, which libffi's Makefile
63 # doesn't expect, so we tweak it to sed them out
64 mv libffi/build/Makefile libffi/build/Makefile.orig
65 sed "s#wc -w#wc -w | sed 's/ //g'#" < libffi/build/Makefile.orig > libffi/build/Makefile
66
67 touch $@
68
69 $(libffi_STAMP_BUILD): $(libffi_STAMP_CONFIGURE)
70 $(MAKE) -C libffi/build MAKEFLAGS=
71 touch $@
72
73 $(libffi_STAMP_INSTALL): $(libffi_STAMP_BUILD)
74 $(MAKE) -C libffi/build MAKEFLAGS= install
75 touch $@
76
77 $(libffi_STATIC_LIB): $(libffi_STAMP_INSTALL)
78 @test -f $@ || { echo "$< exists, but $@ does not."; echo "Suggest removing $<."; exit 1; }
79
80 $(ffi_HEADER): $(libffi_STAMP_INSTALL) | $$(dir $$@)/.
81 cp libffi/build/inst/lib/libffi-*/include/ffitarget.h $(dir $@)
82 cp libffi/build/inst/lib/libffi-*/include/ffi.h $@
83
84 $(eval $(call clean-target,libffi,, \
85 libffi/build libffi/stamp.ffi.* libffi/dist-install))
86
87 endif
88