Fix GMP v4 compatibility.
[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 # We use a tarball like gmp-4.2.4-nodoc.tar.bz2, which is
14 # gmp-4.2.4.tar.bz2 repacked without the doc/ directory contents.
15 # That's because the doc/ directory contents are under the GFDL,
16 # which causes problems for Debian.
17
18 GMP_TARBALL := $(wildcard libraries/integer-gmp/gmp/tarball/gmp*.tar.bz2)
19 GMP_DIR := $(patsubst libraries/integer-gmp/gmp/tarball/%-nodoc-patched.tar.bz2,%,$(GMP_TARBALL))
20
21 ifneq "$(NO_CLEAN_GMP)" "YES"
22 $(eval $(call clean-target,gmp,,\
23 libraries/integer-gmp/gmp/config.mk \
24 libraries/integer-gmp/gmp/libgmp.a \
25 libraries/integer-gmp/gmp/gmp.h \
26 libraries/integer-gmp/gmp/gmpbuild \
27 libraries/integer-gmp/gmp/$(GMP_DIR)))
28
29 clean : clean_gmp
30 .PHONY: clean_gmp
31 clean_gmp:
32 $(call removeTrees,libraries/integer-gmp/gmp/objs)
33 $(call removeTrees,libraries/integer-gmp/gmp/gmpbuild)
34 endif
35
36 ifeq "$(Windows_Host)" "YES"
37 # Apparently building on Windows fails when there is a system gmp
38 # available, so we never try to use the system gmp on Windows
39 libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-intree-gmp
40 endif
41
42 ifeq "$(GMP_PREFER_FRAMEWORK)" "YES"
43 libraries/integer-gmp_CONFIGURE_OPTS += --with-gmp-framework-preferred
44 endif
45
46 ifeq "$(phase)" "final"
47
48 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
49 include libraries/integer-gmp/gmp/config.mk
50 endif
51
52 libraries/integer-gmp_dist-install_EXTRA_CC_OPTS += -Ilibraries/integer-gmp/mkGmpDerivedConstants/dist
53 libraries/integer-gmp_dist-install_EXTRA_HC_OPTS += -Ilibraries/integer-gmp/mkGmpDerivedConstants/dist
54
55 gmp_CC_OPTS += $(addprefix -I,$(GMP_INCLUDE_DIRS))
56 gmp_CC_OPTS += $(addprefix -L,$(GMP_LIB_DIRS))
57
58 # Compile GMP only if we don't have it already
59 #
60 # We use GMP's own configuration stuff, because it's all rather hairy
61 # and not worth re-implementing in our Makefile framework.
62
63 ifeq "$(findstring dyn, $(GhcRTSWays))" "dyn"
64 BUILD_SHARED=yes
65 else
66 BUILD_SHARED=no
67 endif
68
69 # In a bindist, we don't want to know whether /this/ machine has gmp,
70 # but whether the machine the bindist was built on had gmp.
71 ifeq "$(BINDIST)" "YES"
72 ifeq "$(wildcard libraries/integer-gmp/gmp/libgmp.a)" ""
73 HaveLibGmp = YES
74 HaveFrameworkGMP = YES
75 else
76 HaveLibGmp = NO
77 HaveFrameworkGMP = NO
78 endif
79 endif
80
81 $(libraries/integer-gmp_dist-install_depfile_c_asm): $$(GmpDerivedConstants_HEADER)
82
83 ifneq "$(HaveLibGmp)" "YES"
84 ifneq "$(HaveFrameworkGMP)" "YES"
85 $(libraries/integer-gmp_dist-install_depfile_c_asm): libraries/integer-gmp/gmp/gmp.h
86
87 gmp_CC_OPTS += -Ilibraries/integer-gmp/gmp
88 gmp_CC_OPTS += -Ilibraries/integer-gmp/mkGmpDerivedConstants/dist
89
90 libraries/integer-gmp_dist-install_EXTRA_OBJS += libraries/integer-gmp/gmp/objs/*.o
91
92 #INSTALL_LIBS += libraries/integer-gmp/gmp/libgmp.a
93 #INSTALL_HEADERS += libraries/integer-gmp/gmp/gmp.h
94 #
95 #$(eval $(call all-target,gmp_dynamic,libraries/integer-gmp/gmp/libgmp.a))
96 #
97 #ifeq "$(BUILD_SHARED)" "yes"
98 #$(eval $(call all-target,gmp_dynamic,libraries/integer-gmp/gmp/libgmp.dll.a libraries/integer-gmp/gmp/libgmp-3.dll))
99 #endif
100
101 endif
102 endif
103
104 libraries/integer-gmp_dist-install_EXTRA_CC_OPTS += $(gmp_CC_OPTS)
105
106 CLANG = $(findstring clang, $(shell $(CC_STAGE1) --version))
107
108 ifeq "$(CLANG)" "clang"
109 CCX = $(CLANG)
110 else
111 CCX = $(CC_STAGE1)
112 endif
113
114 # 2007-09-26
115 # set -o igncr
116 # is not a valid command on non-Cygwin-systems.
117 # Let it fail silently instead of aborting the build.
118 #
119 # 2007-07-05
120 # We do
121 # set -o igncr; export SHELLOPTS
122 # here as otherwise checking the size of limbs
123 # makes the build fall over on Cygwin. See the thread
124 # http://www.cygwin.com/ml/cygwin/2006-12/msg00011.html
125 # for more details.
126
127 # 2007-07-05
128 # Passing
129 # as_ln_s='cp -p'
130 # isn't sufficient to stop cygwin using symlinks the mingw gcc can't
131 # follow, as it isn't used consistently. Instead we put an ln.bat in
132 # path that always fails.
133
134 libraries/integer-gmp/gmp/libgmp.a libraries/integer-gmp/gmp/gmp.h:
135 $(RM) -rf libraries/integer-gmp/gmp/$(GMP_DIR) libraries/integer-gmp/gmp/gmpbuild libraries/integer-gmp/gmp/objs
136 cat $(GMP_TARBALL) | $(BZIP2_CMD) -d | { cd libraries/integer-gmp/gmp && $(TAR_CMD) -xf - ; }
137 mv libraries/integer-gmp/gmp/$(GMP_DIR) libraries/integer-gmp/gmp/gmpbuild
138 chmod +x libraries/integer-gmp/gmp/ln
139
140 # Their cmd invocation only works on msys. On cygwin it starts
141 # a cmd interactive shell. The replacement works in both environments.
142 mv libraries/integer-gmp/gmp/gmpbuild/ltmain.sh libraries/integer-gmp/gmp/gmpbuild/ltmain.sh.orig
143 sed 's#cmd //c echo "\$$1"#cmd /c "echo $$1"#' < libraries/integer-gmp/gmp/gmpbuild/ltmain.sh.orig > libraries/integer-gmp/gmp/gmpbuild/ltmain.sh
144
145 cd libraries/integer-gmp/gmp; (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
146 PATH=`pwd`:$$PATH; \
147 export PATH; \
148 cd gmpbuild && \
149 CC=$(CCX) NM=$(NM) AR=$(AR_STAGE1) $(SHELL) ./configure \
150 --enable-shared=no \
151 --host=$(HOSTPLATFORM) --build=$(BUILDPLATFORM)
152 $(MAKE) -C libraries/integer-gmp/gmp/gmpbuild MAKEFLAGS=
153 $(CP) libraries/integer-gmp/gmp/gmpbuild/gmp.h libraries/integer-gmp/gmp/
154 $(CP) libraries/integer-gmp/gmp/gmpbuild/.libs/libgmp.a libraries/integer-gmp/gmp/
155 $(MKDIRHIER) libraries/integer-gmp/gmp/objs
156 cd libraries/integer-gmp/gmp/objs && $(AR_STAGE1) x ../libgmp.a
157 $(RANLIB_CMD) libraries/integer-gmp/gmp/libgmp.a
158
159 # XXX TODO:
160 #stamp.gmp.shared:
161 # $(RM) -rf $(GMP_DIR) gmpbuild-shared
162 # $(TAR_CMD) -zxf $(GMP_TARBALL)
163 # mv $(GMP_DIR) gmpbuild-shared
164 # chmod +x ln
165 # (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
166 # PATH=`pwd`:$$PATH; \
167 # export PATH; \
168 # cd gmpbuild-shared && \
169 # CC=$(CC_STAGE1) $(SHELL) ./configure \
170 # --enable-shared=yes --disable-static \
171 # --host=$(HOSTPLATFORM) --build=$(BUILDPLATFORM)
172 # "$(TOUCH_CMD)" $@
173 #
174 #gmp.h: stamp.gmp.static
175 # $(CP) gmpbuild/gmp.h .
176 #
177 #libgmp.a: stamp.gmp.static
178 #
179 #libgmp-3.dll: stamp.gmp.shared
180 # $(MAKE) -C gmpbuild-shared MAKEFLAGS=
181 # $(CP) gmpbuild-shared/.libs/libgmp-3.dll .
182 #
183 #libgmp.dll.a: libgmp-3.dll
184 # $(CP) gmpbuild-shared/.libs/libgmp.dll.a .
185
186 ## GMP takes a long time to build, but changes rarely. Hence we don't
187 ## bother cleaning it before validating, because that adds a
188 ## significant overhead to validation.
189 #ifeq "$(Validating)" "NO"
190 #clean distclean maintainer-clean ::
191 # $(RM) -f stamp.gmp.static stamp.gmp.shared
192 # $(RM) -rf gmpbuild
193 # $(RM) -rf gmpbuild-shared
194 #endif
195
196 endif
197