#!/bin/sh

top=`cd ..; pwd`

export CC=gcc
export CXX=g++

build_cfitsio=1
build_readline=1 # not needed in v2.16.1 and beyond
build_libvotable=1

if [ "$IRAFARCH" = "linux" ] ; then
    CARCH="-m32"
elif [ "$IRAFARCH" = "macintel" ] ; then
    CARCH="-m64"
elif [ "$IRAFARCH" = "macosx" ] ; then
    CARCH="-m32"
fi

echo "Building support libraries ...."
echo "  (Using toplevel directory '"$top"' ....)"

# Global options.
gopts="--prefix=$top --exec-prefix=$top"

#echo "    Cleaning files ...."
#./mkclean



####################################################################
####   CFITSIO Library
####################################################################
if [ $build_cfitsio = 1 ] ; then

    echo -n "    Building CFITSIO libs ...."
    opts="$gopts --bindir=$top/bin --libdir=$top/bin"
    (cd cfitsio ;  \
     ./configure $opts CFLAGS="$CARCH"; \
     make clean 	     ; \
     make 	     ; \
     make install     ; \
     make distclean        ) | tee -a _spool 2>&1
    echo "done"

fi



####################################################################
####   READLINE Library
####################################################################
if [ $build_readline = 1 ] ; then

    echo -n "    Building Readline libs ...."
    opts="$gopts  --disable-shared --bindir=../../bin --libdir=../../bin"
    (cd readline ; mkpkg ) | tee -a _spool 2>&1
    echo "done"

fi



####################################################################
####   VO related Libraries
####################################################################
if [ $build_libvotable = 1 ] ; then

    echo -n "    Building VOTABLE lib ...."

    (cd libvotable ; \
     make all CARCH=$CARCH	        ; \
     make clean 		        ) | tee -a _spool 2>&1
    echo "done"

fi
