1a71e17878a6ce109f9cdd9191a08dc45f8e1bc4
[ghc-hetmet.git] / gmp / ghc.mk
1
2 # Compile GMP only if we don't have it already
3 #
4 # We use GMP's own configuration stuff, because it's all rather hairy
5 # and not worth re-implementing in our Makefile framework.
6
7 ifeq "$(findstring dyn, $(GhcRTSWays))" "dyn"
8 BUILD_SHARED=yes
9 else
10 BUILD_SHARED=no
11 endif
12
13 # In a bindist, we don't want to know whether /this/ machine has gmp,
14 # but whether the machine the bindist was built on had gmp.
15 ifeq "$(BINDIST)" "YES"
16 ifeq "$(wildcard gmp/libgmp.a)" ""
17 HaveLibGmp = YES
18 HaveFrameworkGMP = YES
19 else
20 HaveLibGmp = NO
21 HaveFrameworkGMP = NO
22 endif
23 endif
24
25 ifneq "$(HaveLibGmp)" "YES"
26 ifneq "$(HaveFrameworkGMP)" "YES"
27
28 INSTALL_LIBS += gmp/libgmp.a
29
30 $(eval $(call all-target,gmp_dynamic,gmp/libgmp.a))
31
32 ifeq "$(BUILD_SHARED)" "yes"
33 $(eval $(call all-target,gmp_dynamic,gmp/libgmp.dll.a gmp/libgmp-3.dll))
34 endif
35
36 endif
37 endif
38
39 PLATFORM := $(shell echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g')
40
41 # 2007-09-26
42 #     set -o igncr 
43 # is not a valid command on non-Cygwin-systems.
44 # Let it fail silently instead of aborting the build.
45 #
46 # 2007-07-05
47 # We do
48 #     set -o igncr; export SHELLOPTS
49 # here as otherwise checking the size of limbs
50 # makes the build fall over on Cygwin. See the thread
51 # http://www.cygwin.com/ml/cygwin/2006-12/msg00011.html
52 # for more details.
53
54 # 2007-07-05
55 # Passing
56 #     as_ln_s='cp -p'
57 # isn't sufficient to stop cygwin using symlinks the mingw gcc can't
58 # follow, as it isn't used consistently. Instead we put an ln.bat in
59 # path that always fails.
60
61 # We use a tarball like gmp-4.2.4-nodoc.tar.bz2, which is
62 # gmp-4.2.4.tar.bz2 repacked without the doc/ directory contents.
63 # That's because the doc/ directory contents are under the GFDL,
64 # which causes problems for Debian.
65
66 GMP_TARBALL := $(wildcard gmp/tarball/gmp*.tar.bz2)
67 GMP_DIR := $(patsubst gmp/tarball/%-nodoc.tar.bz2,%,$(GMP_TARBALL))
68
69 # XXX INSTALL_HEADERS += gmp.h
70
71 gmp/libgmp.a:
72         $(RM) -rf $(GMP_DIR) gmp/gmpbuild
73         cd gmp && $(TAR) -jxf ../$(GMP_TARBALL)
74         mv gmp/$(GMP_DIR) gmp/gmpbuild
75         chmod +x gmp/ln
76         cd gmp; (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
77             PATH=`pwd`:$$PATH; \
78             export PATH; \
79             cd gmpbuild && \
80             CC=$(WhatGccIsCalled) $(SHELL) configure \
81                   --enable-shared=no --host=$(PLATFORM) --build=$(PLATFORM)
82         $(MAKE) -C gmp/gmpbuild MAKEFLAGS=
83         $(CP) gmp/gmpbuild/.libs/libgmp.a gmp/
84         $(RANLIB) gmp/libgmp.a
85
86 $(eval $(call clean-target,gmp,,\
87   gmp/libgmp.a gmp/gmpbuild gmp/$(GMP_DIR)))
88
89 # XXX TODO:
90 #stamp.gmp.shared:
91 #       $(RM) -rf $(GMP_DIR) gmpbuild-shared
92 #       $(TAR) -zxf $(GMP_TARBALL)
93 #       mv $(GMP_DIR) gmpbuild-shared
94 #       chmod +x ln
95 #       (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
96 #           PATH=`pwd`:$$PATH; \
97 #           export PATH; \
98 #           cd gmpbuild-shared && \
99 #           CC=$(WhatGccIsCalled) $(SHELL) configure \
100 #                 --enable-shared=yes --disable-static --host=$(PLATFORM) --build=$(PLATFORM)
101 #       touch $@
102 #
103 #gmp.h: stamp.gmp.static
104 #       $(CP) gmpbuild/gmp.h .
105 #
106 #libgmp.a: stamp.gmp.static
107 #
108 #libgmp-3.dll: stamp.gmp.shared
109 #       $(MAKE) -C gmpbuild-shared MAKEFLAGS=
110 #       $(CP) gmpbuild-shared/.libs/libgmp-3.dll .
111 #
112 #libgmp.dll.a: libgmp-3.dll
113 #       $(CP) gmpbuild-shared/.libs/libgmp.dll.a .
114
115 ## GMP takes a long time to build, but changes rarely.  Hence we don't
116 ## bother cleaning it before validating, because that adds a
117 ## significant overhead to validation.
118 #ifeq "$(Validating)" "NO"
119 #clean distclean maintainer-clean ::
120 #       $(RM) -f stamp.gmp.static stamp.gmp.shared
121 #       $(RM) -rf gmpbuild
122 #       $(RM) -rf gmpbuild-shared
123 #endif
124