#!/bin/sh

VERSION=`gmake -s version`

echo_idb()
{

## EOE 
    #####################################################################
    #  Capture bin directory

    dd=`echo $INST_EXAMPLES | sed -e 's/\///'`
    echo d 0755 root sys $dd $dd osg.eoe.sw
    cd bin
    for f in `find . -type l -print | grep -v CVS | sed -e 's/\.\///' | grep -v "\."`
    do
      ffd=`echo "$dd/$f" | sed 's/\/IRIX32//g'`
	  echo f 0755 root sys $ffd $ffd osg.eoe.sw
    done
    cd ..

    #####################################################################
    #  Capture lib and lib/osgPlugins directory

    dd=`echo $INST_LIBS | sed -e 's/\///'`
    echo d 0755 root sys $dd $dd osg.eoe.sw
    echo d 0755 root sys $dd/osgPlugins $dd/osgPlugins osg.eoe.sw
    cd lib
    for f in `find . -type l -print | grep -v CVS | sed -e 's/\.\///' `
    do
      ffd=`echo "$dd/$f" | sed 's/\/IRIX32//g'`
	  echo f 0755 root sys $ffd $ffd osg.eoe.sw
    done
    cd ..

## DEV
    #####################################################################
    #  Capture include directories and files
    dd=`echo $INST_INCLUDE | sed -e 's/\///'`

    cd include
    
    echo d 0755 root sys $dd $dd osg.dev.sw
    for d in  `find . -type d -print | grep -v CVS | sed -e 's/\.\///' | grep -v "\."`
    do
        echo d 0755 root sys $dd/$d $dd/$d osg.dev.sw
    done
    cd ..

    #####################################################################
    #  Capture installed example source

     dd=`echo $INST_SRC | sed -e 's/\///'`
     THISDIR=`pwd`
     cd $INST_SRC
     for d in `find . -type d -print | sed -e 's/\.\///' | grep -v "\." `
     do
         echo d 0755 root sys $dd/$d $dd/$d osg.dev.sw
     done
     for f in `find . -type f -print | sed -e 's/\.\///'`
     do
         echo f 0755 root sys $dd/$f $dd/$f osg.dev.sw
     done
     cd $THISDIR
}

make_idb()
{
    echo_idb | sort -k5
}

make_spec()
{
    cat <<- SPEC_EOF  
product osg
    id "Open Scene Graph $VERSION"
    image eoe
        id "Open Scene Graph $VERSION Run-Time Environment"
        version $VERSION
        order 9999
        subsys sw default
            id "Open Scene Graph $VERSION Run-Time Environment"
            replaces self
            exp osg.eoe.sw
        endsubsys
    endimage
    image dev
        id "Open Scene Graph $VERSION Development Environment"
        version $VERSION
        order 9999
        subsys sw default
            id "Open Scene Graph $VERSION Development Environment"
            replaces self
            exp osg.dev.sw
        endsubsys
    endimage
endproduct
SPEC_EOF
}

intro()
{
    echo; echo;
    echo "============ Building the $OS Distribution Package ==================="
    echo ""
    echo "    Please note that this script requires that" 
    echo 
    echo "        'make install' "
    echo 
    echo "    be previously run.  Please run "
    echo 
    echo "        'make distribution' "
    echo 
    echo "    with the same arguments (if any) as 'make install'"
    echo
    repeat=1
    while [ $repeat = 1 ] 
    do 
      printf "    Continue? (y/n) [y]: "
      read resp
      case $resp in  
       ""|Yes|YES|yes|Y|y) repeat=0 ;; 
	        n|N|no|NO) return 1; repeat=0;;
                *)         repeat=1;; 
      esac
   done

   return 0
}

OS=$1
TOPDIR=$2
INST_LIBS=$3
INST_PLUGINS=$4
INST_INCLUDE=$5
INST_EXAMPLES=$6
INST_SRC=$7
INST_EXAMPLE_SRC=$8
shift;shift; shift;shift; shift;shift; shift;shift;
INST_DOC=$1
INST_DATA=$2


intro || exit 0

make_spec > dist/Irix/osg.spec
make_idb > dist/Irix/osg.idb

DIST_DIR=Distribution-$VERSION

cd dist/Irix
rm -rf $DIST_DIR
mkdir $DIST_DIR
/usr/sbin/gendist -sbase / -idb osg.idb -spec osg.spec -dist $DIST_DIR
cd $DIST_DIR
tar cvf ../osg.tardist *
mv ../osg.tardist .
cd ../../../



exit 0
