#! /bin/sh
#
# Create some files dynamically to fully function it expects 
# both a 1.6 and 1.7 distro in /mnt/rock-v16 and /mnt/rock-v17
# (using symlinks or mounts).
#
# $Id: mkps.sh,v 1.5 2002/06/24 10:46:51 wrk Exp $
# $Source: /home/cvs/opensource/rock/person/pjotr/guide.DEV/mkps.sh,v $
#

# rock=`ls -d --color=never /mnt/rock-linux/rock-src-*|sort|head -1`
latex=`pwd`

# v15=`echo $rock|grep 1\.5`
# cd $rock

v16=/mnt/rock-v16
v17=/mnt/rock-v17

v17config=$v17/config/default/config
helpfn=Documentation/Developers/HACKING-HOWTO
faqfn=Documentation/FAQ

if [ ! -f $v16/Config ]; then
  echo "Can not compile for ROCK v1.6.x - $v16/Config not found (hit enter)"
  read in
fi

if [ ! -f $v17config ]; then
  echo "Can not compile for ROCK v1.7.x - $v17config not found (hit enter)"
  read in
fi

header()
{
  echo $title
  echo "\\\\begin{literalbox}[$title ($version)]" > $fn
  echo "\\\begin{verbatim}" >> $fn
}

footer()
{
  echo "\\\end{verbatim}" >> $fn
  echo "\\\\end{literalbox}" >> $fn
}

dump_output()
{
  script=$1
  fn=$latex/$2
  
  title="Output of \\\script{$script}"
  header
  $script 1>> $fn 2>> $fn
  footer
}

dump_help()
{
  script=$1
  fn=$latex/$2

  title="Output of \\\rscript{Help $script}"
  header
  $latex/helpparse.rb $helpfn scripts/$script >> $fn
  footer
}

dump_faq()
{
  search=$1
  fn=$latex/$2

  title="From the FAQ: $search"
  header
  $latex/helpparse.rb $faqfn $search >> $fn
  footer
}



# if [ ! -d $rock ]; then exit 0 ; fi

if [ "$1" = "pre" ]; then
  if [ -e $v16 ]; then
    echo "Creating output for $v16..."
    cd $v16
    version=`cat VERSION|sed -e 's,\(.*\)\([0-9]\.[0-9]\.[0-9]*\),\2,'`
    echo $version > $latex/script_VERSION_15.tex
    dump_output subdists/install-disks/intel/mk-bootdisk.sh bootroot_15.tex
    dump_output scripts/Download script_download_15.tex 
    dump_output scripts/Build-All script_buildall_15.tex 
    dump_output scripts/Build-Pkg script_buildpkg_15.tex 
  fi
  if [ -e $v17 ]; then
    echo "Creating output for $v17..."
    cd $v17
    # dump_output scripts/Build-Target script_buildtarget.tex
    version=`cat VERSION|sed -e 's,\(.*\)\([0-9]\.[0-9]\.[0-9]*\),\2,'`
    echo $version > $latex/script_VERSION.tex
    dump_output scripts/Download script_download.tex 
    dump_help Download script_help_download.tex 
    dump_faq prerequisites script_faq_prerequisites.tex 
  fi
fi

