#!/bin/ksh

#
# script to create a binary distribution, Unix style
#
# This is an extremely optimistic script, it does no
# error checking whatever. Use with care!

# Understood envvars:
# OSG_DIST_NO_DISTASSEMBLY
# OSG_DIST_NO_EXAMPLEBUILD
# OSG_DIST_NO_REBUILD
# OSG_DIST_NO_RECONFIGURE
# OSG_DIST_NO_REINSTALL
# OSG_DIST_NO_TUTORIALBUILD
# OSG_DIST_REMOVE_BUILDDIR
# OSG_DIST_NO_FCDEDIT
# OSG_DIST_NO_RPM
# OSG_DIST_CLEANUP


# Little function to expand variables in text files and 
# fix line ends for Unix

unix_var_expand()
{
    src=$1
    dest=$2

    sed -e "s/%VERSION%/$OSGVERSION/g"  \
        -e "s/%SYSTEM%/$system/g"       \
        -e "s/%DISTNAME%/$distname/g"   \
        -e "s/%COMPILER%/$compiler/g"   \
        -e "s/%SUFFIX%/$suffix/g" < $src | \
        perl -pi -e 's/\r\n/\n/;' > $dest
}

# Expand vars and fix line ends for Windows
win_var_expand()
{
    src=$1
    dest=$2

    sed -e "s/%VERSION%/$OSGVERSION/g"  \
        -e "s/%SYSTEM%/$system/g"       \
        -e "s/%DISTNAME%/$distname/g"   \
        -e "s/%COMPILER%/$compiler/g"   \
        -e "s/%SUFFIX%/$suffix/g" < $src | \
        perl -pi -e 's/\n/\r\n/;' > $dest
}

echo $0 $*

today=`date '+%y%m%d'`

while test ${#*} -gt 0
do
	case $1 in
                --compiler)
	                compiler=$2
	                shift
	                shift
	                ;;
                --qt)
	                qt_dir=$2
	                shift
	                shift
	                ;;
                --today)
	                today=$2
	                shift
	                shift
	                ;;
		*)	break 2
			;;
	esac
done

if test $# -lt 1
then
    OSGPOOL=`pwd`/OpenSG
else
    OSGPOOL=$1
    shift
fi

echo "Making binary dist in" $OSGPOOL

build_make=gmake

if ! test x$OSG_DIST_FORCE_FULL_REBUILD = x
then
    unset OSG_DIST_NO_DISTASSEMBLY
    unset OSG_DIST_NO_EXAMPLEBUILD
    unset OSG_DIST_NO_REBUILD
    unset OSG_DIST_NO_RECONFIGURE
    unset OSG_DIST_NO_REINSTALL
    unset OSG_DIST_NO_TUTORIALBUILD

    OSG_DIST_REMOVE_BUILDDIR=1

    echo "Full rebuild forced\n";
fi

# does the OSGPOOL exist? If not, check it out.

if test ! -d $OSGPOOL
then
    # Check out the sources

    # little trick to get around the password input
    # not nice but works. Anyone got a better solution?

    cvs_ok=`fgrep -l anonymous@cvs.opensg.sourceforge.net:/cvsroot/opensg $HOME/.cvspass`
    if test "x$cvs_ok" = x
    then
        echo ":pserver:anonymous@cvs.opensg.sourceforge.net:/cvsroot/opensg A" >> $HOME/.cvspass
    fi

    # go where it's suppoosed to be
    cd `dirname $OSGPOOL`

    # cvs needs to be in the path!
    cvs -d:pserver:anonymous@cvs.opensg.sourceforge.net:/cvsroot/opensg co -P OpenSG

    if test `basename $OSGPOOL` != OpenSG
    then
        mv OpenSG `basename $OSGPOOL`
    fi
fi

# get the OSGVERSION

OSGVERSION=`cat $OSGPOOL/VERSION | sed -e "/\n/d"`

