#!/usr/bin/env python

"""
build ww3 library
"""
import sys, os, shutil
from distutils.spawn import find_executable

_CIMEROOT = os.environ.get("CIMEROOT")
if _CIMEROOT is None:
    raise SystemExit("ERROR: must set CIMEROOT environment variable")

_LIBDIR = os.path.join(_CIMEROOT, "scripts", "Tools")
sys.path.append(_LIBDIR)

from standard_script_setup import *
from CIME.buildlib         import parse_input
from CIME.case             import Case

logger = logging.getLogger(__name__)

###############################################################################
def buildlib(bldroot, installpath, case):
###############################################################################
    srcroot = case.get_value("SRCROOT")
    caseroot = case.get_value("CASEROOT")
    casebuild = case.get_value("CASEBUILD")

    with open(os.path.join(casebuild, "ww3conf", "Filepath"), "w") as fd:
        fd.write(f"{caseroot}/SourceMods/src.ww3\n")
        fd.write(f"{srcroot}/components/ww3/src/WW3/model/src\n")
        fd.write(f"{srcroot}/components/ww3/src/WW3/model/src/SCRIP\n")
        fd.write(f"{srcroot}/components/ww3/src/cpl\n")

    cmake_args = " -DSWITCH=E3SM"

    return cmake_args

###############################################################################
def _main_func():
###############################################################################
    caseroot, libroot, bldroot = parse_input(sys.argv)
    with Case(caseroot, read_only=False) as case:
        buildlib(bldroot, libroot, case)

###############################################################################

if __name__ == "__main__":
    _main_func()
