set -e
TARDIR="$HOME/Downloads"
GMPVER=6.1.2
GMPVERP="$GMPVER"
GMPTAR="$TARDIR/gmp-$GMPVER.tar.lz"
GMPPATCH="$TARDIR/gmp-$GMPVERP-allpatches"
MPFRVER=4.0.2
MPFRVERP="$MPFRVER"
MPFRTAR="$TARDIR/mpfr-$MPFRVER.tar.xz"
MPFRPATCH="$TARDIR/mpfr-$MPFRVERP-allpatches"
MPCVER=1.1.0
MPCVERP="$MPCVER"
MPCTAR="$TARDIR/mpc-$MPCVER.tar.gz"
MPCPATCH="$TARDIR/mpc-$MPCVERP-allpatches"
CHANGELOG_CHARS=100000
function truncate {
mv "$1" "$1.rm~"
(
if (($2 > 0)); then
head -c $(($2 - 1))
head -n 1
fi
if [ $(head -c 1 | wc -c) == 1 ]; then
echo "... (truncated)"
fi
) < "$1.rm~" > "$1"
}
tar xf "$GMPTAR"
mv gmp-$GMPVER gmp-$GMPVERP-c
cd gmp-$GMPVERP-c
if [ -f "$GMPPATCH" ]; then
patch -N -Z -p1 < "$GMPPATCH" > /dev/null
fi
truncate ChangeLog $CHANGELOG_CHARS
rm doc/*.info* doc/*.tex
sed -i.rm~ -e '
/Configs for demos/,/Create config.m4/{
/Create config.m4/!s/^/#gmp-mpfr-sys /
s/\(#gmp-mpfr-sys\) $/\1/
}
/^ac_config_files=/{
:repeat
s/\( #gmp-mpfr-sys .*\) #gmp-mpfr-sys\(.*\)/\1\2/
s,^\([^#]*\) \(\(doc\|demos[/a-z]*\)/Makefile\)\([^#]*\)\($\| #\),\1\4 #gmp-mpfr-sys \2\5,
t repeat
}
' configure
sed -i.rm~ -e '
/^SUBDIRS = /{
:repeat
s/\( #gmp-mpfr-sys .*\) #gmp-mpfr-sys\(.*\)/\1\2/
s,^\([^#]*\) \(doc\|demos\)\([^#]*\)\($\| #\),\1\3 #gmp-mpfr-sys \2\4,
t repeat
}
' Makefile.in
cd ..
tar xf "$MPFRTAR"
mv mpfr-$MPFRVER mpfr-$MPFRVERP-c
cd mpfr-$MPFRVERP-c
if [ -f "$MPFRPATCH" ]; then
patch -N -Z -p1 < "$MPFRPATCH" > /dev/null
fi
truncate ChangeLog $CHANGELOG_CHARS
rm doc/*.info* doc/*.tex
sed -i.rm~ -e '
/^ac_config_files=/{
:repeat
s/\( #gmp-mpfr-sys .*\) #gmp-mpfr-sys\(.*\)/\1\2/
s,^\([^#]*\) \(doc/Makefile\|mpfr.pc\)\([^#]*\)\($\| #\),\1\3 #gmp-mpfr-sys \2\4,
t repeat
}
' configure
sed -i.rm~ -e '
/^SUBDIRS = /s,^\([^#]*\) \(doc\)\([^#]*\)\($\| #\),\1\3 #gmp-mpfr-sys \2\4,
/^DATA = /s,^\([^#]*\) \(\$(pkgconfig_DATA)\)\([^#]*\)\($\| #\),\1\3 #gmp-mpfr-sys \2\4,
' Makefile.in
sed -i.rm~ '/get_patches.c:/,/^$/s/^\(.\)/#gmp-mpfr-sys \1/' src/Makefile.in
tools/get_patches.sh > src/get_patches.c
cd ..
tar xf "$MPCTAR"
mv mpc-$MPCVER mpc-$MPCVERP-c
cd mpc-$MPCVERP-c
if [ -f "$MPCPATCH" ]; then
patch -N -Z -p1 < "$MPCPATCH" > /dev/null
fi
chmod -R u+w *
truncate ChangeLog $CHANGELOG_CHARS
rm doc/*.info* doc/*.tex
sed -i.rm~ '
/^ac_config_files=/s,^\([^#]*\) \(doc/Makefile\)\([^#]*\)\($\| #\),\1\3 #gmp-mpfr-sys \2\4,
' configure
sed -i.rm~ '
/^SUBDIRS = /s,^\([^#]*\) \(doc\)\([^#]*\)\($\| #\),\1\3 #gmp-mpfr-sys \2\4,
' Makefile.in
cd ..
for m in $(find *-c -name Makefile.in); do
sed -i.rm~ '/Makefile:/,/esac/s/^/#gmp-mpfr-sys /' $m
done
find *-c -name \*.rm~ -delete