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