#! /usr/bin/bash

# wri-make-check:  Run the "make check" operation that tests the
# generated GMP.
#
# Running "make check" requires that you do a bit of work beforehand.
# (Even with these changes the process only makes it up to the "locale"
# test, but since that's way past the actual mathematical tests I didn't
# bother to figure out how to fix "t-locale.c".)
# 
# (1) Modify tests/mpz/reuse.c.  To the line beginning
#        #if defined(__STDC__)
#     add
#        || defined(_MSC_VER)
# (2) If this is a test of a static library (libgmp.lib rather than GMP.DLL),
#     change GMP.lib in WRILDFLAGS to libgmp.lib.
# (3) Invoke Cygwin in a nonstandard way:
#     * Open a Command Prompt
#     * SET LIB=<path-to-the-top-GMP-directory>\.libs
#     * Now run cygwin.bat.
#     This will have the effect of adding the .libs directory, home of the
#     GMP library, to the list of places the linker looks for libraries.
#
# Enter the top GMP directory, e.g. "gmp-4.1.4", before running:
#     ../wri-make-check
#
# Every time you re-run "wri-make-check" you should first clean up the old
# built tests by running (from the top GMP directory):
#     cd tests; make clean; cd ..

# Invoke the generated Makefile.

# wri-make takes one option:
#  -[g]        If 'g' is present, build a debugging version.
# All other command-line arguments follow -g and are passed on to make.

# Unfortunately, libtool doesn't respect the compiler and linker
# flags given on the command line.  But we can force certain flags
# by using the global environment variables WRICCFLAGS and WRILDFLAGS,
# which add options to wricc and wrild.
WRICCFLAGS="-q -TCONSOLE"	# Add Microsoft extensions & console subsystem
WRILDFLAGS="GMP.lib -Gexport-all-symbols -Yl,/BASE:0x62000000 -s 's/\(.*\)lib\(.*\)-[0-9].dll\$/\1\2.dll/; s/gmp/GMP/g'"
# Set a DLL base address, ensure that library files are output as
# GMP.dll, not libgmp-3.dll, by supplying a sed transformation script,
# and make any DLLs export all their symbols.
export WRICCFLAGS
export WRILDFLAGS

# Making a debug version?  (wri-make-chck -g).  Add -g flag to WRICCFLAGS.
case x"$1" in
    x-g ) WRICCFLAGS="$WRICCFLAGS -g" 
          shift ;;
esac

# Get the directory that this script is located in.  We require
# that the other WRI tools (wricc, wrild, ln, etc.) are in the same
# directory.
script_dir=`dirname "${0}"`
script_dir=`cd "${script_dir}"; pwd`

# Irritatingly, configure generates a libtool that uses the wrong
# kind of quotes in its definition of fix_srcfile_path.  Fix that
# if you can.
if [ -f libtool ] && ( grep '^fix_srcfile_path="' libtool >/dev/null 2>&1 )
then
    cp libtool libtool.orig
    sed "s/^\(fix_srcfile_path=\)\"\(.*\)\"\$/\1'\2'/" libtool.orig > libtool
fi

PATH="$script_dir":$PATH
make check







# Copyright 2010 Wolfram Research, Inc.
#
# This file is part of the build scripts for building the GNU MP Library
# for Mathematica on Windows (32-bit).
#
# This program 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 3 of the License, or (at your
# option) any later version.
#
# This program 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 this program.  If not, see http://www.gnu.org/licenses/.
