Update SConstruct to Python3

This commit is contained in:
Ali Mashtizadeh 2022-12-09 23:29:49 -05:00
parent 04b709f3b3
commit 98a9fc5a6f

View File

@ -31,34 +31,36 @@ env = Environment(options = opts,
Help(opts.GenerateHelpText(env)) Help(opts.GenerateHelpText(env))
# Copy environment variables # Copy environment variables
if os.environ.has_key('CC'): if 'CC' in os.environ:
env["CC"] = os.getenv('CC') env["CC"] = os.getenv('CC')
if os.environ.has_key('CXX'): if 'CXX' in os.environ:
env["CXX"] = os.getenv('CXX') env["CXX"] = os.getenv('CXX')
if os.environ.has_key('AS'): if 'AS' in os.environ:
env["AS"] = os.getenv('AS') env["AS"] = os.getenv('AS')
if os.environ.has_key('LD'): if 'LD' in os.environ:
env["LINK"] = os.getenv('LD') env["LINK"] = os.getenv('LD')
if os.environ.has_key('AR'): if 'AR' in os.environ:
env["AR"] = os.getenv('AR') env["AR"] = os.getenv('AR')
if os.environ.has_key('RANLIB'): if 'RANLIB' in os.environ:
env["RANLIB"] = os.getenv('RANLIB') env["RANLIB"] = os.getenv('RANLIB')
if os.environ.has_key('CFLAGS'): if 'CFLAGS' in os.environ:
env.Append(CCFLAGS = SCons.Util.CLVar(os.environ['CFLAGS'])) env.Append(CCFLAGS = SCons.Util.CLVar(os.environ['CFLAGS']))
if os.environ.has_key('CPPFLAGS'): if 'CPPFLAGS' in os.environ:
env.Append(CPPFLAGS = SCons.Util.CLVar(os.environ['CPPFLAGS'])) env.Append(CPPFLAGS = SCons.Util.CLVar(os.environ['CPPFLAGS']))
if os.environ.has_key('CXXFLAGS'): if 'CXXFLAGS' in os.environ:
env.Append(CXXFLAGS = SCons.Util.CLVar(os.environ['CXXFLAGS'])) env.Append(CXXFLAGS = SCons.Util.CLVar(os.environ['CXXFLAGS']))
if os.environ.has_key('LDFLAGS'): if 'LDFLAGS' in os.environ:
env.Append(LINKFLAGS = SCons.Util.CLVar(os.environ['LDFLAGS'])) env.Append(LINKFLAGS = SCons.Util.CLVar(os.environ['LDFLAGS']))
#env.Append(CPPFLAGS = [ "-Wall", "-Wformat=2", "-Wextra", "-Wwrite-strings", #env.Append(CPPFLAGS = [ "-Wall", "-Wformat=2", "-Wextra", "-Wwrite-strings",
# "-Wno-unused-parameter", "-Wmissing-format-attribute", # "-Wno-unused-parameter", "-Wmissing-format-attribute",
# "-Werror" ]) # "-Werror" ])
#
env.Append(CFLAGS = [ "-Wshadow", "-Wno-typedef-redefinition" ]) env.Append(CFLAGS = [ "-Wshadow", "-Wno-typedef-redefinition" ])
#env.Append(CXXFLAGS = [ "-Wno-non-template-friend", "-Woverloaded-virtual", #env.Append(CXXFLAGS = [ "-Wno-non-template-friend", "-Woverloaded-virtual",
# "-Wcast-qual", "-Wcast-align", "-Wconversion", # "-Wcast-qual", "-Wcast-align", "-Wconversion",
# "-Weffc++", "-std=c++0x", "-Werror" ]) # "-Weffc++", "-std=c++0x", "-Werror" ])
env.Append(CXXFLAGS = [ "-fno-builtin" ])
if env["WITH_GPROF"] == "1": if env["WITH_GPROF"] == "1":
env.Append(CPPFLAGS = [ "-pg" ]) env.Append(CPPFLAGS = [ "-pg" ])
@ -75,11 +77,11 @@ elif env["BUILDTYPE"] == "PERF":
elif env["BUILDTYPE"] == "RELEASE": elif env["BUILDTYPE"] == "RELEASE":
env.Append(CPPFLAGS = ["-DNDEBUG", "-Wall", "-O2"]) env.Append(CPPFLAGS = ["-DNDEBUG", "-Wall", "-O2"])
else: else:
print "Error BUILDTYPE must be RELEASE or DEBUG" print("Error BUILDTYPE must be RELEASE or DEBUG")
sys.exit(-1) sys.exit(-1)
if env["ARCH"] != "amd64": if env["ARCH"] != "amd64":
print "Unsupported architecture: " + env["ARCH"] print("Unsupported architecture: " + env["ARCH"])
sys.exit(-1) sys.exit(-1)
try: try:
@ -118,20 +120,20 @@ env.SetOption('num_jobs', GetNumCPUs(env))
def CopyTree(dst, src, env): def CopyTree(dst, src, env):
def DirCopyHelper(src, dst): def DirCopyHelper(src, dst):
for f in os.listdir(src): for f in os.listdir(src):
srcPath = os.path.join(src, f) srcPath = os.path.join(src, f)
dstPath = os.path.join(dst, f) dstPath = os.path.join(dst, f)
if f.startswith("."): if f.startswith("."):
# Ignore hidden files # Ignore hidden files
pass pass
elif os.path.isdir(srcPath): elif os.path.isdir(srcPath):
if not os.path.exists(dstPath): if not os.path.exists(dstPath):
os.makedirs(dstPath) os.makedirs(dstPath)
DirCopyHelper(srcPath, dstPath) DirCopyHelper(srcPath, dstPath)
else: else:
env.Command(dstPath, srcPath, Copy("$TARGET", "$SOURCE")) env.Command(dstPath, srcPath, Copy("$TARGET", "$SOURCE"))
if (not os.path.exists(dst)): if (not os.path.exists(dst)):
os.makedirs(dst) os.makedirs(dst)
DirCopyHelper(src, dst) DirCopyHelper(src, dst)
# XXX: Hack to support clang static analyzer # XXX: Hack to support clang static analyzer
@ -144,11 +146,11 @@ def CheckFailed():
conf = env.Configure() conf = env.Configure()
if not conf.CheckCC(): if not conf.CheckCC():
print 'Your C compiler and/or environment is incorrectly configured.' print('Your C compiler and/or environment is incorrectly configured.')
CheckFailed() CheckFailed()
if not conf.CheckCXX(): if not conf.CheckCXX():
print 'Your C++ compiler and/or environment is incorrectly configured.' print('Your C++ compiler and/or environment is incorrectly configured.')
CheckFailed() CheckFailed()
conf.Finish() conf.Finish()