#!/usr/bin/env bash

# Create the src directory, starting from upstream sources. We need
# to fix some packaging errors, which cannot be done at install time.
# We apply the patch patches/src.diff directly to the sources and
# re-run autotools.

set -e

# Remove old sources
rm -rf src

# Download and extract new sources
wget -N http://www.math.rutgers.edu/~asbuch/lrcalc/lrcalc-sage-1.1.6.tar.gz
tar xzf lrcalc-sage-1.1.6.tar.gz
mv lrcalc-sage-1.1.6 src
cd src

# Remove broken symbolic links
rm -f m4/*

# These files should not be distributed
rm -f mathlib/dependencies lrcoef/dependencies

# Apply patch to build system
patch -p1 <../patches/build.diff

# Rerun autotools, fix these versions if we use Sage's autotools.
libtoolize --copy
autoreconf --verbose --install
rm -r autom4te.cache
