#!/bin/sh

# This script will add a WRspice view to schematic symbols found in
# the WRspiceDevs library.  Presently, this contains only the
# Josephson junction device.  Devices here are created in Virtuoso
# using the symbol editor.  Then, they must be processed by this
# script.  The supplied jj device has already been processed, so
# unless devices are added or something changes, this script need not
# be run.

# Usage:         ./makeWrs [test]
# generates:     ./updates devices in WRspiceDevs in-place
# option:        test,  Don't modify library, keep tmp.il script.

test=no
if [ -n $1 -a $1 = test ]; then
    test=yes
fi

# Sanity checks.

if [ -z "$CDSHOME" ]; then
   echo ERROR:  CDSHOME not set in environment.  This should be set to
   echo your Virtuoso installation directory containing the tools link.
   exit 1.
fi
if [ ! -d $CDSHOME/tools/dfII/src/artist ]; then
   echo ERROR:  no such directory $CDSHOME/tools/dfII/src/artist
   echo Error in path, or Virtuoso setup incomplete.
   exit 2;
fi
if [ ! -d $CDSHOME/tools/dfII/src/artist/WRspice ]; then
   echo ERROR:  no such directory $CDSHOME/tools/dfII/src/artist/WRspice
   echo WRspice subdirectory missing.
   exit 3;
fi
if [ ! -d WRspiceDevs ]; then
   echo ERROR:  WRspiceDevs library directory not found.
   exit 4;
fi


# Build to script to load.

# One can add simulators here if it makes sense.
simulators="( WRspice )"

cat << EOF > tmp.il
\i printf("Loading tmp.il...")
\i lib = "WRspiceDevs"
\i sourcePath = "$path"
\i simulators = '$simulators
\i ddGetObj( lib )
\i sstatus( writeProtect nil)
\i load("../params.il")
\i load("./labels.il")
\i (almBuildLibrary ?lib lib ?sourcePath sourcePath ?simulators simulators)
\i exit()
EOF

if [ $test = no ]; then
    /bin/rm -f WRspiceDevs.log
    virtuoso -replay ./tmp.il -nograph -log ./WRspiceDevs.log
    rm tmp.il
fi

