#!/bin/sh

CVSCOSRC=/cern/new/src
export CVSCOSRC

default="scripts packlib pawlib graflib mathlib "
default="$default packpgm pawpgm grafpgm geant321 mclibs phtools"

build(){
	[ ! -r $1/Makefile ] && gmake $1/Makefile >> log/$3.`date +%m%d` 2>&1
	time gmake -C $1 $2 >> log/$3.`date +%m%d` 2>&1 
	rc=$?
	[ $rc -eq 0 ] && echo Remade $2 in $1 \
		     || echo Failed to make $2 in $1

}

[ $# -eq 0 ] && todo=$default

while [ $# -gt 0 ] ; do
	todo="$todo $1"
	shift
done

for target in $todo  ; do
case $target in 
tree)		build . tree  tree
	;;
scripts)	build scripts install.bin scripts
	;;
packlib)	build packlib install.lib packlib
	;;
pawlib)		build pawlib install.lib  pawlib
	;;
graflib)	build graflib install.lib graflib
	;;
mathlib)	build mathlib install.lib mathlib
	;;
packpgm)	build packlib install.bin packpgm
	;;
pawpgm)		build pawlib install.bin  pawpgm
	;;
grafpgm)	build graflib install.bin  grafpgm
	;;
geant321)	build geant321 install.lib geant321
	;;
mclibs)		build mclibs install.lib mclibs
		build mclibs install.bin mcpgms
	;;
mcpgms)		build mclibs install.bin mcpgms
	;;
phtools)	build phtools install.lib phtools
	;;
patchy)		build patchy install.bin patchy
	;;
*)	echo Ignoring unknown build target $target
	;;
esac
done