# make the libs

olddir=`pwd`
cd $OSGPOOL

host=`CommonConf/config.guess`
system=`CommonConf/config.sub $host`

# find the configure options for the dist

case $system in

    mips-sgi-* )

        compiler=${compiler:=CC}
        
        case "$compiler" in
        
            CC)
                # IGD Irix settings
                
                qt_dir=${qt_dir:="/igd/a4/software/IRIX/packages/qt-3.0"}
                qt_args="--with-qt=${qt_dir}"
                glut_dir="/igd/a4/software/IRIX"
                glut_lib="libglut.a"
                glut_args="--with-glut=$glut_dir"             
                tif_args="--with-tif"
                jpg_args="--with-jpg"
                png_args=""
                par_jobs=6
                build_make=gmake
                export PATH=/igd/a4/software/IRIX/bin/:/sgi/bin:$PATH
                ;;
            
            CC64)
                 # VRAC Irix settings
                 
                qt_dir=${qt_dir:="/home/users/dreiners"}
                qt_args="--with-qt=${qt_dir}"
                glut_dir="/usr/freeware/lib64"
                glut_lib="libglut.a"
                glut_args="--with-glut --with-glutincludedir=/usr/freeware/include/ --with-glutlibdir=/usr/freeware/lib64"             
                tif_args="--with-tif"
                jpg_args="--with-jpg"
                png_args=""
                par_jobs=6
                build_make=/home/users/dreiners/bin/IRIX64/make
                export PATH=${qt_dir}/bin/:$PATH
                ;;           
        esac

        distname=sgi
        ;;

    *-linux-gnu )

        glut_dir="/usr"
        glut_lib="libglut.so.3"
        glut_args="--with-glut=$glut_dir"
        qt_dir=${qt_dir:="/usr/lib/qt3"}
        qt_lib=libqt-mt.so.3
        qt_args="--with-qt=$qt_dir"
        tif_args="--with-tif"
        jpeg_args="--with-jpeg"
        png_args="--with-png"
        par_jobs=4
        compiler=${compiler:=g++}
        config_shell=bash
        export PATH=/igd/a4/software/Linux/bin/:$PATH
        if test -r /etc/SuSE-release
        then
            VERSION=`tail -1 /etc/SuSE-release | sed -e 's/^[^0-9]*//'`
            distname=suse$VERSION
        elif test -r /etc/fedora-release
        then
            VERSION=`sed -e 's/^[^0-9]*//' -e 's/\([0-9]*\).*$/\1/' < /etc/fedora-release`
            distname=fedora$VERSION
        elif test -r /etc/redhat-release
        then
            VERSION=`sed -e 's/^[^0-9]*//' -e 's/\([0-9]*\).*$/\1/' < /etc/redhat-release`
            distname=redhat$VERSION
        else
            distname=linux
        fi
        ;;

    *-pc-cygwin )

        if test ${#*} -eq 1
        then
            echo "got config"
            config_in=$1
            shift

            echo "Building for windows using config " $config_in

            . $config_in
        else
            glut_dir="`pwd`/../supportlibs"
            glut_lib="glut32.dll"
            glut_args="--with-glut=$glut_dir"
            qt_dir=${qt_dir:="`pwd`/../packages/qt-3.36"}
            qt_lib=qt-mt336.dll
            qt_args="--with-qt=$qt_dir"
            tif_args=""
            par_jobs=1
            compiler=${compiler:=icl50}
            config_shell=bash
            distname=win
	    innosetup=""
	    for p in "/cygdrive/c/Programme" "/cygdrive/c/Program Files" "`pwd`/.." "`pwd`/../packages"
	    do
		for v in 3 4 5
		do
			i="${p}/Inno Setup ${v}/ISCC.exe"
			
			if test -x "$i"
			then
				innosetup="$i"
			fi
		done
	    done
            if ! test -x "$innosetup"
            then
                echo "Warning: Innosetup not found! Won't build installer!"
                innosetup=""
            fi
            build_make=make
        fi
        ;;


    hppa2.0w-hp* )

        build_make=make
	qt_args="--with-qt=/igd/a4/software/HP-UX"
        qt_dir=${qt_dir:="/igd/a4/software/HP-UX"}
        qt_lib=libqt.3
	glut_args="--with-glut --with-glutincludedir=/opt/graphics/OpenGL/contrib/libglut --with-glutlibdir=/opt/graphics/OpenGL/contrib/libglut"
 	glut_lib=
        tif_args="--with-tif=/igd/a4/software/HP-UX/"
	jpeg_args="--with-jpeg=/igd/a4/software/HP-UX/"
 	png_args=""
   	par_jobs=${par_jobs:=4}
	compiler=${compiler:=aCC}
        distname=hpux
	export PATH=/igd/a4/software/HP-UX/bin/:$PATH
        # Move HP-toxic stuff out of the way
        Common/prep_hp
	;;
	
    ia64-unknown-linux* )	
    	
        glut_dir="/usr"
        glut_lib="libglut.so.3"
        glut_args="--with-glut=$glut_dir"
        qt_dir=${qt_dir:="/opt"}
        qt_lib=libqt-mt.so.3
        qt_args="--with-qt=$qt_dir"
        tif_args="--with-tif"
        jpeg_args="--with-jpeg"
        png_args="--with-png"
        par_jobs=2
        compiler=${compiler:=g++}
        config_shell=bash
        distname=ia64
        build_make=make
	;;

    *-apple-darwin* )    

        glut_args="--with-glut"
        par_jobs=${par_jobs:=1}
        compiler=${compiler:=cc}
        config_shell=sh
        mail=/usr/bin/Mail
        export PATH=$PATH
        loginfo="OS: `uname -a` <br>"
        # get rid of version number
        system=`echo $system | sed -e 's/darwin[0-9].[0-9]/darwin/' | sed -e 's/darwin.[0-9]/darwin/'`
        build_make=make
        ;;

    *)

        echo "Unknown system $system!"
        exit 1
        ;;

