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