#!/bin/sh
#*=====================================================================*/
#*    serrano/prgm/project/bigloo/gc/install-gc7.0alpha7               */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Wed Dec 19 07:52:02 2007                          */
#*    Last change :  Sat Mar  5 07:39:55 2011 (serrano)                */
#*    Copyright   :  2007-11 Manuel Serrano                            */
#*    -------------------------------------------------------------    */
#*    This shell script installs a new GC.                             */
#*    Run the script with:                                             */
#*      GC=/usr/local/src/gc-7.0alpha7.tar.gz ./install-gc             */
#*=====================================================================*/

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

# untar the two version of the GC
tar xfz $src -C ../gc || exit 1 
mv ../gc/$gc "../gc/$gc"_fth || exit 1

tar xfz $src  -C ../gc || exit 1

# Patch the two versions
(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
(/bin/rm -f "../gc/$gc"_fth/libatomic_ops-1.2/src/*.o) || exit 1
(/bin/rm -f ../gc/$gc/libatomic_ops-1.2/src/*.o) || exit 1

# Patch the Makefiles for generating a good lib name
for p in configure configure.ac Makefile 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

# 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/$gc
cp ../runtime/Clib/inline_alloc.c "../gc/$gc"_fth
