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