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# https://gitlab.haskell.org/ghc/ghc/wikis/building/architecture 9# https://gitlab.haskell.org/ghc/ghc/wikis/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 18ifneq "$(BINDIST)" "YES" 19GMP_TARBALL := $(wildcard libraries/integer-gmp/gmp/gmp-tarballs/gmp*.tar.bz2) 20GMP_DIR := $(patsubst libraries/integer-gmp/gmp/gmp-tarballs/%-nodoc.tar.bz2,%,$(GMP_TARBALL)) 21 22ifeq "$(GMP_TARBALL)" "" 23$(error "GMP tarball is missing; you may need to run 'git submodule update --init'.") 24endif 25endif 26 27ifneq "$(NO_CLEAN_GMP)" "YES" 28$(eval $(call clean-target,gmp,,\ 29 libraries/integer-gmp/include/ghc-gmp.h \ 30 libraries/integer-gmp/gmp/libgmp.a \ 31 libraries/integer-gmp/gmp/gmp.h \ 32 libraries/integer-gmp/gmp/gmpbuild \ 33 libraries/integer-gmp/gmp/$(GMP_DIR))) 34 35clean : clean_gmp 36.PHONY: clean_gmp 37clean_gmp: 38 $(call removeTrees,libraries/integer-gmp/gmp/objs) 39 $(call removeTrees,libraries/integer-gmp/gmp/gmpbuild) 40endif 41 42ifeq "$(Windows_Host)" "YES" 43# Apparently building on Windows fails when there is a system gmp 44# available, so we never try to use the system gmp on Windows 45libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-intree-gmp 46endif 47 48ifeq "$(GMP_PREFER_FRAMEWORK)" "YES" 49libraries/integer-gmp_CONFIGURE_OPTS += --with-gmp-framework-preferred 50endif 51 52ifeq "$(phase)" "final" 53 54ifneq "$(CLEANING)" "YES" 55# Hack. The file config.mk doesn't exist yet after running ./configure in 56# the toplevel (ghc) directory. To let some toplevel make commands such as 57# sdist go through, right after ./configure, don't consider this an error. 58-include libraries/integer-gmp/dist-install/build/config.mk 59endif 60 61gmp_CC_OPTS += $(addprefix -I,$(GMP_INCLUDE_DIRS)) 62gmp_CC_OPTS += $(addprefix -L,$(GMP_LIB_DIRS)) 63 64# Compile GMP only if we don't have it already 65# 66# We use GMP's own configuration stuff, because it's all rather hairy 67# and not worth re-implementing in our Makefile framework. 68 69ifeq "$(findstring dyn, $(GhcRTSWays))" "dyn" 70BUILD_SHARED=yes 71else 72BUILD_SHARED=no 73endif 74 75# In a bindist, we don't want to know whether /this/ machine has gmp, 76# but whether the machine the bindist was built on had gmp. 77ifeq "$(BINDIST)" "YES" 78ifeq "$(wildcard libraries/integer-gmp/gmp/libgmp.a)" "" 79HaveLibGmp = YES 80HaveFrameworkGMP = YES 81else 82HaveLibGmp = NO 83HaveFrameworkGMP = NO 84endif 85endif 86 87UseIntreeGmp = NO 88ifneq "$(HaveLibGmp)" "YES" 89ifneq "$(HaveFrameworkGMP)" "YES" 90UseIntreeGmp = YES 91endif 92endif 93 94ifeq "$(UseIntreeGmp)" "YES" 95$(libraries/integer-gmp_dist-install_depfile_c_asm): libraries/integer-gmp/gmp/gmp.h libraries/integer-gmp/include/ghc-gmp.h 96 97libraries/integer-gmp/include/ghc-gmp.h: libraries/integer-gmp/gmp/gmp.h 98 $(CP) $< $@ 99 100gmp_CC_OPTS += -Ilibraries/integer-gmp/gmp 101 102libraries/integer-gmp_dist-install_EXTRA_OBJS += libraries/integer-gmp/gmp/objs/*.o 103else 104$(libraries/integer-gmp_dist-install_depfile_c_asm): libraries/integer-gmp/include/ghc-gmp.h 105 106libraries/integer-gmp/include/ghc-gmp.h: libraries/integer-gmp/gmp/ghc-gmp.h 107 $(CP) $< $@ 108endif 109 110libraries/integer-gmp_dist-install_EXTRA_CC_OPTS += $(gmp_CC_OPTS) 111 112ifneq "$(CLEANING)" "YES" 113# When running `make clean` before `./configure`, CC_STAGE1 is undefined. 114CLANG = $(findstring clang, $(shell $(CC_STAGE1) --version)) 115 116ifeq "$(CLANG)" "clang" 117CCX = $(CLANG) 118else 119CCX = $(CC_STAGE1) 120endif 121 122libraries/integer-gmp/gmp/libgmp.a libraries/integer-gmp/gmp/gmp.h: 123 $(RM) -rf libraries/integer-gmp/gmp/$(GMP_DIR) libraries/integer-gmp/gmp/gmpbuild libraries/integer-gmp/gmp/objs 124 cat $(GMP_TARBALL) | $(BZIP2_CMD) -d | { cd libraries/integer-gmp/gmp && $(TAR_CMD) -xf - ; } 125 mv libraries/integer-gmp/gmp/$(GMP_DIR) libraries/integer-gmp/gmp/gmpbuild 126 cd libraries/integer-gmp/gmp && $(PATCH_CMD) -p0 < gmpsrc.patch 127 chmod +x libraries/integer-gmp/gmp/ln 128 129 # Note: We must pass `TARGETPLATFORM` to the `--host` argument of GMP's 130 # `./configure`, not `HOSTPLATFORM`: the 'host' on which GMP will 131 # run is the 'target' platform of the compiler we're building. 132 # Note2: we pass --with-readline=no, to prevent getting an indirect 133 # dependency on ncurses through gmp. readline is only relevant 134 # for gmp test programs. (See gmp's configure) 135 cd libraries/integer-gmp/gmp/gmpbuild; \ 136 CC=$(CCX) CXX=$(CCX) NM=$(NM) AR=$(AR_STAGE1) ./configure \ 137 --enable-shared=no --with-pic=yes --with-readline=no \ 138 --host=$(TARGETPLATFORM) --build=$(BUILDPLATFORM) 139 $(MAKE) -C libraries/integer-gmp/gmp/gmpbuild MAKEFLAGS= 140 $(CP) libraries/integer-gmp/gmp/gmpbuild/gmp.h libraries/integer-gmp/gmp/ 141 $(CP) libraries/integer-gmp/gmp/gmpbuild/.libs/libgmp.a libraries/integer-gmp/gmp/ 142 $(MKDIRHIER) libraries/integer-gmp/gmp/objs 143 cd libraries/integer-gmp/gmp/objs && $(AR_STAGE1) x ../libgmp.a 144 $(RANLIB_CMD) libraries/integer-gmp/gmp/libgmp.a 145 146endif # CLEANING 147endif # phase 148