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