#! /bin/csh
#
#            Build the lint library for the documented routines 
#
if ($#argv > 0) then
    if ("$1" == "-help") then
        echo "$0 [ arch ]"
        echo "Build the lint library lint/tools.ln"
	echo " "
	echo "This script is invoked by the tools install procedure and"
	echo "normally should not need to be called separately."
        exit 0;
    endif
endif
alias cd 'cd'
if ($?TOOLSDIR == 0) then
    set TOOLSDIR = `pwd`
endif
set TOOLS = $TOOLSDIR 
if (! -e $TOOLSDIR/lint/blinth) then
    echo "Please build $TOOLSDIR/lint/blinth"
    exit 1
endif
set ARCH = `bin/tarch`
set HASPRUNE    = `bin/findprune $ARCH`

#
# Build lint library source
#
if (! -e lint) mkdir lint
#
# Add the include files into the lint library head
#
/bin/rm -f lint/tools.c
cat > lint/tools.c <<.
/*LINTLIBRARY*/
/*NOTUSED*/
/*NOTDEFINED*/
#include "tools.h"
#include <stdio.h>
#include <signal.h>
#include <sys/time.h>
#include "system/system.h"
#include "system/nreg.h"
.
#
# Add special code for sparse
if (-e sparse/spmat.h) then
cat >> lint/tools.c <<.
#define NO_GENERIC_SPARSE
.
endif
#
foreach inc (blkcm/bc.h blkcm/mesh.h comm/comm.h comm/hosts.h comm/htable/bhost.h mg/mg.h sparse/spmat.h sparse/diag/diag.h solvers/svctx.h iter/itall.h vectors/vector.h vectors/dvec.h vectors/pvec.h vectors/zvec.h set/set.h set/iset.h preg/preg.h amult/pmat.h xtools/xball.h comm/io/pio.h nonlin/nlall.h psolvers/psvctx.h)
    if (-e $inc) then
cat >> lint/tools.c <<.
#include "$inc"
.
endif
end
#
if ($HASPRUNE == 1) then
find . \( -name libs -prune -o -name man -prune -o -name ref -prune -o \
	      -name '*.old' -prune \) -o -type d \
	-exec $TOOLS/bin/mklint $TOOLS \{\} \; >> lint/tools.c
else 
     find . -type d -exec $TOOLS/bin/mklint $TOOLS \{\} \; >> lint/tools.c
endif
#
# Different lints use different arguments to name the output lint library file
set TONAME = "-Ctools -z"
if ($ARCH == "rs6000") then
    # Also add space for symbols (Nn), dimension (Nd), suppress non-ANSI msgs
    # There appears to be no way to suppress the undefined structure defs
    # when used in names.
    set TONAME = "-otools -h -x -n -wD -wk -Nn3500 -Nd4000"
else if ($ARCH == "IRIX") then
    set TONAME = "-o tools -h -x -n"
endif
if (! -e lint/$ARCH) mkdir lint/$ARCH
#
# Build the library
(cd lint ; lint -u -v $TONAME -DLINT -I.. tools.c ; mv llib-ltools.ln $ARCH/tools.ln ; )
#
# The cray needs something like "lint -c -o tools tools.c."
#
