#!/bin/sh
#
# Copyright (C) GFD Dennou Club, 2002-2025.  All rights reserved.
#
prefix=$PREFIX
version=$VERSION
out=${1:-dcpamfrt}

cat > $out <<EOF
#!/bin/sh
#=begin
#== NAME
#((* $out *)) -- script for fortran using DCPAM6
#
#Wrapper shell script for fortran compiler using spml
#
#== SYNTAX
#
# % $out [fortran_compiler_option] fortran_program.f90
#
#== DESCRIPTION
#
#((* $out *)) is simple shell script.
#This script set environment variables for using spml library.
#
#== OPTION
#
#:fortran_compiler_option
#  commonly used fortran compiler option, see your fortran compiler manual
#
#== BUGS
#
#If you find a bug, please report it at SPMODEL Development Group
#<dcstaff_(at)_gfd-dennou.org>
#=end

EOF


cat >> $out <<EOF
prefix="$prefix"
exec_prefix=${prefix}
bindir=${prefix}/bin
dcpamconfig=${prefix}/bin/dcpamconfig

files=""
while test \$# -gt 0; do
    case "\$1" in
    --help)       usage 0              ;;
    --zonal)      dcpamconfig=${prefix}/bin/dcpamzonalconfig  ;;
    --mpi)        dcpamconfig=${prefix}/bin/dcpammpiconfig    ;;
	*)        files="\$files \$1" ;;
    esac
    shift
done

fc=\`\$dcpamconfig --fc\`
fcflags=\`\$dcpamconfig --fcflags\`
ldflags=\`\$dcpamconfig --ldflags\`
ldlibs=\`\$dcpamconfig --ldlibs\`
version="$version"

EOF

cat >> $out <<EOF

# echo \$fc \$fcflags "\$@" \$ldflags \$ldlibs
# exec \$fc \$fcflags "\$@" \$ldflags \$ldlibs
echo \$fc \$fcflags \$files \$ldflags \$ldlibs
exec \$fc \$fcflags \$files \$ldflags \$ldlibs

EOF

