#!/bin/sh
# usage: klone_util function args...

set -x

case $1 in

klone.shar)
    cat FILES FILES_KIT | fshar >klone.shar
    ;;

install)	# install bin-dir lib-dir
    if test ! -f .rootdir
    then echo "please create this directory with the \"make dir\" command!"
	exit 1
    fi
    mv $2/klone $2/klone.old
    install -c -s klone $2		# cp klone $2
    mkdir $3
    cd `cat .rootdir`/data
    for ff in .*.kl *.kl *.xbm *.xpm
    do
	install -c $ff $3
    done
    ;;

dir|sdir)		# sdir dirname
    if test -z "$2";then echo "USAGE: make DIR=mach sdir";exit 1;fi
    ND="$2"
    case "$ND" in */*);;*)ND=../$ND;;esac
    mkdir $ND
    pwd >$ND/.rootdir
    NDB=`basename $ND`
    echo  "$NDB">$ND/.dir
    if test ! -f Configs/"$NDB"
    then cp Configs/TEMPLATE Configs/"$NDB"
    fi
    Pwd=`pwd`
    if test "0" = `expr match "$ND" '^[.][.][/][^/]*$'`
    then ln -s $Pwd $ND/SRC
    else ln -s ../`basename $Pwd` $ND/SRC
    fi
    if cd $ND;then :;else exit;fi
    ln -s SRC/Configs/"$NDB" Config."$NDB"
    ln -s SRC/amiga .
    for i in `cat $Pwd/FILES` kl tests
    do ln -s SRC/$i .;done
    cd $Pwd
    echo "Now, go in $ND and edit Config.$NDB if necessary"
    echo "then, type:     make makefile; make"
    ;;

# By Hand: FAIRE GAFFE A DF!
dummy_do_by_hand ) 
 # compiler ds linux, linux6, solaris, alpha (symblink)
 # alpha: ganesa: cd ~/Klone/src; make DIR=/0/var/tmp/alpha sdir
 # cd /0/var/tmp/alpha; make
 # ---
 # then compile on all archis...
 # on a main machine (koala, aye), make public kl files in ~/t/kl
 cd ~/Klone/src; rm -rf Inst;mkdir Inst 2>/dev/null;cp -r kl Inst/kl;cd Inst
 rm -f `cat ../FILES_AUX ../FILES_WOOL`;cd kl;../../scripts/klone-update;cd ..
 grep '^kl[/]' ../FILES_KIT|fshar> ~/t/klinst.shar; cd ..; rm -rf Inst
 cd ~/t;rm -rf kl;mkdir kl;funshar < klinst.shar
 # ---
 # then, on miracle
 df /net/lib/klone
 # (we must have enough room: ~ 3M)
 D=~/Klone;DD=/net/lib/klone/klone
 rm -rf $DD/common/lib/*
 cp -p ~/t/kl/* $DD/common/lib
 super rdsh -f ${DD}/common/lib

 for i in linux linux6 solaris alpha;do cp -p $D/$i/klone $DD/$i/bin/klone;done

 super rdsh -f ${DD}-2

# Ne pas refaire: pour info:
# install of archi A was done as: (A = linux linux-libc6 sun4OS5 decosf1)
for A in linux linux-libc6 sun4OS5 decosf1;do
 mkdir -p /net/lib/klone/klone/$A/bin 
 ln -s ../common/lib /net/lib/klone/klone/$A
 ln -s klone/$A /net/lib/klone
 rm -f /net/$A/local/klone;ln -s /net/lib/klone/$A /net/$A/local/klone
 rm -f /net/$A/local/bin/klone;ln -s /usr/local/klone/bin/klone /net/$A/local/bin/klone
 rm -f /net/$A/local/lib/klone;ln -s /usr/local/klone/lib /net/$A/local/lib/klone
 super rdsh -f /net/lib/klone \
	       /net/$A/local/lib/klone \
               /net/$A/local/bin/klone \
               /net/$A/local/klone
done

;;

esac
