Commit fdf1cd03 authored by Ian Lynagh's avatar Ian Lynagh

Update the in-tree GMP; fixes trac #832

gmp is now in a top-level directory and we only have the tarball in the
darcs repo. It gets untarred if it is needed.
parent e552cfc4
......@@ -59,12 +59,12 @@ include $(TOP)/mk/boilerplate.mk
# We can't 'make boot' in libraries until stage1 is built
ifeq "$(BootingFromHc)" "YES"
SUBDIRS_BUILD = includes rts compat compiler docs utils driver
SUBDIRS_BUILD = gmp includes rts compat compiler docs utils driver
else
SUBDIRS_BUILD = includes compat utils driver docs compiler rts
SUBDIRS_BUILD = gmp includes compat utils driver docs compiler rts
endif
SUBDIRS = includes compat utils driver docs rts libraries compiler
SUBDIRS = gmp includes compat utils driver docs rts libraries compiler
# Sanity check that all the core libraries are in the tree, to catch
# failure to run darcs-all.
......@@ -261,6 +261,7 @@ binary-dist-pre::
$(MKDIRHIER) $(BIN_DIST_DIR)/share
binary-dist::
$(MAKE) -C gmp binary-dist DOING_BIN_DIST=YES
$(MAKE) -C includes binary-dist DOING_BIN_DIST=YES
$(MAKE) -C compiler binary-dist DOING_BIN_DIST=YES $(INSTALL_STAGE)
# XXX $(MAKE) -C docs binary-dist DOING_BIN_DIST=YES
......
......@@ -13,7 +13,6 @@ do
done
chmod +x push-all
chmod +x rts/gmp/configure
echo "Booting ."
autoreconf
......
TOP=..
include $(TOP)/mk/boilerplate.mk
# -----------------------------------------------------------------------------
# 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.
ifneq "$(HaveLibGmp)" "YES"
ifneq "$(HaveFrameworkGMP)" "YES"
boot :: stamp.gmp
PLATFORM := $(shell echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g')
# 2007-07-05
# We do
# set -o igncr; export SHELLOPTS
# here as otherwise checking the size of limbs
# makes the build fall over on Cygwin. See the thread
# http://www.cygwin.com/ml/cygwin/2006-12/msg00011.html
# for more details.
# 2007-07-05
# Passing
# as_ln_s='cp -p'
# isn't sufficient to stop cygwin using symlinks the mingw gcc can't
# follow, as it isn't used consistently. Instead we put an ln.bat in
# path that always fails.
GMP_TARBALL := $(firstword $(wildcard gmp*.tar.gz))
GMP_DIR := $(subst .tar.gz,,$(GMP_TARBALL))
BMP_BUILD_DIR := build
stamp.gmp:
$(RM) -rf $(GMP_DIR) gmpbuild
$(TAR) -zxf $(GMP_TARBALL)
mv $(GMP_DIR) gmpbuild
chmod +x ln
set -o igncr; export SHELLOPTS; \
export PATH=`pwd`:$$PATH; \
cd gmpbuild && \
CC=$(WhatGccIsCalled) $(SHELL) configure \
--enable-shared=no --host=$(PLATFORM) --build=$(PLATFORM)
touch $@
all :: gmpbuild/libgmp.a
ifeq "$(DLLized)" "YES"
all :: $(DLL_PEN)/gmp.dll
$(DLL_PEN)/gmp.dll:
$(MAKE) -C gmpbuild gmp.dll
$(CP) gmpbuild/gmp.dll $(DLL_PEN)
endif
install :: gmpbuild/libgmp.a
INSTALL_LIBS += gmpbuild/libgmp.a
gmpbuild/libgmp.a ::
$(MAKE) -C gmpbuild MAKEFLAGS=
$(CP) gmpbuild/.libs/libgmp.a gmpbuild
$(RANLIB) gmpbuild/libgmp.a
endif
endif
clean distclean maintainer-clean ::
$(RM) -f stamp.gmp
$(RM) -rf gmpbuild
$(RM) -rf gmpbuild
#-----------------------------------------------------------------------------
#
# Files to install
#
# Just libHSrts is installed uniformly across ways
#
ifeq "$(DLLized)" "YES"
INSTALL_PROGS += gmpbuild/gmp.dll
INSTALL_LIBS += gmpbuild/libgmp_imp.a
endif
#-----------------------------------------------------------------------------
#
# binary-dist
include $(TOP)/mk/target.mk
binary-dist:
@:
ifneq "$(HaveLibGmp)" "YES"
ifneq "$(HaveFrameworkGMP)" "YES"
$(INSTALL_DIR) $(BIN_DIST_DIR)/gmp
$(INSTALL_DIR) $(BIN_DIST_DIR)/gmp/gmpbuild
touch $(BIN_DIST_DIR)/gmp/$(GMP_TARBALL)
$(INSTALL_DATA) Makefile $(BIN_DIST_DIR)/gmp/
ifneq "$(INSTALL_PROGS)" ""
$(INSTALL_DATA) $(INSTALL_PROGS) $(BIN_DIST_DIR)/gmp/gmpbuild/
endif
ifneq "$(INSTALL_LIBS)" ""
$(INSTALL_DATA) $(INSTALL_LIBS) $(BIN_DIST_DIR)/gmp/gmpbuild/
endif
endif
endif
exit 1
......@@ -12,7 +12,7 @@ H_PLATFORM = ghcplatform.h
#
# All header files
#
H_FILES = $(filter-out gmp.h $(H_CONFIG) $(H_PLATFORM),$(wildcard *.h)) gmp.h
H_FILES = $(filter-out $(H_CONFIG) $(H_PLATFORM),$(wildcard *.h))
ifneq "$(DOING_BIN_DIST)" "YES"
......@@ -27,20 +27,14 @@ ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
SRC_CC_OPTS += -DTABLES_NEXT_TO_CODE
endif
SRC_CC_OPTS += -I. -I../rts
SRC_CC_OPTS += -I. -I../rts -I../gmp/gmpbuild
ifneq "$(GhcWithSMP)" "YES"
SRC_CC_OPTS += -DNOSMP
endif
boot :: gmp.h
all :: $(H_CONFIG) $(H_PLATFORM)
# gmp.h is copied from the GMP directory
gmp.h : $(FPTOOLS_TOP)/rts/gmp/gmp.h
$(CP) $< $@
# The fptools configure script creates the configuration header file and puts it
# in fptools/mk/config.h. We copy it down to here (without any PACKAGE_FOO
# definitions to avoid clashes), prepending some make variables specifying cpp
......
......@@ -7,9 +7,6 @@
# .hc files are "Haskellized-C", compiled using the C compiler and
# (possibly) the assembly-mangler. The GHC driver script
# knows how to compile this stuff.
#
# Other sorta independent, compile-once subdirs are:
# gmp -- GNU multi-precision library (for Integer)
#-----------------------------------------------------------------------------
# Preamble
......@@ -254,46 +251,6 @@ endif
# We use GMP's own configuration stuff, because it's all rather hairy
# and not worth re-implementing in our Makefile framework.
ifneq "$(HaveLibGmp)" "YES"
ifneq "$(HaveFrameworkGMP)" "YES"
boot ::
if [ -f gmp/config.status ]; then \
cd gmp && CC=$(WhatGccIsCalled) ./config.status; \
else \
cd gmp && CC=$(WhatGccIsCalled) $(SHELL) configure --enable-shared=no \
--host=`echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g'`; \
fi
# Slight cheatage here to pass host as target, but x-compilation isn't supported by ghc.
ifeq "$(way)" ""
all :: gmp/libgmp.a
ifeq "$(DLLized)" "YES"
all :: $(DLL_PEN)/gmp.dll
$(DLL_PEN)/gmp.dll:
$(MAKE) -C gmp gmp.dll
$(MV) gmp/gmp.dll $(DLL_PEN)
endif
endif
install :: gmp/libgmp.a
ifeq "$(way)" ""
clean distclean maintainer-clean ::
-$(MAKE) -C gmp MAKEFLAGS= $@
INSTALL_LIBS += gmp/libgmp.a
endif
endif
gmp/libgmp.a ::
$(MAKE) -C gmp MAKEFLAGS=
@$(CP) gmp/.libs/libgmp.a gmp
@$(RANLIB) gmp/libgmp.a
endif
CLEAN_FILES += gmp/libgmp.a
# Need to get the GMP vars in through CPP to package.conf.in, and put
......@@ -314,6 +271,11 @@ ifneq "$(GMP_LIB_DIRS)" ""
SRC_LD_OPTS += -L$(GMP_LIB_DIRS)
endif
SRC_CC_OPTS += -I../gmp/gmpbuild
SRC_HC_OPTS += -I../gmp/gmpbuild
SRC_HSC2HS_OPTS += -I../gmp/gmpbuild
SRC_LD_OPTS += -L../gmp/gmpbuild
#-----------------------------------------------------------------------------
#
# Building the GUM SysMan
......
# Copyright (C) 1999 Free Software Foundation, Inc.
#
# This file is part of the GNU MP Library.
#
# The GNU MP Library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or (at your
# option) any later version.
#
# The GNU MP Library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with the GNU MP Library; see the file COPYING.LIB. If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
# MA 02111-1307, USA.
define pz
set __gmpz_dump ($)
end
define pq
set __gmpz_dump ($->_mp_num)
echo /
set __gmpz_dump ($->_mp_den)
end
define pf
set __gmpf_dump ($)
end
Authors if GNU MP (in chronological order)
Torbjrn Granlund
John Amanatides
Paul Zimmermann
Ken Weber
Bennet Yee
Andreas Schwab
Robert Harley
Linus Nordberg
Kent Boortz
Kevin Ryde
Guillaume Hanrot
No preview for this file type
This diff is collapsed.
INSTALLING GNU MP
=================
These instructions are only for the impatient. Others should read the install
instructions in the manual, gmp.info. Use
info -f ./gmp.info
or in emacs
C-u C-h i gmp.info
Here are some brief instructions on how to install GMP, and some examples to
help you get started using GMP.
First, you need to compile, and optionally install, GMP. Since you're
impatient, try this:
./configure; make
If that fails, or you care about the performance of GMP, you need to read the
full instructions in the chapter "Installing GMP", in the manual.
Next, try some small test programs, for example the ones below.
In GMP programs, all variables need to be initialized before they are
assigned, and cleared out before program flow leaves the scope in which they
were declared. Here is an example program that reads two numbers from the
command line, multiplies them, and prints the result to stdout.
#include <stdio.h>
#include <gmp.h> /* All GMP programs need to include gmp.h */
main (int argc, char **argv)
{
mpz_t a, b, p;
if (argc != 3)
{ printf ("Usage: %s <number> <number>\n", argv[0]); exit (1); }
/* Initialize variables */
mpz_init (a);
mpz_init (b);
mpz_init (p);
/* Assign a and b from base 10 strings in argv */
mpz_set_str (a, argv[1], 10);
mpz_set_str (b, argv[2], 10);
/* Multiply a and b and put the result in p */
mpz_mul (p, a, b);
/* Print p in base 10 */
mpz_out_str (stdout, 10, p);
fputc ('\n', stdout);
/* Clear out variables */
mpz_clear (a);
mpz_clear (b);
mpz_clear (p);
exit (0);
}
This might look tedious, with all the initializing and clearing. Fortunately
some of these operations can be combined, and other operations can often be
avoided. An experienced GMP user might write:
#include <stdio.h>
#include <gmp.h>
main (int argc, char **argv)
{
mpz_t a, b, p;
if (argc != 3)
{ printf ("Usage: %s <number> <number>\n", argv[0]); exit (1); }
/* Initialize and assign a and b from base 10 strings in argv */
mpz_init_set_str (a, argv[1], 10);
mpz_init_set_str (b, argv[2], 10);
/* Initialize p */
mpz_init (p);
/* Multiply a and b and put the result in p */
mpz_mul (p, a, b);
/* Print p in base 10 */
mpz_out_str (stdout, 10, p);
fputc ('\n', stdout);
/* Since we're about to exit, no need to clear out variables */
exit (0);
}
Now you have to compile your test program, and link it with the GMP library.
Assuming your working directory is still the gmp source directory, and your
source file is called example.c, enter:
gcc -g -I. example.c .libs/libgmp.a
After installing, the command becomes: "gcc -g example.c -lgmp". Also, GMP is
libtool based so you can use that to link if you want.
Now try to run the example:
./a.out 98365871231256752134 319378318340103345227
31415926535897932384618573336104570964418
The functions used here all operate on signed integers, and have names
starting with "mpz_". There are many more such functions than used in these
examples. See the chapter "Integer Functions" in the manual, for a complete
list.
There are two other main classes of functions in GMP. They operate on
rational numbers and floating-point numbers, respectively. The chapters
"Rational Number Functions", and "Floating-point Functions" document these
classes.
To run a set of tests, do "make check". This will take a while.
To create the printable documentation from the texinfo source, type "make
gmp.dvi" or "make gmp.ps". This requires various "tex" commands.
To install the library, do "make install" (then you can use -lgmp instead of
.libs/libgmp.a).
If you decide to use GMP, it is a good idea you at least read the chapter "GMP
Basics" in the manual.
Some known build problems are noted in the "Installing GMP" chapter of
the manual. Please report other problems to bug-gmp@gnu.org.
----------------
Local variables:
mode: text
fill-column: 78
End: