#!/bin/csh -f
#
#	$Id: nhlcc.csh,v 1.6 2010-04-02 17:52:38 haley Exp $
#

#*********************************************#
#                                             #
# Make sure NCARG_ROOT is set for this script #
#                                             #
#*********************************************#
setenv NCARG_ROOT  `ncargpath root`

if ($status != 0) then
	exit 1
endif

set xlibs = "-lXpm -lX11 -lXext"
set cairolib = "-lcairo -lXrender -lfontconfig -lpixman-1 -lfreetype -lexpat -lpng -lz -lbz2"
set system   = ""Darwin_Intel""
set cc       = "/opt/local/bin/h5cc"
set defines  = "-DSYSV -D_POSIX_SOURCE -D_XOPEN_SOURCE -D__JIRA1530__ -DByteSwapped -D__UNIXOS2__ -D_DARWIN_C_SOURCE -DNeedFuncProto"
set loadflags  = "-fPIC -D_DARWIN_C_SOURCE -Os -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=int-conversion -Wno-error=incompatible-pointer-types -DH5_USE_110_API -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX11.sdk  -O   "
set libdir   = `ncargpath lib`
set incdir   = `ncargpath include`
set syslibdir = "-L/opt/X11/lib"
set sysincdir = "-I/opt/X11/include"
set ro       = "$libdir/ncarg/robj"
set f77libs  = "-L /opt/local/lib/libgcc -lgfortran -lgomp"
set newargv = "$cc $defines $loadflags"
set libpath = "-L$libdir $syslibdir"
set incpath = "-I$incdir $sysincdir"

#
# set up default libraries
#
set libncarg    = "-lncarg"
set libgks      = "-lncarg_gks"
set libmath     = ""
set libncarg_c  = "-lncarg_c"
set libhlu      = "-lhlu"
set ncarbd      = "$ro/libncarbd.o"
set ngmathbd    = "$ro/libngmathbd.o"
set extra_libs

set robjs
unset NGMATH_LD
unset NGMATH_BLOCKD_LD

foreach arg ($argv)
  switch ($arg)

  case "-XmXt":
  case "-xmxt":
    set extra_libs = "$extra_libs -lXm -lXt -lSM -lICE"
    breaksw

  case "-ngmath":
    set libmath     = "-lngmath"
    breaksw

  case "-ncarbd":
    set robjs = "$robjs $ncarbd"
    set NGMATH_BLOCKD_LD
    breaksw

  case "-ngmathbd":
    set robjs = "$robjs $ngmathbd"
# Make sure the ngmath blockdata routine doesn't get loaded twice.
    unset NGMATH_BLOCKD_LD
    breaksw

  case "-netcdf":
  case "-cdf":
    set extra_libs = "$extra_libs -lnetcdf -lhdf5_hl -lhdf5"
    breaksw

  case "-hdf":
    set extra_libs = "$extra_libs -lmfhdf -ldf"
    breaksw

  default:
    set newargv = "$newargv $arg"
  endsw
end


#
# If -ncarbd was set, *and* the ngmath library was loaded,
# then automatically take care of loading libngmathbd.o.
#
if ($?NGMATH_LD && $?NGMATH_BLOCKD_LD) then
  set robjs = "$robjs $ngmathbd"
endif

set ncarg_libs = "$libhlu $libncarg $libgks $libncarg_c $libmath"
set newargv = "$newargv $libpath $incpath $extra_libs $robjs $ncarg_libs $xlibs $cairolib $f77libs"

echo $newargv
eval $newargv