esac

echo "System" $system
echo "Dist" $distname

# Add QT to PATH for moc and uic
export PATH="${qt_dir}/bin:${qt_dir}/lib:$PATH"     # The /lib is for cygwin
export LD_LIBRARY_PATH="${qt_dir}/lib:$LD_LIBRARY_PATH"

# configure it

if ! test x$OSG_DIST_REMOVE_BUILDDIR = x
then
    echo "OSG_DIST_REMOVE_BUILDDIR set, remove build dir " Builds/$system-$compiler$suffix
    rm -rf Builds/$system-$compiler$suffix
fi

if test x$OSG_DIST_NO_RECONFIGURE = x
then
    $config_shell ./configure --prefix=BUILD --with-compiler=$compiler        \
       $stl_args $glut_args $qt_args $tif_args $jpg_args $png_args $gif_args \
       $freetype_args $add_inc_dirs $add_lib_dirs $platform_args $config_args \
       $compiler_args
else
    echo "OSG_DIST_NO_RECONFIGURE   set, skipping configure"
fi

# Build the libs

cd Builds/$system-$compiler$suffix

export OSGSUBPARJOBS=$par_jobs

if test x$OSG_DIST_NO_REBUILD = x
then
    if $build_make opt
    then
        echo "Opt Build succeeded"
    else
        echo "ERROR: Opt Build failed"
        exit
    fi
    if $build_make dbg
    then
        echo "Dbg Build succeeded"
    else
        echo "ERROR: Dbg Build failed"
        exit
    fi
else
    echo "OSG_DIST_NO_REBUILD       set, skipping build"
fi

if test x$OSG_DIST_NO_REINSTALL = x
then
    if $build_make install
    then
        echo "Install succeeded"
    else
        echo "ERROR: Install failed"
        exit
    fi
