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