#!/usr/bin/csh -f
#
#   $Id: MakeNcl.csh,v 1.5 2008-07-27 04:12:48 haley Exp $
#                                                                      
#                Copyright (C)  2004
#        University Corporation for Atmospheric Research
#                All Rights Reserved
#
# The use of this Software is governed by a License Agreement.
#
# Use this script to make an ncl executable from installed libraries.
#

set cc_ld         = "g++"
set cc_opts       = "-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wno-complain-wrong-lang -Werror=format-security -fpermissive -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -mtls-dialect=gnu2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -std=c99 -fPIC -fno-strict-aliasing -fopenmp -fcommon -DH5_USE_110_API"
set ld_libs       = "-L/usr/lib64/ncarg -L/usr/lib64/hdf -lnetcdf -lcurl  -lnetcdf  -lmfhdf -ldf -ljpeg -lz -lhdf5_hl -lhdf5 -lg2c -ljasper -lgdal -lproj   -ludunits2  -lpng -lz -lcairo -lfreetype -lgsl -lgslcblas -L../../.././external/sphere3.1_dp -lsphere3.1_dp -L../../.././external/fftpack5_dp -lfftpack5_dp -L../../.././external/lapack -lflexiblas -L../../.././external/blas -lflexiblas"
set extra_ld_libs = "-lX11 -lXext -lgfortran -lm  -ldl  "
set libpath       = "/usr/lib64/ncarg"
set incpath       = "/usr/include"
set libdir        = "-L$libpath"
set incdir        = "-I$incpath"
set libncl        = "-lncl"
set libnfp        = "-lnfp -lnfpfort"
set libhlu        = "-lhlu"
set libncarg      = "-lncarg"
set libgks        = "-lncarg_gks"
set libncarg_c    = "-lncarg_c"
set libmath       = "-lngmath"
set ncarg_libs    = "$libncl $libnfp $libhlu $libncarg $libgks $libncarg_c $libmath"

if (! -d "$libpath") then
  echo "Library directory <$libpath> does not exist."
  exit 1
endif

set files      = ""
set extra_opts = ""

foreach arg ($argv)

    switch ($arg)

    case "-*":
        set extra_opts = "$extra_opts $arg"
        breaksw

    default:
        set files = "$files $arg"
        breaksw
    endsw
end

if ("$files" == "") then
  echo "MakeNcl error: You must input one or more *.o files"
  exit 1
endif

set newargv = "$cc_ld $cc_opts $extra_opts -o ncl $files $incdir $libdir $ncarg_libs $ld_libs $extra_ld_libs"

echo $newargv
eval $newargv
