forked from derpycode/ctoaster.cupcake
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SConstruct
74 lines (59 loc) · 2.22 KB
/
SConstruct
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
from __future__ import print_function
import os
import platform as P
import sys
# Assuming version.py, utils.py, and other required modules are in appropriate paths.
# Check for version.py to set up environment.
if os.path.exists("version.py"):
exec(open("version.py").read(), globals())
else:
srcdir = "src"
build_type = "debug" if "debug" in ARGUMENTS else "normal"
sys.path.append("tools")
import utils as U
# Ensure cTOASTER is set up correctly.
if not U.read_ctoaster_config():
sys.exit("cTOASTER not set up: run the setup.py script!")
# Load platform configuration.
platform = U.discover_platform()
print(f'Using platform "{platform}"')
exec(open(os.path.join(U.ctoaster_root, "platforms", platform)).read(), globals())
# NetCDF paths - assuming netcdf dictionary is defined somewhere.
netcdfinc, netcdflib = netcdf["base"]
# Define modules and utils.
modules = Split(
"""atchem biogem embm ents gemlite goldstein goldsteinseaice rokgem sedgem"""
)
utils = Split("common utils wrappers")
subdirs = modules + utils
# F90 module search paths.
modpath = [os.path.join("#/build", d) for d in subdirs]
# Version and compilation flags.
rev = ARGUMENTS.get("rev", "UNKNOWN")
defs = [f"-DREV={rev}"]
# Environment setup.
envcopy = os.environ.copy()
baselinkflags = f90.get("baselinkflags", [])
extraf90flags = f90.get(build_type, [])
extralinkflags = f90.get(f"{build_type}_link", [])
extraf90libpaths = [f90["libpath"]] if "libpath" in f90 else []
extraf90libs = [f90["libs"]] if "libs" in f90 else []
target_vs_arch = os.environ.get("TARGET_VS_ARCH", "linux")
env = Environment(
ENV=envcopy,
TOOLS=["default", f90["compiler"]],
HOST_ARCH=target_vs_arch,
F90FLAGS=f90["baseflags"] + extraf90flags + defs,
LINKFLAGS=baselinkflags + extralinkflags,
F90PATH=[netcdfinc] + modpath,
FORTRANMODDIRPREFIX=f90["module_dir"],
FORTRANMODDIR="${TARGET.dir}",
LIBPATH=[netcdflib] + extraf90libpaths,
LIBS=netcdf["libs"] + extraf90libs,
)
if "ld_library_path" in f90:
env["ENV"]["LD_LIBRARY_PATH"] = f90["ld_library_path"]
# Build configuration.
Export("env", "subdirs", "build_type")
SConscript(os.path.join(srcdir, "SConscript"), variant_dir="#build", duplicate=0)
Install(".", "build/cupcake.exe")