#!/bin/sh

# Install defaults
APPDEFAULTS=/usr/lib/X11/app-defaults
BINDIR=/usr/games/bin
LIBDIR=/usr/games/lib/scrabble

# Version (don't modify without knowing!!)
MAJOR=2
MINOR=10

if ! [ "$*" ] ; then
  echo "\
Usage:
   ./build bin          builds the binary programs
   ./build install      installs the binary programs
   ./build lang XX      installs language XX
                       (currently available: en, fr)
   ./build clean        cleans everything

Present settings are:
   APPDEFAULTS=$APPDEFAULTS
   BINDIR=$BINDIR
   LIBDIR=$LIBDIR
First edit these parameters as needed in the 'build' script...
"
fi

if test "$1" = "bin" ; then
  echo "Building src/config.h"
  echo "\
#define VERSION $MAJOR$MINOR
#define DICT_FILE \"$LIBDIR/en/OSPD3.gz\"
#define SCORE_FILE \"$LIBDIR/en/scrabble_scores\"
#define RULES_FILE \"$LIBDIR/en/scrabble_rules\"
" > src/config.h
  xmkmf -a
  make
  echo "
Now, type './build install' to install programs in $BINDIR
"
fi

if test "$1" = "clean" ; then
  if [ -r Makefile ]; then
    make clean
  fi
  rm -rf ../xscrabble-$MAJOR.$MINOR/exports
  echo "rm -rf ../xscrabble-$MAJOR.$MINOR/exports"
  rm -f *~ Makefile* src/Makefile* src/config.h
  echo "rm -f *~ Makefile* src/Makefile* src/config.h"
fi

if test "$1" = "install" ; then
  mkdirhier $BINDIR
  echo "mkdirhier $BINDIR"
  install -c -s src/xscrab $BINDIR
  echo "install -c -s src/xscrab $BINDIR"
  install -c -s src/xscrabble $BINDIR
  echo "install -c -s src/xscrabble $BINDIR"
  rm -f $APPDEFAULTS/XScrabble
  cp -f XScrabble $APPDEFAULTS
  echo "cp -f XScrabble $APPDEFAULTS"
  echo "
Now, type './build lang XX' to install dictionaries in 
           $LIBDIR
The language installed in last place will be the default.
"
fi

if test "$1" = "lang" ; then

  if ! [ -r ../xscrabble_$2.tgz ] ; then
     echo "Can't find package xscrabble_$2.tgz !!"
     echo "Please download the dictionary file xscrabble_$2.tgz"
     echo "(if any), from  ftp://ftp.ac-grenoble.fr/ge/educational_games"
     echo "and make sure that you put it under the same (sub)directory"
     echo "as the main package xscrabble-2.xx.tgz"
     exit
  fi
  echo "Installing language ($en) dictionary and related files..."
  mkdirhier $LIBDIR
  tar xvfz ../xscrabble_$2.tgz 
  echo ""
  rm -rf $LIBDIR/$2
  echo "rm -rf $LIBDIR/$2"
  mv -f xscrabble_$2/lib $LIBDIR/$2
  echo "mv -f xscrabble_$2/lib $LIBDIR/$2"
  mv -f xscrabble_$2/app-defaults/XScrabble_$2 $APPDEFAULTS
  echo "mv -f xscrabble_$2/app-defaults/XScrabble_$2 $APPDEFAULTS"
  rm -f $APPDEFAULTS/XScrabble
  echo "rm -f $APPDEFAULTS/XScrabble"
  ln -fs $APPDEFAULTS/XScrabble_$2 $APPDEFAULTS/XScrabble
  echo "ln -fs $APPDEFAULTS/XScrabble_$2 $APPDEFAULTS/XScrabble"
  chmod a+rwx $LIBDIR/$2 
  chmod a+rw $LIBDIR/$2/scrabble_scores
  rm -rf xscrabble_$2

  echo "
Type './build lang YY' to install any other dictionaries in 
          $LIBDIR
The language installed in last place will be the default.
When installation is finished, type './build clean' to clean-up everything.
"
fi




