FIX BUILD (Windows): Copy the ln trick used by the GMP build
[ghc.git] / libffi / Makefile
1
2 TOP=..
3
4 include $(TOP)/mk/boilerplate.mk
5
6 # -----------------------------------------------------------------------------
7 # This Makefile is copied from the one we use for GMP in ../gmp.
8 #
9 # We use libffi's own configuration stuff.
10
11 PLATFORM := $(shell echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g')
12
13 # 2007-09-26
14 # set -o igncr
15 # is not a valid command on non-Cygwin-systems.
16 # Let it fail silently instead of aborting the build.
17 #
18 # 2007-07-05
19 # We do
20 # set -o igncr; export SHELLOPTS
21 # here as otherwise checking the size of limbs
22 # makes the build fall over on Cygwin. See the thread
23 # http://www.cygwin.com/ml/cygwin/2006-12/msg00011.html
24 # for more details.
25
26 # 2007-07-05
27 # Passing
28 # as_ln_s='cp -p'
29 # isn't sufficient to stop cygwin using symlinks the mingw gcc can't
30 # follow, as it isn't used consistently. Instead we put an ln.bat in
31 # path that always fails.
32
33 LIBFFI_TARBALL := $(firstword $(wildcard libffi*.tar.gz))
34 LIBFFI_DIR := $(subst .tar.gz,,$(LIBFFI_TARBALL))
35
36 ifeq "$(findstring dyn, $(GhcRTSWays))" "dyn"
37 BUILD_SHARED=yes
38 else
39 BUILD_SHARED=no
40 endif
41
42 boot :: stamp.ffi.static
43 BINDIST_STAMPS = stamp.ffi.static
44 INSTALL_HEADERS += ffi.h
45 INSTALL_LIBS += libffi.a
46
47 ifeq "$(BUILD_SHARED)" "yes"
48 boot :: stamp.ffi.shared
49 BINDIST_STAMPS += stamp.ffi.shared
50 INSTALL_LIBS += libffi.dll.a
51 INSTALL_PROGS += libffi-3.dll
52 endif
53
54 install all :: $(INSTALL_HEADERS) $(INSTALL_LIBS) $(INSTALL_PROGS)
55
56 # We have to fake a non-working ln for configure, so that the fallback
57 # option (cp -p) gets used instead. Otherwise the libffi build system
58 # will use cygwin symbolic linkks which cannot be read by mingw gcc.
59 # The same trick is played by the GMP build in ../gmp.
60
61 stamp.ffi.static:
62 $(RM) -rf $(LIBFFI_DIR) build
63 $(TAR) -zxf $(LIBFFI_TARBALL)
64 mv $(LIBFFI_DIR) build
65 chmod +x ln
66 (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
67 PATH=`pwd`:$$PATH; \
68 export PATH; \
69 cd build && \
70 CC=$(WhatGccIsCalled) $(SHELL) configure \
71 --enable-shared=no --host=$(PLATFORM) --build=$(PLATFORM)
72 touch $@
73
74 stamp.ffi.shared:
75 $(RM) -rf $(LIBFFI_DIR) build-shared
76 $(TAR) -zxf $(LIBFFI_TARBALL)
77 mv $(LIBFFI_DIR) build-shared
78 chmod +x ln
79 (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
80 PATH=`pwd`:$$PATH; \
81 export PATH; \
82 cd build-shared && \
83 CC=$(WhatGccIsCalled) $(SHELL) configure \
84 --enable-shared=yes --disable-static --host=$(PLATFORM) --build=$(PLATFORM)
85 touch $@
86
87 ffi.h: stamp.ffi.static
88 $(CP) build/include/ffi.h .
89
90 libffi.a: stamp.ffi.static
91 $(MAKE) -C build MAKEFLAGS=
92 $(CP) build/.libs/libffi.a .
93 $(RANLIB) libffi.a
94
95 libffi-3.dll: stamp.ffi.shared
96 $(MAKE) -C build-shared MAKEFLAGS=
97 $(CP) build-shared/.libs/libffi-3.dll .
98
99 libffi.dll.a: libffi-3.dll
100 $(CP) build-shared/.libs/libffi.dll.a .
101
102 clean distclean maintainer-clean ::
103 $(RM) -f stamp.ffi.static stamp.ffi.shared ffi.h
104 $(RM) -f libffi.a libffi-3.dll libffi.dll.a
105 $(RM) -rf build
106 $(RM) -rf build-shared
107
108 #-----------------------------------------------------------------------------
109 #
110 # binary-dist
111
112 include $(TOP)/mk/target.mk
113
114 binary-dist:
115 $(INSTALL_DIR) $(BIN_DIST_DIR)/libffi
116 $(INSTALL_DATA) Makefile $(BIN_DIST_DIR)/libffi/
117 ifneq "$(HaveLibFFI)" "YES"
118 $(INSTALL_DATA) $(BINDIST_STAMPS) $(BIN_DIST_DIR)/libffi/
119 ifneq "$(INSTALL_PROGS)" ""
120 $(INSTALL_DATA) $(INSTALL_PROGS) $(BIN_DIST_DIR)/libffi/
121 endif
122 ifneq "$(INSTALL_LIBS)" ""
123 $(INSTALL_DATA) $(INSTALL_LIBS) $(BIN_DIST_DIR)/libffi/
124 endif
125 ifneq "$(INSTALL_HEADERS)" ""
126 $(INSTALL_HEADER) $(INSTALL_HEADERS) $(BIN_DIST_DIR)/libffi/
127 endif
128 endif
129