-
Notifications
You must be signed in to change notification settings - Fork 23
/
buildlib.csm_share
executable file
·159 lines (126 loc) · 6.13 KB
/
buildlib.csm_share
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env python3
import sys,os
_CIMEROOT = os.getenv("CIMEROOT")
sys.path.append(os.path.join(_CIMEROOT,"scripts","Tools"))
from standard_script_setup import *
from CIME.utils import copyifnewer, run_bld_cmd_ensure_logging, expect, symlink_force
from CIME.case import Case
from CIME.build import get_standard_makefile_args
import glob
logger = logging.getLogger(__name__)
def parse_command_line(args, description):
###############################################################################
parser = argparse.ArgumentParser(
usage="""\n{0} [--debug]
OR
{0} --verbose
OR
{0} --help
\033[1mEXAMPLES:\033[0m
\033[1;32m# Run \033[0m
> {0}
""" .format (os.path.basename(args[0])),
description=description,
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
CIME.utils.setup_standard_logging_options(parser)
parser.add_argument("buildroot",
help="build path root")
parser.add_argument("installpath",
help="install path ")
parser.add_argument("caseroot", nargs="?", default=os.getcwd(),
help="Case directory to build")
args = CIME.utils.parse_args_and_handle_standard_logging_options(args, parser)
return args.buildroot, args.installpath, args.caseroot
def buildlib(bldroot, installpath, case):
###############################################################################
gmake_args = get_standard_makefile_args(case, shared_lib=True)
srcroot = case.get_value("SRCROOT")
caseroot = case.get_value("CASEROOT")
libroot = case.get_value("LIBROOT")
filepath = [os.path.join(caseroot,"SourceMods","src.share")]
filepath.extend([os.path.join(srcroot,"components","cmeps", "cesm", "nuopc_cap_share"),
os.path.join(srcroot,"components","cmeps", "cesm", "flux_atmocn"),
os.path.join(srcroot,"share","src"),
os.path.join(srcroot,"share","src","water_isotopes"),
os.path.join(srcroot,"share","RandNum","src"),
os.path.join(srcroot,"share","RandNum","src","dsfmt_f03"),
os.path.join(srcroot,"share","RandNum","src","kissvec"),
os.path.join(srcroot,"share","RandNum","src","mt19937")])
#
# Provide an interface to the CrayLabs SmartSim tools, if the tools are not used
# then build a stub interface. See cime/tools/smartsim/README.md for details
#
if case.get_value("USE_SMARTSIM"):
smartredis_lib = os.getenv("SMARTREDIS_LIB")
expect(smartredis_lib," Expect path to SMARTREDIS in env variable SMARTREDIS_LIB - is the module loaded?")
fortran_src_path = os.getenv("SMARTREDIS_FSRC")
expect(fortran_src_path," Expect path to SMARTREDIS fortran source code in env variable SMARTREDIS_FSRC - is the module loaded?")
redis_include_path = os.getenv("SMARTREDIS_INCLUDE")
expect(os.path.isdir(redis_include_path), "Could not find or read directory {}".format(redis_include_path))
os.environ["USER_INCLDIR"] = "-I" + redis_include_path
gmake_args += " USE_SMARTSIM=TRUE "
else:
fortran_src_path = os.path.join(srcroot,"share","src","stubs","smartredis")
expect(os.path.isdir(fortran_src_path), "Could not find or read directory {}".format(fortran_src_path))
filepath.append(fortran_src_path)
libdir = os.path.join(bldroot,"csm_share")
if not os.path.isdir(libdir):
os.makedirs(libdir)
filepathfile = os.path.join(libdir, "Filepath")
# if the filepathfile has a different number of lines than filepath, replace it
file_len = 0
if os.path.isfile(filepathfile):
file_len = len(open(filepathfile).readlines())
if len(filepath) != file_len:
with open(filepathfile, "w") as fd:
for path in filepath:
fd.write("{}\n".format(path))
components = case.get_values("COMP_CLASSES")
multiinst_cppdefs = ""
multi_driver = case.get_value("MULTI_DRIVER")
for comp in components:
if comp == "CPL":
continue
if multi_driver:
ninst_comp = 1
else:
ninst_comp = case.get_value("NINST_{}".format(comp))
multiinst_cppdefs += " -DNUM_COMP_INST_{}={}".format(comp, ninst_comp)
if case.get_value("COMP_OCN") == "nemo":
multiinst_cppdefs += " -DNEMO_IN_CCSM "
print(f"here installpath is {installpath}")
for ndir in ("lib", "include"):
if not os.path.isdir(os.path.join(installpath,ndir)):
os.makedirs(os.path.join(installpath,ndir))
# copy some header files
for _file in glob.iglob(os.path.join(srcroot,"share","include","*")):
copyifnewer(_file, os.path.join(installpath, "include", os.path.basename(_file)))
for _file in glob.iglob(os.path.join(srcroot,"share","RandNum","include","*")):
copyifnewer(_file, os.path.join(installpath, "include", os.path.basename(_file)))
# This runs the make command
gmake_opts = "-f {}/Makefile complib MODEL=csm_share COMP_NAME=csm_share ".format(os.path.join(caseroot,"Tools"))
gmake_opts += "-j {} ".format(case.get_value("GMAKE_J"))
gmake_opts += " COMPLIB=libcsm_share.a"
gmake_opts += ' USER_CPPDEFS="{} -DTIMING" '.format(multiinst_cppdefs)
gmake_opts += "INCLUDE_DIR={} ".format(os.path.join(installpath, "include"))
gmake_opts += gmake_args
gmake_opts += " -C {}".format(libdir)
gmake_cmd = case.get_value("GMAKE")
cmd = "{} {}".format(gmake_cmd, gmake_opts)
run_bld_cmd_ensure_logging(cmd, logger)
#
# The pgi compiler sometimes has issues with long include paths
# on the command line, this is a workaround for that problem
#
case_inc_dir = os.path.join(libroot, "include")
if not os.path.isdir(case_inc_dir):
os.mkdir(case_inc_dir)
for _file in glob.iglob(os.path.join(installpath,"include","*")):
symlink_force(_file, os.path.join(case_inc_dir,os.path.basename(_file)))
def _main(argv, documentation):
bldroot, installpath, caseroot = parse_command_line(argv, documentation)
with Case(caseroot) as case:
buildlib(bldroot, installpath, case)
if (__name__ == "__main__"):
_main(sys.argv, __doc__)