# Note: depends on patch
# Note: depends on bison
# Note: depends on autoconf
wget -c http://www.gnu-pascal.de/alpha/gpc-20060325.tar.bz2
tar -xjf gpc-20060325.tar.bz2
cd gpc-20060325
wget -c http://www.gnu-pascal.de/alpha/gcc-core-3.4.4.tar.bz2
tar -xjf gcc-core-3.4.4.tar.bz2
cp -r p gcc-3.4.4/gcc/
mkdir -p build
cd gcc-3.4.4
patch -p0 < gcc/p/diffs/gcc-3.4.4.diff

# Some workarounds:
sed -i -e '/%{/a# define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)' gcc/p/parse.y # Fixes those ->last_file errors
sed -i -e 's/expect-rr 24/expect-rr 25/' gcc/p/parse.y # Something to do with older versions of bison counting something wrong
sed -i -e 's/struct siginfo/siginfo_t/' gcc/config/i386/linux.h

cd ../build
../gcc-3.4.4/configure --prefix="/usr" --enable-languages="pascal"
touch gcc/install.texi
touch gcc/welcome.texi
touch gcc/news.texi
touch gcc/faq.texi
touch gcc/authors.texi
touch gcc/copying.texi
touch gcc/copying-lib.texi
touch gcc/copying-demo.texi
touch gcc/support.texi
touch gcc/gpc.texi
touch gcc/gpcs.texi
make # can't handle -j#
# Since this build is based on an earlier version of gcc, cherrypick what to install to avoid overwriting our currently installed gcc with an older version, except for the pascal parts
make install DESTDIR="`pwd`/tmpinstall"
cp -r tmpinstall/usr/libexec /usr
cp -r tmpinstall/usr/lib/gcc /usr/lib
cp -r tmpinstall/usr/doc /usr
install tmpinstall/usr/bin/binobj /usr/bin
install tmpinstall/usr/bin/gpc /usr/bin
install tmpinstall/usr/bin/gpc-run /usr/bin
install tmpinstall/usr/bin/gpidump /usr/bin