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