#!/usr/bin/env bash

NTL=ntl-5.5.2


SPKG_ROOT=`pwd`

set -e
shopt -s extglob

# Remove old sources and download new
rm -rf src
mkdir src
cd src

tar xzf <( curl -L "http://www.shoup.net/ntl/$NTL.tar.gz" )

if [ ! -d "$NTL" ]; then
    echo "$NTL directory not in tarball, aborting"
    exit 1
fi
mv "$NTL" ntl


### libtool
#
# NTL requires libtool to build its shared library but doesn't use
# autoconf itself. So it asks for a global install of libtool, which
# is actually discouraged by autoconf.

mkdir libtool
cd libtool
cp "$SPKG_ROOT/patches/configure.ac" .
touch Makefile.am
autoreconf -fiv
rm -rf autom4te.cache

### Finished creating the src/ directory

# Make everything writable
cd "$SPKG_ROOT"
chmod -R u+w src
