Fix building libgmp on cygwin
[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 "$(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
129 # Their cmd invocation only works on msys. On cygwin it starts
130 # a cmd interactive shell. The replacement works in both environments.
131 mv libraries/integer-gmp/gmp/gmpbuild/ltmain.sh libraries/integer-gmp/gmp/gmpbuild/ltmain.sh.orig
132 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
133
134 cd libraries/integer-gmp/gmp; (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
135 PATH=`pwd`:$$PATH; \
136 export PATH; \
137 cd gmpbuild && \
138 CC=$(CC_STAGE1) NM=$(NM) AR=$(AR_STAGE1) $(SHELL) configure \
139 --enable-shared=no \
140 --host=$(HOSTPLATFORM) --build=$(BUILDPLATFORM)
141 $(MAKE) -C libraries/integer-gmp/gmp/gmpbuild MAKEFLAGS=
142 $(CP) libraries/integer-gmp/gmp/gmpbuild/gmp.h libraries/integer-gmp/gmp/
143 $(CP) libraries/integer-gmp/gmp/gmpbuild/.libs/libgmp.a libraries/integer-gmp/gmp/
144 $(MKDIRHIER) libraries/integer-gmp/gmp/objs
145 cd libraries/integer-gmp/gmp/objs && $(AR_STAGE1) x ../libgmp.a
146 $(RANLIB) libraries/integer-gmp/gmp/libgmp.a
147
148 # XXX TODO:
149 #stamp.gmp.shared:
150 # $(RM) -rf $(GMP_DIR) gmpbuild-shared
151 # $(TAR_CMD) -zxf $(GMP_TARBALL)
152 # mv $(GMP_DIR) gmpbuild-shared
153 # chmod +x ln
154 # (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
155 # PATH=`pwd`:$$PATH; \
156 # export PATH; \
157 # cd gmpbuild-shared && \
158 # CC=$(CC_STAGE1) $(SHELL) configure \
159 # --enable-shared=yes --disable-static \
160 # --host=$(HOSTPLATFORM) --build=$(BUILDPLATFORM)
161 # "$(TOUCH_CMD)" $@
162 #
163 #gmp.h: stamp.gmp.static
164 # $(CP) gmpbuild/gmp.h .
165 #
166 #libgmp.a: stamp.gmp.static
167 #
168 #libgmp-3.dll: stamp.gmp.shared
169 # $(MAKE) -C gmpbuild-shared MAKEFLAGS=
170 # $(CP) gmpbuild-shared/.libs/libgmp-3.dll .
171 #
172 #libgmp.dll.a: libgmp-3.dll
173 # $(CP) gmpbuild-shared/.libs/libgmp.dll.a .
174
175 ## GMP takes a long time to build, but changes rarely. Hence we don't
176 ## bother cleaning it before validating, because that adds a
177 ## significant overhead to validation.
178 #ifeq "$(Validating)" "NO"
179 #clean distclean maintainer-clean ::
180 # $(RM) -f stamp.gmp.static stamp.gmp.shared
181 # $(RM) -rf gmpbuild
182 # $(RM) -rf gmpbuild-shared
183 #endif
184
185 endif
186