#! /bin/sh

#
# This script will create a copy of the OTC C++ library which can then be
# moved on to a PC and compiled with Borland C++ or other DOS C++ compilers
# such as Watcom C++. To run the script simply type
#
#   ./BORLAND dirname
#
# from the same directory that this script is in. The single argument,
# "dirname" should be the name of the directory into which you wish the
# library source to be copied. The directory you indicate must not be
# the same directory that this script is in.
#
# Once you have the code on your PC you will need to create you own project
# file. When I did this I compiled templates as "Global". Then at the start
# of my test program; before including any header files, I would include
# 
#   #define EXPAND_TEMPLATES
# 
# For the programs the "Smart" option was used for templates. If your C++
# compiler supports exceptions, you need to use the compiler option:
#
#   -DHAVE_EXCEPTIONS
#
# A makefile has been supplied by one user. This is in the 'misc' directory
# and is called 'borland.mk'. You make need to modify it for your system.
# They have also included a small test program and makefile for that test
# program. These are called 'bccex.cc' and 'bccex.mk'.
#
# I know very little about Borland C++ so there may be a better way. If
# there is I would be interested to here about it. I would also be interested
# in any other comments regarding making the library more usable under DOS.
#

if test "$#" != 1
then
  echo "Usage: `basename $0` dirname"
  exit 1
fi

TOP="$1"

if test -f $TOP/`basename $0`
then
  echo "`basename $0`: can't use current directory as destination."
  exit 1
fi

echo mkdir $TOP
if test "$DEBUG" = ""
then
  mkdir $TOP
fi

echo cp ANNOUNCE COPYING PACKAGE $TOP
if test "$DEBUG" = ""
then
  cp ANNOUNCE COPYING PACKAGE $TOP
fi

echo cp misc/borland.mk misc/bccex.cc misc/bccex.mk $TOP
if test "$DEBUG" = ""
then
  cp misc/borland.mk misc/bccex.cc misc/bccex.mk $TOP
fi

echo mkdir $TOP/include
if test "$DEBUG" = ""
then
  mkdir $TOP/include
fi

echo mkdir $TOP/include/OSE
if test "$DEBUG" = ""
then
  mkdir $TOP/include/OSE
fi

. `dirname $0`/PACKAGE

echo creating $TOP/include/OSE/OSE.h

if test "$DEBUG" = ""
then
  cat > $TOP/include/OSE/OSE.h << EOF
#ifndef OSE_OSE_H
#define OSE_OSE_H

#define OSE_RELEASE_NAME "${OSE_RELEASE_NAME}"
#define OSE_MAJOR_RELEASE ${OSE_MAJOR_RELEASE}
#define OSE_MINOR_RELEASE ${OSE_MINOR_RELEASE}
#define OSE_MAINTENANCE_RELEASE ${OSE_MAINTENANCE_RELEASE}

#endif /* OSE_OSE_H */
EOF
fi

echo mkdir $TOP/include/OTC
if test "$DEBUG" = ""
then
  mkdir $TOP/include/OTC
fi

echo cp include/OTC/OTC.h $TOP/include/OTC/OTC.h
if test "$DEBUG" = ""
then
  cp include/OTC/OTC.h $TOP/include/OTC/OTC.h
fi

for i in include/OTC/*
do
  if test -d $i -a -f $i/Makefile
  then
    echo mkdir $TOP/$i
    if test "$DEBUG" = ""
    then
      mkdir $TOP/$i
    fi
    for j in $i/*[hc]
    do
      echo cp $j $TOP/$j
      if test "$DEBUG" = ""
      then
	cp $j $TOP/$j
      fi
    done
  fi
done

echo mkdir $TOP/lib
if test "$DEBUG" = ""
then
  mkdir $TOP/lib
fi

echo mkdir $TOP/lib/OTC
if test "$DEBUG" = ""
then
  mkdir $TOP/lib/OTC
fi

for i in lib/OTC/*
do
  if test -d $i -a -f $i/Makefile
  then
    # echo mkdir $TOP/$i
    # mkdir $TOP/$i
    for j in $i/otc*.c
    do
      if test -f $j
      then
	f=`echo $j | sed -e 's%[^/]*/otc\(.*\)\.c%\1.c%'`
	echo cp $j $TOP/$f
	if test "$DEBUG" = ""
	then
	  cp $j $TOP/$f
	fi
      fi
    done
    for j in $i/otc*.cc
    do
      if test -f $j
      then
	f=`echo $j | sed -e 's%[^/]*/otc\(.*\)\.cc%\1.cpp%'`
	echo cp $j $TOP/$f
	if test "$DEBUG" = ""
	then
	  cp $j $TOP/$f
	fi
      fi
    done
  fi
done

# echo "rm $TOP/include/OTC/ostore/*.hh"
# rm $TOP/include/OTC/ostore/*.hh
# echo "rm $TOP/include/OTC/ostore/*.h"
# rm $TOP/include/OTC/ostore/*.c
# echo "rmdir $TOP/include/OTC/ostore"
# rmdir $TOP/include/OTC/ostore
# echo "rm $TOP/lib/OTC/ostore/*.cpp"
# rm $TOP/lib/OTC/ostore/*.cpp
# echo "rmdir $TOP/lib/OTC/ostore"
# rmdir $TOP/lib/OTC/ostore

echo "rm $TOP/include/OTC/text/ostring.hh"
if test "$DEBUG" = ""
then
  rm $TOP/include/OTC/text/ostring.hh
fi

echo "rm $TOP/include/OTC/text/obuffer.hh"
if test "$DEBUG" = ""
then
  rm $TOP/include/OTC/text/obuffer.hh
fi

echo "rm $TOP/include/OTC/text/buffer.hh"
if test "$DEBUG" = ""
then
  rm $TOP/include/OTC/text/buffer.hh
fi

echo "rm $TOP/lib/OTC/ostring.cpp"
if test "$DEBUG" = ""
then
  rm $TOP/lib/OTC/ostring.cpp
fi

echo "rm $TOP/lib/OTC/obuffer.cpp"
if test "$DEBUG" = ""
then
  rm $TOP/lib/OTC/obuffer.cpp
fi
