import os import subprocess AddOption( '--arch', dest = 'arch', type = 'choice', choices = ('i686', 'x86_64'), nargs = 1, action = 'store', default = 'x86_64' ) AddOption( '--target', dest = 'target', type = 'choice', choices = ('os', 'stdlib'), nargs = 1, action = 'store', default = 'os' ) arch = GetOption('arch') target = GetOption('target') env = Environment(tools = ['default', 'compilation_db'], ENV = os.environ) # TODO inheriting the environment is not a best practice env.Append(CCFLAGS = ['-g', '-O0', '-fno-stack-protector']) env.Append(CPPDEFINES = ['BASTL_EXTENSIONS=1']) env['BUILD_TARGET'] = target env['TARGET_ARCH'] = arch # env.Append(CCFLAGS = ['-O2']) env['ISO_FILES'] = [] env = SConscript('targets/_any/SConscript', exports = 'env') if env['BUILD_TARGET'] == 'os': env = SConscript(f'targets/{arch}/SConscript', exports = 'env') comp_db = env.CompilationDatabase(target = '#compile_commands.json') env.Default(comp_db) iso_targets = [] for iso_file in env['ISO_FILES']: iso_targets.append(env.Command(f'iso/{iso_file["target"]}', iso_file["source"], Copy("$TARGET", "$SOURCE"))) env.Command('os.iso', iso_targets, 'grub-mkrescue -o "$TARGET" "iso"')