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