#!/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 = "-lX11 -lXext"
set cairolib = "-lcairo -lXrender -lfontconfig -lpixman-1 -lfreetype -lexpat -lpng -lz -lbz2"
set system   = ""LINUX""
set f77       = "f77"
set loadflags  = "-fPIC -g -O2 -ffile-prefix-map=/build/ncl-ncarg=. -fstack-protector-strong  -fallow-invalid-boz -fallow-argument-mismatch -fno-second-underscore -fno-range-check   -fPIE -Wl,-z,relro -Wl,-z,now  -Wl,-z,muldefs -Wl,-z,relro -Wl,-z,now -Wl,-z,muldefs   -L../../.././shared"
set libdir   = `ncargpath lib`
set incdir   = `ncargpath include`
set syslibdir = ""
set sysincdir = "IncSearchUser"
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 -lcurl -Wl,-L/usr/lib/aarch64-linux-gnu/hdf5/serial  -lhdf5_hl -lhdf5 -lsz"
    breaksw

  case "-hdf":
    set extra_libs = "$extra_libs -lmfhdfalt -ldfalt -ljpeg -lz"
    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
