Build: ./boot && ./configure && make sdist (#8723)
[ghc.git] / libraries / integer-gmp / 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://ghc.haskell.org/trac/ghc/wiki/Building/Architecture
9 # http://ghc.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/include/ghc-gmp.h \
24 libraries/integer-gmp/gmp/config.mk \
25 libraries/integer-gmp/gmp/libgmp.a \
26 libraries/integer-gmp/gmp/gmp.h \
27 libraries/integer-gmp/gmp/gmpbuild \
28 libraries/integer-gmp/gmp/$(GMP_DIR)))
29
30 clean : clean_gmp
31 .PHONY: clean_gmp
32 clean_gmp:
33 $(call removeTrees,libraries/integer-gmp/gmp/objs)
34 $(call removeTrees,libraries/integer-gmp/gmp/gmpbuild)
35 endif
36
37 ifeq "$(Windows_Host)" "YES"
38 # Apparently building on Windows fails when there is a system gmp
39 # available, so we never try to use the system gmp on Windows
40 libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-intree-gmp
41 endif
42
43 ifeq "$(GMP_PREFER_FRAMEWORK)" "YES"
44 libraries/integer-gmp_CONFIGURE_OPTS += --with-gmp-framework-preferred
45 endif
46
47 ifeq "$(phase)" "final"
48
49 ifneq "$(CLEANING)" "YES"
50 # Hack. The file gmp/config.mk doesn't exist yet after running ./configure in
51 # the toplevel (ghc) directory. To let some toplevel make commands such as
52 # sdist go through, right after ./configure, don't consider this an error.
53 -include libraries/integer-gmp/gmp/config.mk
54 endif
55
56 gmp_CC_OPTS += $(addprefix -I,$(GMP_INCLUDE_DIRS))
57 gmp_CC_OPTS += $(addprefix -L,$(GMP_LIB_DIRS))
58
59 # Compile GMP only if we don't have it already
60 #
61 # We use GMP's own configuration stuff, because it's all rather hairy
62 # and not worth re-implementing in our Makefile framework.
63
64 ifeq "$(findstring dyn, $(GhcRTSWays))" "dyn"
65 BUILD_SHARED=yes
66 else
67 BUILD_SHARED=no
68 endif
69
70 # In a bindist, we don't want to know whether /this/ machine has gmp,
71 # but whether the machine the bindist was built on had gmp.
72 ifeq "$(BINDIST)" "YES"
73 ifeq "$(wildcard libraries/integer-gmp/gmp/libgmp.a)" ""
74 HaveLibGmp = YES
75 HaveFrameworkGMP = YES
76 else
77 HaveLibGmp = NO
78 HaveFrameworkGMP = NO
79 endif
80 endif
81
82 UseIntreeGmp = NO
83 ifneq "$(HaveLibGmp)" "YES"
84 ifneq "$(HaveFrameworkGMP)" "YES"
85 UseIntreeGmp = YES
86 endif
87 endif
88
89 ifeq "$(UseIntreeGmp)" "YES"
90 $(libraries/integer-gmp_dist-install_depfile_c_asm): libraries/integer-gmp/gmp/gmp.h libraries/integer-gmp/include/ghc-gmp.h
91
92 libraries/integer-gmp/include/ghc-gmp.h: libraries/integer-gmp/gmp/gmp.h
93 $(CP) $< $@
94
95 gmp_CC_OPTS += -Ilibraries/integer-gmp/gmp
96
97 libraries/integer-gmp_dist-install_EXTRA_OBJS += libraries/integer-gmp/gmp/objs/*.o
98 else
99 $(libraries/integer-gmp_dist-install_depfile_c_asm): libraries/integer-gmp/include/ghc-gmp.h
100
101 libraries/integer-gmp/include/ghc-gmp.h: libraries/integer-gmp/gmp/ghc-gmp.h
102 $(CP) $< $@
103 endif
104
105 libraries/integer-gmp_dist-install_EXTRA_CC_OPTS += $(gmp_CC_OPTS)
106
107 ifneq "$(CLEANING)" "YES"
108 # When running `make clean` before `./configure`, CC_STAGE1 is undefined.
109 CLANG = $(findstring clang, $(shell $(CC_STAGE1) --version))
110
111 ifeq "$(CLANG)" "clang"
112 CCX = $(CLANG)
113 else
114 CCX = $(CC_STAGE1)
115 endif
116
117 libraries/integer-gmp/gmp/libgmp.a libraries/integer-gmp/gmp/gmp.h:
118 $(RM) -rf libraries/integer-gmp/gmp/$(GMP_DIR) libraries/integer-gmp/gmp/gmpbuild libraries/integer-gmp/gmp/objs
119 cat $(GMP_TARBALL) | $(BZIP2_CMD) -d | { cd libraries/integer-gmp/gmp && $(TAR_CMD) -xf - ; }
120 mv libraries/integer-gmp/gmp/$(GMP_DIR) libraries/integer-gmp/gmp/gmpbuild
121 cd libraries/integer-gmp/gmp && $(PATCH_CMD) -p0 < gmpsrc.patch
122 cat libraries/integer-gmp/gmp/tarball/gmp-5.0.4.patch | { cd libraries/integer-gmp/gmp/gmpbuild && $(PATCH_CMD) -p1 ; }
123 chmod +x libraries/integer-gmp/gmp/ln
124
125 # Their cmd invocation only works on msys. On cygwin it starts
126 # a cmd interactive shell. The replacement works in both environments.
127 mv libraries/integer-gmp/gmp/gmpbuild/ltmain.sh libraries/integer-gmp/gmp/gmpbuild/ltmain.sh.orig
128 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
129
130 cd libraries/integer-gmp/gmp; (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
131 PATH=`pwd`:$$PATH; \
132 export PATH; \
133 cd gmpbuild && \
134 CC=$(CCX) NM=$(NM) AR=$(AR_STAGE1) ./configure \
135 --enable-shared=no \
136 --host=$(HOSTPLATFORM) --build=$(BUILDPLATFORM)
137 $(MAKE) -C libraries/integer-gmp/gmp/gmpbuild MAKEFLAGS=
138 $(CP) libraries/integer-gmp/gmp/gmpbuild/gmp.h libraries/integer-gmp/gmp/
139 $(CP) libraries/integer-gmp/gmp/gmpbuild/.libs/libgmp.a libraries/integer-gmp/gmp/
140 $(MKDIRHIER) libraries/integer-gmp/gmp/objs
141 cd libraries/integer-gmp/gmp/objs && $(AR_STAGE1) x ../libgmp.a
142 $(RANLIB_CMD) libraries/integer-gmp/gmp/libgmp.a
143
144 endif # CLEANING
145 endif # phase