#!/bin/sh

TMP_GS=/tmp/inst-gs/
TMP_GSN=$TMP_GS/native
TMP_GSX=$TMP_GS/x11
TMP_GSB=$TMP_GS/base

echo ==========================================
echo Step 1 of 5: Building native version.
echo ==========================================
sleep 1
make -f src/unix-gcc.mak

echo ==========================================
echo Step 2 of 5: Creating native package.
echo ==========================================
sleep 1
mkdir -p $TMP_GSN/usr
make -f src/unix-gcc.mak prefix=$TMP_GSN/usr install-exec install-scripts
strip $TMP_GSN/usr/bin/gs.exe
rm -fr $TMP_GSN/usr/share
tar cjCf $TMP_GSN $TMP_GS/ghostscript-7.05-1.tar.bz2 usr

echo ==========================================
echo Step 3 of 5: Building X11 version.
echo ==========================================
sleep 1
make -f src/unix-gcc.mak clean
make -f src/cygwin-x11.mak

echo ==========================================
echo Step 4 of 5: Creating X11 package.
echo ==========================================
sleep 1
mkdir -p $TMP_GSX $TMP_GSX/usr/X11R6
make -f src/cygwin-x11.mak prefix=$TMP_GSX/usr install-exec install-scripts
mv $TMP_GSX/usr/bin $TMP_GSX/usr/X11R6
strip $TMP_GSX/usr/X11R6/bin/gs.exe
rm -fr $TMP_GSX/usr/share
tar cjCf $TMP_GSX $TMP_GS/ghostscript-x11-7.05-1.tar.bz2 usr

echo ==========================================
echo Step 5 of 5: Creating base package.
echo ==========================================
sleep 1
mkdir -p $TMP_GSB
make -f src/unix-gcc.mak prefix=$TMP_GSB/usr install-data cygwin-doc
tar xzCf $TMP_GSB/usr/share/ghostscript /tmp/gnu-gs-fonts-std-6.0.tar.gz
tar xzCf $TMP_GSB/usr/share/ghostscript /tmp/gnu-gs-fonts-other-6.0.tar.gz
tar cjCf $TMP_GSB $TMP_GS/ghostscript-base-7.05-1.tar.bz2 usr
