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