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