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