#!/bin/csh -f
set noglob
set nonomatch
set archive = yes
set shared = no
set result = 0
set expprog = ()
if ("$1" == "-as") then
	shift
	set shared = yes
else if ("$1" == "-s") then
		shift
		set archive = no
		set shared = yes
	endif
endif

 if("$argv[1]" == "-d") then
	shift
	set expprog = ( $argv[1] $expprog)
	shift
endif

set name = $1
shift
set basedir = $1 
shift
set linkprefix = "$1"
shift
if ($archive == yes) then
	echo "making archive lib"$name.a	
	rm -f lib$name.a
	set list = ()
	foreach ename ($argv:q)
	        if ("$ename:e" == "o") then 
   	             set list = ($ename $list)
  	      endif
	end
	ar clq lib$name.a $list
	if ($status != 0) then
		echo "Couldn't create archive library for $name."
		set result = -1
	endif
	ranlib lib$name.a
	if ($status != 0) then
		echo "Couldn't ranlib archive library for $name."
		set result = -1
	endif
endif
if ($shared == yes) then
	if !(-x $basedir/etc/mkatkshlib) then
		echo "Couldn't find $basedir/etc/mkatkshlib or it wasn't executable."
		echo "Perhaps ATK or the OS doesn't support shared libraries on this system?"
		exit -1
	endif
	$basedir/etc/mkatkshlib $name $basedir "$linkprefix" $*
	if ($status != 0) then
		echo "Couldn't create shared library for $name."
		@ result = $result - 2
	endif
endif
if ($#expprog != 0) then
	$expprog $name $basedir "$linkprefix" $*
	if ($status != 0) then
		echo "$expprog failed for $name."
		@ result = $result - 4
	endif
	shift expprog
endif
exit $result
