#!/bin/sh
# shell script to help building GWM
# necessary for the buggy BSD make

# usage: gwm_util function args...

set -x

case $1 in

latex)
    while grep -s 'Rerun to get cross-references right' $2.log
    do latex $2.tex;done
    ;;

install)	# install bin-dir lib-dir
    if test -f /bin/install -o -f /usr/bin/install
        then INSTALL='install -c'
	else INSTALL='cp'
    fi
    if test ! -f .rootdir
    then echo "please create this directory with the \"make dir\" command!"
	exit 1
    fi
    mv $2/gwm $2/gwm.old
    $INSTALL gwm $2
    mkdir $3
    cd `cat .rootdir`/data
    for ff in .*.gwm *.gwm *.xbm *.xpm
    do
	$INSTALL $ff $3
    done
    echo "WARNING: you may have to install by hand things in contrib"
    ;;

dir|sdir)		# sdir dirname
    if test -z "$2";then echo "USAGE: make DIR=mach sdir";exit 1;fi
    case "$2" in */*);;*)DIR=../$2;;esac
    mkdir $2
    pwd >$2/.rootdir
    echo  `basename $2`>$2/.dir
    if test ! -f Make/Make.`basename $2`
    then cp Make.TEMPLATE Make/Make.`basename $2`
    fi
    Pwd=`pwd`
    ln -s $Pwd $2/SRC
    cd $2
    ln -s SRC/Make/Make.`basename $2` .
    for i in  .dbxinit .gdbinit `fgrep -v / $Pwd/FILES` data
    do ln -s SRC/$i .;done
    cp Makefile.noXtree Makefile
    echo "Now, go in $2 and edit Make.`basename $2`."
    ;;

esac