else
    echo "OSG_DIST_NO_REINSTALL     set, skipping install"
fi

# create the distribution(s)

case $system in
    # Windows is very different from the Unices. No, really. :)
    *-pc-cygwin )

    cd $olddir

    if test x$OSG_DIST_NO_DISTASSEMBLY = x
    then

        echo "Copying support"
        rm -rf OpenSG-$OSGVERSION-$distname-$compiler$suffix
        mkdir OpenSG-$OSGVERSION-$distname-$compiler$suffix
        cd OpenSG-$OSGVERSION-$distname-$compiler$suffix

        # support libs

        mkdir tmp
        cd tmp
        unzip -o $OSGPOOL/dist/win/supportlibs.zip > /dev/null

        mv include ..
        mv stlport ../include
        mv sources/*.txt ../include
        mv README.txt ../README_SupportLibs.txt

        mv lib ..

        cd ..
        rm -rf tmp

        # copy windows defaults
        # copies GLUT lib automatically

        cp -r $OSGPOOL/dist/win/dist/* .
        win_var_expand $OSGPOOL/dist/win/README.bindist README.txt

        # copy the QT lib, as Qt3 is not everywhere yet

        if test x$qt_lib != x
        then
            cp ${qt_dir}/lib/${qt_lib} lib
        fi

        # copy OpenSG stuff
        cp -r $OSGPOOL/Builds/$system-$compiler$suffix/include/OpenSG ./include
        cp -r $OSGPOOL/Builds/$system-$compiler$suffix/lib/* lib

    else
        echo "OSG_DIST_NO_DISTASSEMBLY  set, skipping assembly"

        cd OpenSG-$OSGVERSION-$distname-$compiler$suffix
    fi

    if test x$OSG_DIST_NO_EXAMPLEBUILD = x
    then

        # make the sceneviewer

        mkdir Examples

        cp -r $OSGPOOL/Examples/SceneViewer Examples

        cd Examples/SceneViewer

        echo "Building SceneViewer"

        if $build_make LIBTYPE=opt QTDIR=$qt_dir OSGROOT=$OSGPOOL/Builds/$system-$compiler$suffix
        then
            echo "SceneViewer Build succeeded"
        else
            echo "ERROR: SceneViewer Build failed"
            exit
        fi

        cd ../..

        # copy the SceneViewer
        cp Examples/SceneViewer/osgSceneViewer.exe* .

        rm -rf Examples

    else
        echo "OSG_DIST_NO_EXAMPLEBUILD  set, skipping example build"

        # copy the SceneViewer

        if test -r Examples/SceneViewer/osgSceneViewer.exe
        then
            cp Examples/SceneViewer/osgSceneViewer.exe* .
        fi
    fi

    if test x$OSG_DIST_NO_FCDEDIT = x
    then

        # make the fcdEdit

        mkdir Tools

        cp -r $OSGPOOL/Tools/fcdEdit Tools

        cd Tools/fcdEdit

        echo "Building fcdCompile"

        if $build_make LIBTYPE=opt NOGUI=true QTDIR=$qt_dir OSGROOT=$OSGPOOL/Builds/$system-$compiler$suffix
        then
            echo "fcdCompile Build succeeded"
        else
            echo "ERROR: fcdCompile Build failed"
            exit
        fi

        cd ../..
        # copy the fcdCompile
        cp Tools/fcdEdit/fcdCompile.exe* .

        cd Tools/fcdEdit

        $build_make LIBTYPE=opt NOGUI=true OSGROOT=$OSGPOOL/Builds/$system-$compiler$suffix clean

        echo "Building fcdEdit"

        if $build_make LIBTYPE=opt QTDIR=$qt_dir OSGROOT=$OSGPOOL/Builds/$system-$compiler$suffix
        then
            echo "fcdEdit Build succeeded"
        else
            echo "ERROR: fcdEdit Build failed"
            exit
        fi

        cd ../..

        # copy the fcdEdit
        cp Tools/fcdEdit/fcdEdit.exe* .

        rm -rf Tools

    else
        echo "OSG_DIST_NO_FCDEDIT set, skipping fcdEdit build"

        # copy the fcdEdit

        if test -r Tools/fcdEdit/fcdCompile.exe
        then
            cp Tools/fcdEdit/fcdCompile.exe* .
        fi

        if test -r Tools/fcdEdit/fcdEdit.exe
        then
            cp Tools/fcdEdit/fcdEdit.exe* .
        fi
    fi

    if test x$OSG_DIST_NO_TUTORIALBUILD = x
    then
        # do the tutorials

        if test -w Tutorials
        then
            rm -rf Tutorials
        fi

        cp -r $OSGPOOL/Tutorials .

        cd Tutorials

        echo "Building Tutorials"

        if $build_make LIBTYPE=opt OSGPOOL=$OSGPOOL OSGROOT=$OSGPOOL/Builds/$system-$compiler$suffix -f Makefile
        then
            echo "Tutorial Build succeeded"
        else
            echo "ERROR: Tutorial Build failed"
            exit
        fi
    else
        echo "OSG_DIST_NO_TUTORIALBUILD set, skipping tutorial build"

        cd Tutorials
    fi

    $build_make COMP=$compiler${suffix}-ms_stl -f Makefile.win dsw

    echo "Cleaning up"

    # cleanup the garbage
    rm -rf Makefile* common.* template.* template-* Tutorials.dsp.raw \
           README BUILD vc60.idb vc70.idb *.obj *.pdb *.ilk .prefix* \
           .cvsignore SConscript

    win_var_expand $OSGPOOL/dist/win/BUILD.tutorials BUILD.txt
    win_var_expand $OSGPOOL/dist/README.tutorials README.txt

    cd ..

    find . -name CVS | xargs rm -rf

    # Build the installer

    if ! test "x$innosetup" = x
    then
        echo "Building Installer"
        cd ..

        win_var_expand $OSGPOOL/dist/win/opensg_bindist.iss opensg_bindist.iss.raw
        perl -pi -e 's/\n/\r\n/;' < opensg_bindist.iss.raw > opensg_bindist.iss
        "$innosetup" opensg_bindist.iss
    fi
    
    if ! test x$OSG_DIST_CLEANUP = x
    then
        rm -rf OpenSG-$OSGVERSION-$distname-$compiler$suffix

        echo "Removed OpenSG-$OSGVERSION-$distname-$compiler$suffix";
    fi

    exit
    ;;
esac

# from here on it's Unix

cd $olddir

if test x$OSG_DIST_NO_EXAMPLEBUILD = x
then

    # make the sceneviewer

    cd OpenSG/Examples/SceneViewer

    if $build_make QTDIR=$qt_dir OSGROOT=../../Builds/$system-$compiler$suffix
    then
        echo "SceneViewer Build succeeded"
    else
        echo "ERROR: SceneViewer Build failed"
        exit
    fi

    cd $olddir
else
    echo "OSG_DIST_NO_EXAMPLEBUILD  set, skipping example build"
fi

if test x$OSG_DIST_NO_FCDEDIT = x
then

    cd OpenSG/Tools/fcdEdit

    if $build_make NOGUI=true QTDIR=$qt_dir OSGROOT=../../Builds/$system-$compiler$suffix
    then
        echo "fcdCompile Build succeeded"
    else
        echo "ERROR: fcdCompile Build failed"
        exit
    fi

    mv fcdCompile fcdCompile.keepit
    $build_make NOGUI=true OSGROOT=../../Builds/$system-$compiler$suffix clean
    mv fcdCompile.keepit fcdCompile

    if $build_make QTDIR=$qt_dir OSGROOT=../../Builds/$system-$compiler$suffix
    then
        echo "fcdEdit Build succeeded"
    else
        echo "ERROR: fcdEdit Build failed"
        exit
    fi

    cd $olddir
else
    echo "OSG_DIST_NO_FCDEDIT set, skipping fcdEdit build"
fi

echo "Making Opt dist"

# make the opt OSGVERSION

echo "dir..."
rm -rf OpenSG-$OSGVERSION-$distname-opt
mkdir OpenSG-$OSGVERSION-$distname-opt

cd OpenSG-$OSGVERSION-$distname-opt
unix_var_expand $OSGPOOL/dist/README.bindist README

# copy the libs/includes

cp -r $OSGPOOL/Builds/$system-$compiler/include .
cp -r $OSGPOOL/Builds/$system-$compiler/bin .

mkdir lib
cp -r $OSGPOOL/Builds/$system-$compiler/lib/opt lib

# copy the QT lib, as Qt 3.0 is not everywhere yet
if test x$qt_lib != x
then
    cp ${qt_dir}/lib/${qt_lib} lib/opt
fi

# copy the GLUT lib, as it is not everywhere yet
if test x$glut_lib != x
then
    cp ${glut_dir}/lib/${glut_lib} lib/opt
fi

# make the tutorial examples

echo "tuts..."
cp -r $OSGPOOL/Tutorials .

cd Tutorials
rm -rf CVS
unix_var_expand $OSGPOOL/dist/README.tutorials README
unix_var_expand $OSGPOOL/dist/BUILD.tutorials BUILD
sed -e 's|##DBG##|opt|g' < BUILD > BUILD.sed
mv BUILD.sed BUILD
sed -e 's|##DBG##|opt|g' < Makefile.dist > Makefile

if test x$OSG_DIST_NO_EXAMPLEBUILD = x
then
    sed -e 's|##DBG##|opt|g' < $OSGPOOL/dist/run_osgSceneViewer > ../run_osgSceneViewer
    chmod 755 ../run_osgSceneViewer
fi

#remove the stuff we don't need here
rm -f Makefile.dist Makefile.win template.* template-*  Tutorials.dsp.raw common.cygwin .prefix.* \
    .cvsignore SConscript

unix_var_expand $OSGPOOL/dist/README.tutorials README


if test x$OSG_DIST_NO_TUTORIALBUILD = x
then
    # do the tutorials
    if $build_make
    then
        echo "Tutorials succeeded"
    else
        echo "ERROR: Tutorials failed"
        exit
    fi
    $build_make clean
else
    echo "OSG_DIST_NO_TUTORIALBUILD set, skipping tutorial build"
fi

cd ..

if test x$OSG_DIST_NO_EXAMPLEBUILD = x
then
    # copy the SceneViewer
    cp $OSGPOOL/Examples/SceneViewer/osgSceneViewer .
fi

if test x$OSG_DIST_NO_FCDEDIT = x
then
    cp $OSGPOOL/Tools/fcdEdit/fcdCompile .
    cp $OSGPOOL/Tools/fcdEdit/fcdEdit .
fi

# do system-specific stuff

case $system in
    mips-sgi-* )
    ;;
    
    *-pc-linux-gnu )
    ;;
esac

# and pack it up

echo "pack..."
cd ..

tar cf - OpenSG-$OSGVERSION-$distname-opt | \
            gzip -9 > OpenSG-$OSGVERSION-$distname-opt.tgz

# now add the debug libs...

echo "Making Opt+Dbg dist"

echo "dir..."
rm -rf OpenSG-$OSGVERSION-$distname-opt+dbg
mv OpenSG-$OSGVERSION-$distname-opt OpenSG-$OSGVERSION-$distname-opt+dbg

cd OpenSG-$OSGVERSION-$distname-opt+dbg

cp -r ${OSGPOOL}/Builds/$system-$compiler/lib/dbg lib
#needed by SceneViewer, and not everywhere yet
if test x$qt_lib != x
then
    ln -s ../opt/${qt_lib} lib/dbg
fi

# copy the GLUT lib, as it is not everywhere yet either
ln -s ../opt/${glut_lib} lib/dbg


echo "pack (disabled)..."

cd ..

#tar cf - OpenSG-$OSGVERSION-${distname}-opt+dbg | \
#            gzip -9 > OpenSG-$OSGVERSION-${distname}-opt+dbg.tgz

# ... get rid of the opt libs ...

echo "Making Dbg dist"
echo "dir..."

rm -rf OpenSG-$OSGVERSION-$distname-dbg
mv OpenSG-$OSGVERSION-$distname-opt+dbg OpenSG-$OSGVERSION-$distname-dbg

cd OpenSG-$OSGVERSION-$distname-dbg
#needed by SceneViewer, and not everywhere yet
if test x$qt_lib != x
then
    rm -rf lib/dbg/${qt_lib}
    cp ${qt_dir}/lib/${qt_lib} lib/dbg
fi
if test x$glut_lib != x
then
    rm -rf lib/dbg/${glut_lib}
    cp ${glut_dir}/lib/${glut_lib} lib/dbg
fi
rm -rf lib/opt

# Build the dbg-tutorials again

echo "tuts..."


if test x$OSG_DIST_NO_TUTORIALBUILD = x
then
    # do the tutorials

    cd Tutorials
    $build_make Clean

    unix_var_expand $OSGPOOL/dist/README.tutorials README
    unix_var_expand $OSGPOOL/dist/BUILD.tutorials BUILD
    sed -e 's|##DBG##|dbg|g' < BUILD > BUILD.sed
    mv BUILD.sed BUILD
    sed -e 's|##DBG##|dbg|g' < $OSGPOOL/Tutorials/Makefile.dist > Makefile
    if test x$OSG_DIST_NO_EXAMPLEBUILD = x
    then
        sed -e 's|##DBG##|dbg|g' < $OSGPOOL/dist/run_osgSceneViewer > ../run_osgSceneViewer
        chmod 755 ../run_osgSceneViewer
    fi

    if $build_make
    then
        echo "Dbg Tutorials succeeded"
    else
        echo "ERROR: Dbg Tutorials failed"
        exit
    fi
    $build_make clean
else
    echo "OSG_DIST_NO_TUTORIALBUILD set, skipping tutorial build"

    cd Tutorials
fi

cd ..

echo "pack..."
cd ..

tar cf - OpenSG-$OSGVERSION-${distname}-dbg | \
            gzip -9 > OpenSG-$OSGVERSION-${distname}-dbg.tgz


if ! test x$OSG_DIST_CLEANUP = x
then
    rm -rf OpenSG-$OSGVERSION-${distname}-dbg

    echo "Cleanup\n";
fi


# do system-specific installers

case $system in
    mips-sgi-* )
    ;;
    
    *-linux-gnu )
    # Should we do RPMs?
    if test x$OSG_DIST_NO_RPM = x
    then
        echo Running $OSGPOOL/dist/make_rpm $OSGPOOL $OSGPOOL/Builds/$system-$compiler \
            $today "No conf" `pwd`
        $OSGPOOL/dist/make_rpm $OSGPOOL $OSGPOOL/Builds/$system-$compiler \
            $today "No conf" `pwd`
        mv OpenSG-$OSGVERSION*.src.rpm      OpenSG-$OSGVERSION-${distname}.src.rpm
        mv OpenSG-devel-$OSGVERSION*.rpm OpenSG-$OSGVERSION-${distname}-devel.rpm
        mv OpenSG-$OSGVERSION-1*.rpm      OpenSG-$OSGVERSION-${distname}.rpm
    fi
    
    ;;
esac

# that's it!
echo "All done. Enjoy!"



