ghc.mk 4.96 KB
Newer Older
1
2
3
4
5
6
7
# -----------------------------------------------------------------------------
#
# (c) 2009 The University of Glasgow
#
# This file is part of the GHC build system.
#
# To understand how the build system works and how to modify it, see
8
9
#      http://ghc.haskell.org/trac/ghc/wiki/Building/Architecture
#      http://ghc.haskell.org/trac/ghc/wiki/Building/Modifying
10
11
12
#
# -----------------------------------------------------------------------------

Ian Lynagh's avatar
Ian Lynagh committed
13
14
15
16
17
# We use a tarball like gmp-4.2.4-nodoc.tar.bz2, which is
# gmp-4.2.4.tar.bz2 repacked without the doc/ directory contents.
# That's because the doc/ directory contents are under the GFDL,
# which causes problems for Debian.

18
19
20
21
22
23
24
25
ifneq "$(BINDIST)" "YES"
GMP_TARBALL := $(wildcard libraries/integer-gmp/gmp/gmp-tarballs/gmp*.tar.bz2)
GMP_DIR := $(patsubst libraries/integer-gmp/gmp/gmp-tarballs/%-nodoc.tar.bz2,%,$(GMP_TARBALL))

ifeq "$(GMP_TARBALL)" ""
$(error "GMP tarball is missing; you may need to run 'git submodule update --init'.")
endif
endif
Ian Lynagh's avatar
Ian Lynagh committed
26
27
28

ifneq "$(NO_CLEAN_GMP)" "YES"
$(eval $(call clean-target,gmp,,\
29
  libraries/integer-gmp/include/ghc-gmp.h \
Ian Lynagh's avatar
Ian Lynagh committed
30
31
32
33
34
35
36
37
38
  libraries/integer-gmp/gmp/config.mk \
  libraries/integer-gmp/gmp/libgmp.a \
  libraries/integer-gmp/gmp/gmp.h \
  libraries/integer-gmp/gmp/gmpbuild \
  libraries/integer-gmp/gmp/$(GMP_DIR)))

clean : clean_gmp
.PHONY: clean_gmp
clean_gmp:
39
40
	$(call removeTrees,libraries/integer-gmp/gmp/objs)
	$(call removeTrees,libraries/integer-gmp/gmp/gmpbuild)
Ian Lynagh's avatar
Ian Lynagh committed
41
42
endif

43
ifeq "$(Windows_Host)" "YES"
44
45
# Apparently building on Windows fails when there is a system gmp
# available, so we never try to use the system gmp on Windows
ian@well-typed.com's avatar
ian@well-typed.com committed
46
47
48
49
50
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-intree-gmp
endif

ifeq "$(GMP_PREFER_FRAMEWORK)" "YES"
libraries/integer-gmp_CONFIGURE_OPTS += --with-gmp-framework-preferred
51
52
endif

53
ifeq "$(phase)" "final"
Ian Lynagh's avatar
Ian Lynagh committed
54

55
ifneq "$(CLEANING)" "YES"
56
57
58
59
# Hack. The file gmp/config.mk doesn't exist yet after running ./configure in
# the toplevel (ghc) directory. To let some toplevel make commands such as
# sdist go through, right after ./configure, don't consider this an error.
-include libraries/integer-gmp/gmp/config.mk
60
endif
61

ian@well-typed.com's avatar
ian@well-typed.com committed
62
63
gmp_CC_OPTS += $(addprefix -I,$(GMP_INCLUDE_DIRS))
gmp_CC_OPTS += $(addprefix -L,$(GMP_LIB_DIRS))
64

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Compile GMP only if we don't have it already
#
# We use GMP's own configuration stuff, because it's all rather hairy
# and not worth re-implementing in our Makefile framework.

ifeq "$(findstring dyn, $(GhcRTSWays))" "dyn"
BUILD_SHARED=yes
else
BUILD_SHARED=no
endif

# In a bindist, we don't want to know whether /this/ machine has gmp,
# but whether the machine the bindist was built on had gmp.
ifeq "$(BINDIST)" "YES"
ifeq "$(wildcard libraries/integer-gmp/gmp/libgmp.a)" ""
HaveLibGmp = YES
HaveFrameworkGMP = YES
else
HaveLibGmp = NO
HaveFrameworkGMP = NO
endif
endif

88
UseIntreeGmp = NO
89
90
ifneq "$(HaveLibGmp)" "YES"
ifneq "$(HaveFrameworkGMP)" "YES"
91
92
93
94
95
96
97
98
99
UseIntreeGmp = YES
endif
endif

ifeq "$(UseIntreeGmp)" "YES"
$(libraries/integer-gmp_dist-install_depfile_c_asm): libraries/integer-gmp/gmp/gmp.h libraries/integer-gmp/include/ghc-gmp.h

libraries/integer-gmp/include/ghc-gmp.h: libraries/integer-gmp/gmp/gmp.h
	$(CP) $< $@
100

ian@well-typed.com's avatar
ian@well-typed.com committed
101
gmp_CC_OPTS += -Ilibraries/integer-gmp/gmp
102

Ian Lynagh's avatar
Ian Lynagh committed
103
libraries/integer-gmp_dist-install_EXTRA_OBJS += libraries/integer-gmp/gmp/objs/*.o
104
105
else
$(libraries/integer-gmp_dist-install_depfile_c_asm): libraries/integer-gmp/include/ghc-gmp.h
106

107
108
libraries/integer-gmp/include/ghc-gmp.h: libraries/integer-gmp/gmp/ghc-gmp.h
	$(CP) $< $@
109
110
endif

ian@well-typed.com's avatar
ian@well-typed.com committed
111
112
libraries/integer-gmp_dist-install_EXTRA_CC_OPTS += $(gmp_CC_OPTS)

113
114
ifneq "$(CLEANING)" "YES"
# When running `make clean` before `./configure`, CC_STAGE1 is undefined.
115
116
117
118
119
120
121
122
CLANG = $(findstring clang, $(shell $(CC_STAGE1) --version))

ifeq "$(CLANG)" "clang"
CCX = $(CLANG)
else
CCX = $(CC_STAGE1)
endif

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
Ian Lynagh's avatar
Ian Lynagh committed
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
	cd libraries/integer-gmp/gmp && $(PATCH_CMD) -p0 < gmpsrc.patch
128
	chmod +x libraries/integer-gmp/gmp/ln
Ian Lynagh's avatar
Ian Lynagh committed
129

130
131
132
	# Note: We must pass `TARGETPLATFORM` to the `--host` argument of GMP's
	#       `./configure`, not `HOSTPLATFORM`: the 'host' on which GMP will
	#       run is the 'target' platform of the compiler we're building.
133
	cd libraries/integer-gmp/gmp/gmpbuild; \
134
	    CC=$(CCX) NM=$(NM) AR=$(AR_STAGE1) ./configure \
Ian Lynagh's avatar
Ian Lynagh committed
135
	          --enable-shared=no \
136
	          --host=$(TARGETPLATFORM) --build=$(BUILDPLATFORM)
137
138
139
	$(MAKE) -C libraries/integer-gmp/gmp/gmpbuild MAKEFLAGS=
	$(CP) libraries/integer-gmp/gmp/gmpbuild/gmp.h libraries/integer-gmp/gmp/
	$(CP) libraries/integer-gmp/gmp/gmpbuild/.libs/libgmp.a libraries/integer-gmp/gmp/
Ian Lynagh's avatar
Ian Lynagh committed
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
145
endif # CLEANING
endif # phase