#!/bin/csh -f
#
#	$Id: nhlf77.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 f77       = "/opt/local/bin/gfortran-mp-14"
set loadflags  = "-fPIC -fno-range-check -m64 -Wall -Os -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -fallow-argument-mismatch  -O  -Wl,-rpath,/opt/local/lib/libgcc "
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 newargv = "$f77 $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 "-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"


echo $newargv
eval $newargv
