#!/bin/sh
#*=====================================================================*/
#*    serrano/prgm/project/bigloo/gc/install-gc-7.2alpha2              */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano, Florian Loitsch                   */
#*    Copyright   :  2007-11 Manuel Serrano, Florian Loitsch           */
#*    -------------------------------------------------------------    */
#*    This shell script installs a new GC.                             */
#*    Run the script with:                                             */
#*      GC=/usr/local/src/gc-7.2alpha2.tar.gz ./install-gc             */
#*=====================================================================*/

src=$GC.tar.gz
gc=`basename $src .tar.gz`
bglversion=`grep release ../configure | head -n 1 | awk -F= '{ print $2 }'`

tar=$TAR
patch=$PATCH

if [ "$tar " = " " ]; then
  tar=tar
fi

if [ "$patch " = " " ]; then
  patch=patch
fi

# untar the two version of the GC
tar xfz $src -C ../gc || (echo "tar xfz $src failed"; exit 1)
mv ../gc/$gc "../gc/$gc"_fth || (echo "mv gc-7.1 failed"; exit 1)

tar xfz $src  -C ../gc || (echo "tar xfz $src failed"; exit 1)

(cd "../gc/$gc"_fth && patch -p1 < ../$gc.patch > /dev/null) || exit 1
(cd ../gc/$gc && patch -p1 < ../$gc.patch > /dev/null) || exit 1

# Remove parasite IA64 object files
(rm -f "../gc/$gc"_fth/libatomic_ops-1.2/src/*.a) || exit 1
(rm -f ../gc/$gc/libatomic_ops-1.2/src/*.a) || exit 1

# Patch the Makefiles for generating a good lib name
for p in configure configure.ac Makefile.direct Makefile.am Makefile.in Makefile.DLLs; do

  sed 's|gc\.a|$(BOOTLIBDIR)/libbigloogc-$(RELEASE).a|g' $gc/$p > $gc/$p.new
  mv $gc/$p.new $gc/$p

  sed 's|gc\.a|$(BOOTLIBDIR)/libbigloogc_fth-$(RELEASE).a|g' "$gc"_fth/$p > "$gc"_fth/$p.new
  mv "$gc"_fth/$p.new "$gc"_fth/$p

done

# Install the Makefiles.
#mv $gc/Makefile.direct $gc/Makefile
#mv "$gc"_fth/Makefile.direct "$gc"_fth/Makefile

# Set the correct mode for configure (configure is not currently used by Bigloo)
chmod a+rx $gc/configure
chmod a+rx "$gc"_fth/configure

# Copy the inline_alloc.c file
cp ../runtime/Clib/inline_alloc.c $gc
cp ../runtime/Clib/inline_alloc.c "$gc"_fth
