mirror of https://github.com/flysand7/ciabatta.git
add more options
This commit is contained in:
parent
45ae248539
commit
8ceb3e2e49
48
build.py
48
build.py
|
@ -9,9 +9,16 @@ import re
|
||||||
|
|
||||||
arg_parser = argparse.ArgumentParser(description="Build ciabatta", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
arg_parser = argparse.ArgumentParser(description="Build ciabatta", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||||
arg_parser.add_argument("-t", "--test", help="Specify a file to compile with ciabatta")
|
arg_parser.add_argument("-t", "--test", help="Specify a file to compile with ciabatta")
|
||||||
|
arg_parser.add_argument("-m", "--mode", help="Specify mode (release, debug)")
|
||||||
|
arg_parser.add_argument("--ld", action="store_true", help="Enable loader debugging (only works with --mode debug)")
|
||||||
args = vars(arg_parser.parse_args())
|
args = vars(arg_parser.parse_args())
|
||||||
|
|
||||||
test_file = args['test']
|
test_file = args['test']
|
||||||
|
build_mode = args['mode']
|
||||||
|
loader_debugging_enabled = args['ld']
|
||||||
|
|
||||||
|
if build_mode == None:
|
||||||
|
build_mode = 'debug'
|
||||||
|
|
||||||
class colors:
|
class colors:
|
||||||
grey='\033[38;5;243m'
|
grey='\033[38;5;243m'
|
||||||
|
@ -47,6 +54,28 @@ cc_flags = []
|
||||||
cc_defines = []
|
cc_defines = []
|
||||||
cc_includes = []
|
cc_includes = []
|
||||||
|
|
||||||
|
cc_flags_stack = []
|
||||||
|
def cc_flags_push():
|
||||||
|
global cc_flags
|
||||||
|
global cc_flags_stack
|
||||||
|
cc_flags_stack.append(cc_flags)
|
||||||
|
cc_flags = cc_flags.copy()
|
||||||
|
def cc_flags_pop():
|
||||||
|
global cc_flags
|
||||||
|
global cc_flags_stack
|
||||||
|
cc_flags = cc_flags_stack.pop()
|
||||||
|
|
||||||
|
cc_defines_stack = []
|
||||||
|
def cc_defines_push():
|
||||||
|
global cc_defines
|
||||||
|
global cc_defines_stack
|
||||||
|
cc_defines_stack.append(cc_defines)
|
||||||
|
cc_defines = cc_defines.copy()
|
||||||
|
def cc_defines_pop():
|
||||||
|
global cc_defines
|
||||||
|
global cc_defines_stack
|
||||||
|
cc_defines = cc_defines_stack.pop()
|
||||||
|
|
||||||
def compile(output, inputs, additional_flags=[]):
|
def compile(output, inputs, additional_flags=[]):
|
||||||
flags_cmdline = ' '.join(cc_flags + additional_flags)
|
flags_cmdline = ' '.join(cc_flags + additional_flags)
|
||||||
defines_cmdline = ' '.join(map(prefix('-D '), map(quote, cc_defines)))
|
defines_cmdline = ' '.join(map(prefix('-D '), map(quote, cc_defines)))
|
||||||
|
@ -85,16 +114,23 @@ target_abi = 'sysv'
|
||||||
target_arch = 'x86-64'
|
target_arch = 'x86-64'
|
||||||
target_os = 'linux'
|
target_os = 'linux'
|
||||||
|
|
||||||
|
cc_defines.append(f'_CIA_OS_CONF=\\"os/{target_os}/conf.h\\"')
|
||||||
cc_flags.extend(['-nostdlib', '-fno-stack-protector'])
|
cc_flags.extend(['-nostdlib', '-fno-stack-protector'])
|
||||||
|
|
||||||
|
if build_mode == 'debug':
|
||||||
cc_flags.extend(['-g', '-O0'])
|
cc_flags.extend(['-g', '-O0'])
|
||||||
cc_defines.append('_DEBUG')
|
cc_defines.append('_DEBUG')
|
||||||
cc_defines.append(f'_CIA_OS_CONF=\\"os/{target_os}/conf.h\\"')
|
elif build_mode == 'release':
|
||||||
|
cc_flags.extend(['-O3'])
|
||||||
|
cc_defines.append('NDEBUG')
|
||||||
|
|
||||||
cc_includes.append('include')
|
cc_includes.append('include')
|
||||||
cc_includes.append('include/linux')
|
cc_includes.append('include/linux')
|
||||||
|
|
||||||
# Build the dynamic loader
|
# Build the dynamic loader
|
||||||
loader_flags = [
|
cc_flags_push()
|
||||||
|
cc_defines_push()
|
||||||
|
cc_flags.extend([
|
||||||
'-Wl,-e,_dlstart',
|
'-Wl,-e,_dlstart',
|
||||||
'-Wl,--sort-section,alignment',
|
'-Wl,--sort-section,alignment',
|
||||||
'-Wl,--sort-common',
|
'-Wl,--sort-common',
|
||||||
|
@ -102,10 +138,14 @@ loader_flags = [
|
||||||
'-Wl,--hash-style=both',
|
'-Wl,--hash-style=both',
|
||||||
'-Wl,--no-undefined',
|
'-Wl,--no-undefined',
|
||||||
'-Wl,--exclude-libs=ALL'
|
'-Wl,--exclude-libs=ALL'
|
||||||
]
|
])
|
||||||
|
if loader_debugging_enabled:
|
||||||
|
cc_defines.append('_CIA_LD_DEBUG')
|
||||||
print_step("Building lib/ld-cia.so\n")
|
print_step("Building lib/ld-cia.so\n")
|
||||||
assemble_obj('bin/loader-entry.o', [f'arch/{target_abi}_{target_arch}/loader-entry.asm'], ['-f "elf64"'])
|
assemble_obj('bin/loader-entry.o', [f'arch/{target_abi}_{target_arch}/loader-entry.asm'], ['-f "elf64"'])
|
||||||
compile_shared('lib/ld-cia.so', ['bin/loader-entry.o','loader/loader-self-reloc.c','loader/loader.c'], loader_flags)
|
compile_shared('lib/ld-cia.so', ['bin/loader-entry.o','loader/loader-self-reloc.c','loader/loader.c'])
|
||||||
|
cc_defines_pop()
|
||||||
|
cc_flags_pop()
|
||||||
|
|
||||||
# Build the ciabatta
|
# Build the ciabatta
|
||||||
print_step("Building lib/cia.a\n")
|
print_step("Building lib/cia.a\n")
|
||||||
|
|
|
@ -107,7 +107,7 @@ static void printf(char *fmt, ...) {
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_DEBUG)
|
#if defined(_DEBUG) && defined(_CIA_LD_DEBUG)
|
||||||
#define _dbg_print_char(c) print_char(c)
|
#define _dbg_print_char(c) print_char(c)
|
||||||
#define _dbg_print_string(s) print_string(s)
|
#define _dbg_print_string(s) print_string(s)
|
||||||
#define _dbg_print_string_n(s,n) print_string_n(s,n)
|
#define _dbg_print_string_n(s,n) print_string_n(s,n)
|
||||||
|
|
Loading…
Reference in New Issue