2014-02-12 21:47:13 +00:00
|
|
|
import sys
|
|
|
|
import os
|
2014-07-22 06:43:01 +00:00
|
|
|
import shutil
|
2014-02-12 21:47:13 +00:00
|
|
|
import multiprocessing
|
|
|
|
import SCons.Util
|
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
|
|
|
opts = Variables('Local.sc')
|
|
|
|
|
|
|
|
opts.AddVariables(
|
|
|
|
("CC", "C Compiler"),
|
|
|
|
("AS", "Assembler"),
|
|
|
|
("LINK", "Linker"),
|
2014-10-10 04:14:58 +00:00
|
|
|
("AR", "Archiver"),
|
|
|
|
("RANLIB", "Archiver Indexer"),
|
2014-02-12 21:47:13 +00:00
|
|
|
("BUILDTYPE", "Build type (RELEASE, DEBUG, or PERF)", "RELEASE"),
|
|
|
|
("VERBOSE", "Show full build information (0 or 1)", "0"),
|
2023-08-30 16:58:14 +00:00
|
|
|
("STRICT", "Strict error checking (0 or 1)", "0"),
|
2014-02-12 21:47:13 +00:00
|
|
|
("NUMCPUS", "Number of CPUs to use for build (0 means auto).", "0"),
|
|
|
|
("WITH_GPROF", "Include gprof profiling (0 or 1).", "0"),
|
|
|
|
("PREFIX", "Installation target directory.", "#pxelinux"),
|
2014-08-01 23:20:40 +00:00
|
|
|
("ARCH", "Target Architecture", "amd64"),
|
2019-07-31 21:30:50 +00:00
|
|
|
("BOOTDISK", "Build boot disk (0 or 1)", "1"),
|
2014-08-01 23:20:40 +00:00
|
|
|
("BOOTDISK_SIZE", "Boot disk size", "128")
|
2014-02-12 21:47:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
env = Environment(options = opts,
|
2023-08-22 22:03:24 +00:00
|
|
|
tools = ['default', 'compilation_db'],
|
2014-02-12 21:47:13 +00:00
|
|
|
ENV = os.environ)
|
|
|
|
Help(opts.GenerateHelpText(env))
|
|
|
|
|
|
|
|
# Copy environment variables
|
2022-12-10 04:29:49 +00:00
|
|
|
if 'CC' in os.environ:
|
2014-02-12 21:47:13 +00:00
|
|
|
env["CC"] = os.getenv('CC')
|
2022-12-10 04:29:49 +00:00
|
|
|
if 'AS' in os.environ:
|
2014-02-12 21:47:13 +00:00
|
|
|
env["AS"] = os.getenv('AS')
|
2022-12-10 04:29:49 +00:00
|
|
|
if 'LD' in os.environ:
|
2014-02-12 21:47:13 +00:00
|
|
|
env["LINK"] = os.getenv('LD')
|
2022-12-10 04:29:49 +00:00
|
|
|
if 'AR' in os.environ:
|
2014-10-10 04:14:58 +00:00
|
|
|
env["AR"] = os.getenv('AR')
|
2022-12-10 04:29:49 +00:00
|
|
|
if 'RANLIB' in os.environ:
|
2014-10-10 04:14:58 +00:00
|
|
|
env["RANLIB"] = os.getenv('RANLIB')
|
2022-12-10 04:29:49 +00:00
|
|
|
if 'CFLAGS' in os.environ:
|
2014-02-12 21:47:13 +00:00
|
|
|
env.Append(CCFLAGS = SCons.Util.CLVar(os.environ['CFLAGS']))
|
2022-12-10 04:29:49 +00:00
|
|
|
if 'CPPFLAGS' in os.environ:
|
2014-02-12 21:47:13 +00:00
|
|
|
env.Append(CPPFLAGS = SCons.Util.CLVar(os.environ['CPPFLAGS']))
|
2022-12-10 04:29:49 +00:00
|
|
|
if 'LDFLAGS' in os.environ:
|
2014-02-12 21:47:13 +00:00
|
|
|
env.Append(LINKFLAGS = SCons.Util.CLVar(os.environ['LDFLAGS']))
|
|
|
|
|
2023-09-11 01:03:01 +00:00
|
|
|
toolenv = env.Clone()
|
|
|
|
|
2014-09-29 20:46:38 +00:00
|
|
|
env.Append(CFLAGS = [ "-Wshadow", "-Wno-typedef-redefinition" ])
|
2023-09-11 00:56:49 +00:00
|
|
|
env.Append(CPPFLAGS = [ "-target", "x86_64-freebsd-freebsd-elf",
|
|
|
|
"-fno-builtin", "-fno-stack-protector",
|
2023-08-30 19:12:24 +00:00
|
|
|
"-fno-optimize-sibling-calls" ])
|
2023-09-11 00:56:49 +00:00
|
|
|
env.Append(LINKFLAGS = [ "-no-pie" ])
|
2023-08-30 16:58:14 +00:00
|
|
|
|
|
|
|
if (env["STRICT"] == "1"):
|
|
|
|
env.Append(CPPFLAGS = [ "-Wformat=2", "-Wmissing-format-attribute",
|
|
|
|
"-Wthread-safety", "-Wwrite-strings" ])
|
2014-02-12 21:47:13 +00:00
|
|
|
|
|
|
|
if env["WITH_GPROF"] == "1":
|
|
|
|
env.Append(CPPFLAGS = [ "-pg" ])
|
|
|
|
env.Append(LINKFLAGS = [ "-pg" ])
|
|
|
|
|
2015-11-15 23:17:18 +00:00
|
|
|
env.Append(CPPFLAGS = "-DBUILDTYPE=" + env["BUILDTYPE"])
|
2014-02-12 21:47:13 +00:00
|
|
|
if env["BUILDTYPE"] == "DEBUG":
|
|
|
|
env.Append(CPPFLAGS = [ "-g", "-DDEBUG", "-Wall",
|
|
|
|
"-Wno-deprecated-declarations" ])
|
2023-09-23 01:36:50 +00:00
|
|
|
env.Append(LINKFLAGS = [ "-g" ])
|
2014-02-12 21:47:13 +00:00
|
|
|
elif env["BUILDTYPE"] == "PERF":
|
|
|
|
env.Append(CPPFLAGS = [ "-g", "-DNDEBUG", "-Wall", "-O2"])
|
2023-09-23 01:36:50 +00:00
|
|
|
env.Append(LDFLAGS = [ "-g" ])
|
2014-02-12 21:47:13 +00:00
|
|
|
elif env["BUILDTYPE"] == "RELEASE":
|
|
|
|
env.Append(CPPFLAGS = ["-DNDEBUG", "-Wall", "-O2"])
|
|
|
|
else:
|
2022-12-10 04:29:49 +00:00
|
|
|
print("Error BUILDTYPE must be RELEASE or DEBUG")
|
2014-02-12 21:47:13 +00:00
|
|
|
sys.exit(-1)
|
|
|
|
|
|
|
|
if env["ARCH"] != "amd64":
|
2022-12-10 04:29:49 +00:00
|
|
|
print("Unsupported architecture: " + env["ARCH"])
|
2014-02-12 21:47:13 +00:00
|
|
|
sys.exit(-1)
|
|
|
|
|
|
|
|
try:
|
|
|
|
hf = open(".git/HEAD", 'r')
|
|
|
|
head = hf.read()
|
|
|
|
if head.startswith("ref: "):
|
|
|
|
if head.endswith("\n"):
|
|
|
|
head = head[0:-1]
|
|
|
|
with open(".git/" + head[5:]) as bf:
|
|
|
|
branch = bf.read()
|
|
|
|
if branch.endswith("\n"):
|
|
|
|
branch = branch[0:-1]
|
|
|
|
env.Append(CPPFLAGS = [ "-DGIT_VERSION=\\\"" + branch + "\\\""])
|
|
|
|
except IOError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if env["VERBOSE"] == "0":
|
|
|
|
env["CCCOMSTR"] = "Compiling $SOURCE"
|
|
|
|
env["SHCCCOMSTR"] = "Compiling $SOURCE"
|
|
|
|
env["ARCOMSTR"] = "Creating library $TARGET"
|
|
|
|
env["RANLIBCOMSTR"] = "Indexing library $TARGET"
|
|
|
|
env["LINKCOMSTR"] = "Linking $TARGET"
|
2014-10-10 04:14:58 +00:00
|
|
|
env["ASCOMSTR"] = "Assembling $TARGET"
|
|
|
|
env["ASPPCOMSTR"] = "Assembling $TARGET"
|
|
|
|
env["ARCOMSTR"] = "Archiving $TARGET"
|
|
|
|
env["RANLIBCOMSTR"] = "Indexing $TARGET"
|
2014-02-12 21:47:13 +00:00
|
|
|
|
|
|
|
def GetNumCPUs(env):
|
|
|
|
if env["NUMCPUS"] != "0":
|
|
|
|
return int(env["NUMCPUS"])
|
|
|
|
return 2*multiprocessing.cpu_count()
|
|
|
|
|
|
|
|
env.SetOption('num_jobs', GetNumCPUs(env))
|
|
|
|
|
2014-07-22 06:43:01 +00:00
|
|
|
def CopyTree(dst, src, env):
|
|
|
|
def DirCopyHelper(src, dst):
|
2022-12-10 04:29:49 +00:00
|
|
|
for f in os.listdir(src):
|
|
|
|
srcPath = os.path.join(src, f)
|
|
|
|
dstPath = os.path.join(dst, f)
|
2022-12-10 06:07:35 +00:00
|
|
|
if f.startswith("."):
|
|
|
|
# Ignore hidden files
|
|
|
|
pass
|
|
|
|
elif os.path.isdir(srcPath):
|
|
|
|
if not os.path.exists(dstPath):
|
|
|
|
os.makedirs(dstPath)
|
|
|
|
DirCopyHelper(srcPath, dstPath)
|
|
|
|
else:
|
|
|
|
env.Command(dstPath, srcPath, Copy("$TARGET", "$SOURCE"))
|
|
|
|
if (not os.path.exists(dst)):
|
|
|
|
os.makedirs(dst)
|
2014-07-22 06:43:01 +00:00
|
|
|
DirCopyHelper(src, dst)
|
|
|
|
|
2014-02-12 21:47:13 +00:00
|
|
|
# XXX: Hack to support clang static analyzer
|
|
|
|
def CheckFailed():
|
|
|
|
if os.getenv('CCC_ANALYZER_OUTPUT_FORMAT') != None:
|
|
|
|
return
|
|
|
|
Exit(1)
|
|
|
|
|
|
|
|
# Configuration
|
|
|
|
conf = env.Configure()
|
|
|
|
|
|
|
|
if not conf.CheckCC():
|
2022-12-10 04:29:49 +00:00
|
|
|
print('Your C compiler and/or environment is incorrectly configured.')
|
2014-02-12 21:47:13 +00:00
|
|
|
CheckFailed()
|
|
|
|
|
2023-08-22 22:03:24 +00:00
|
|
|
if not env["CCVERSION"].startswith("15."):
|
|
|
|
print('Only Clang 15 is supported')
|
|
|
|
print('You are running: ' + env["CCVERSION"])
|
|
|
|
CheckFailed()
|
|
|
|
|
2014-02-12 21:47:13 +00:00
|
|
|
conf.Finish()
|
|
|
|
|
|
|
|
Export('env')
|
2023-09-11 01:03:01 +00:00
|
|
|
Export('toolenv')
|
2014-02-12 21:47:13 +00:00
|
|
|
|
2023-08-22 22:03:24 +00:00
|
|
|
|
2015-02-27 23:57:07 +00:00
|
|
|
# Program start/end
|
|
|
|
env["CRTBEGIN"] = [ "#build/lib/libc/crti.o", "#build/lib/libc/crt1.o" ]
|
|
|
|
env["CRTEND"] = [ "#build/lib/libc/crtn.o" ]
|
|
|
|
|
2014-02-12 21:47:13 +00:00
|
|
|
# Debugging Tools
|
|
|
|
|
2014-07-22 06:43:01 +00:00
|
|
|
# Create include tree
|
|
|
|
CopyTree('build/include', 'include', env)
|
|
|
|
CopyTree('build/include/sys', 'sys/include', env)
|
|
|
|
CopyTree('build/include/machine', 'sys/' + env['ARCH'] + '/include', env)
|
2019-07-31 21:30:50 +00:00
|
|
|
#CopyTree('build/include/', 'lib/liblwip/src/include', env)
|
2014-07-22 06:43:01 +00:00
|
|
|
|
2014-02-12 21:47:13 +00:00
|
|
|
# Build Targets
|
|
|
|
SConscript('sys/SConscript', variant_dir='build/sys')
|
2014-07-28 00:09:31 +00:00
|
|
|
SConscript('lib/libc/SConscript', variant_dir='build/lib/libc')
|
2019-07-31 21:30:50 +00:00
|
|
|
#SConscript('lib/liblwip/SConscript', variant_dir='build/lib/liblwip')
|
2022-12-10 04:37:47 +00:00
|
|
|
SConscript('bin/cat/SConscript', variant_dir='build/bin/cat')
|
2022-12-10 06:01:38 +00:00
|
|
|
SConscript('bin/date/SConscript', variant_dir='build/bin/date')
|
2023-08-21 04:28:15 +00:00
|
|
|
SConscript('bin/echo/SConscript', variant_dir='build/bin/echo')
|
2015-01-27 18:35:20 +00:00
|
|
|
SConscript('bin/ethdump/SConscript', variant_dir='build/bin/ethdump')
|
2015-01-28 19:35:47 +00:00
|
|
|
SConscript('bin/ethinject/SConscript', variant_dir='build/bin/ethinject')
|
2022-12-10 04:37:47 +00:00
|
|
|
SConscript('bin/ls/SConscript', variant_dir='build/bin/ls')
|
2014-11-26 06:24:54 +00:00
|
|
|
SConscript('bin/shell/SConscript', variant_dir='build/bin/shell')
|
2015-01-23 21:02:31 +00:00
|
|
|
SConscript('sbin/ifconfig/SConscript', variant_dir='build/sbin/ifconfig')
|
2014-07-28 00:09:31 +00:00
|
|
|
SConscript('sbin/init/SConscript', variant_dir='build/sbin/init')
|
2015-11-15 23:17:18 +00:00
|
|
|
SConscript('sbin/sysctl/SConscript', variant_dir='build/sbin/sysctl')
|
2015-01-18 23:15:55 +00:00
|
|
|
SConscript('tests/SConscript', variant_dir='build/tests')
|
2014-02-12 21:47:13 +00:00
|
|
|
|
2014-08-01 21:15:06 +00:00
|
|
|
# Build Tools
|
|
|
|
env["TOOLCHAINBUILD"] = "TRUE"
|
|
|
|
env["CC"] = "cc"
|
2014-10-10 04:05:02 +00:00
|
|
|
env["LINK"] = "cc"
|
2014-08-01 21:15:06 +00:00
|
|
|
SConscript('sbin/newfs_o2fs/SConscript', variant_dir='build/tools/newfs_o2fs')
|
|
|
|
|
2023-08-22 22:03:24 +00:00
|
|
|
env.CompilationDatabase()
|
|
|
|
|
2014-02-12 21:47:13 +00:00
|
|
|
# Install Targets
|
|
|
|
env.Install('$PREFIX/','build/sys/castor')
|
|
|
|
env.Alias('install','$PREFIX')
|
|
|
|
|
2014-08-01 23:20:40 +00:00
|
|
|
# Boot Disk Target
|
2014-08-08 00:22:58 +00:00
|
|
|
if env["BOOTDISK"] == "1":
|
|
|
|
newfs = Builder(action = 'build/tools/newfs_o2fs/newfs_o2fs -s $BOOTDISK_SIZE -m $SOURCE $TARGET')
|
|
|
|
env.Append(BUILDERS = {'BuildImage' : newfs})
|
|
|
|
bootdisk = env.BuildImage('#build/bootdisk.img', '#release/bootdisk.manifest')
|
|
|
|
Depends(bootdisk, "#build/tools/newfs_o2fs/newfs_o2fs")
|
2022-12-10 04:37:47 +00:00
|
|
|
Depends(bootdisk, "#build/bin/cat/cat")
|
2022-12-10 06:01:38 +00:00
|
|
|
Depends(bootdisk, "#build/bin/date/date")
|
2023-08-21 04:28:15 +00:00
|
|
|
Depends(bootdisk, "#build/bin/echo/echo")
|
2015-01-27 18:35:20 +00:00
|
|
|
Depends(bootdisk, "#build/bin/ethdump/ethdump")
|
2015-01-28 19:35:47 +00:00
|
|
|
Depends(bootdisk, "#build/bin/ethinject/ethinject")
|
2022-12-10 04:37:47 +00:00
|
|
|
Depends(bootdisk, "#build/bin/ls/ls")
|
2014-11-26 06:24:54 +00:00
|
|
|
Depends(bootdisk, "#build/bin/shell/shell")
|
2015-01-23 21:02:31 +00:00
|
|
|
Depends(bootdisk, "#build/sbin/ifconfig/ifconfig")
|
2014-08-08 00:22:58 +00:00
|
|
|
Depends(bootdisk, "#build/sbin/init/init")
|
2015-11-15 23:17:18 +00:00
|
|
|
Depends(bootdisk, "#build/sbin/sysctl/sysctl")
|
2014-08-08 00:22:58 +00:00
|
|
|
Depends(bootdisk, "#build/sys/castor")
|
2019-07-31 21:30:50 +00:00
|
|
|
#Depends(bootdisk, "#build/tests/lwiptest")
|
2015-02-02 07:56:45 +00:00
|
|
|
Depends(bootdisk, "#build/tests/pthreadtest")
|
2023-10-02 22:16:15 +00:00
|
|
|
Depends(bootdisk, "#build/tests/spawnanytest")
|
|
|
|
Depends(bootdisk, "#build/tests/spawnmultipletest")
|
|
|
|
Depends(bootdisk, "#build/tests/spawnsingletest")
|
2015-01-18 23:15:55 +00:00
|
|
|
Depends(bootdisk, "#build/tests/threadtest")
|
2014-08-08 00:22:58 +00:00
|
|
|
env.Alias('bootdisk', '#build/bootdisk.img')
|
|
|
|
env.Install('$PREFIX/','#build/bootdisk.img')
|
2014-08-01 23:20:40 +00:00
|
|
|
|