struct
{
- bool address_sanitizer,
- thread_sanitizer,
- no_pdb;
-
- c8 binary_name[ 128 ];
+ c8 project_name[ 128 ];
struct stack_allocator all;
}
static _metacompiler;
-struct source_file
+struct command
{
- enum source_type
+ enum command_type
{
k_source_c,
k_source_include_path
if( compare_buffers( keyvalues_key( kvs, kv, NULL ), 0, "name", 0 ) )
{
buffer_copy( keyvalues_value( kvs, kv, NULL ), 0,
- _metacompiler.binary_name, sizeof(_metacompiler.binary_name ) );
+ _metacompiler.project_name, sizeof(_metacompiler.project_name) );
}
if( compare_buffers( keyvalues_key( kvs, kv, NULL ), 0, "add", 0 ) )
{
- struct source_file *source = stretchy_append( &_source_list );
+ struct command *source = stretchy_append( &_source_list );
source->type = k_source_c;
stream_open_stack( &source->path, &_metacompiler.all, k_stream_null_terminate );
if( compare_buffers( keyvalues_key( kvs, kv, NULL ), 0, "include", 0 ) )
{
- struct source_file *source = stretchy_append( &_source_list );
+ struct command *source = stretchy_append( &_source_list );
source->type = k_source_include_path;
stream_open_stack( &source->path, &_metacompiler.all, k_stream_null_terminate );
ASSERT_CRITICAL( system(call) == 0 );
}
+static i32 enum_read( const c8 *options[], u32 option_count, const c8 *input )
+{
+ for( i32 i=0; i<option_count; i ++ )
+ if( compare_buffers( input, 0, options[i], 0 ) )
+ return i;
+
+ $log( $fatal, {"Supplied option name '"}, {input}, {"' was not found in option list"} );
+ $log( $info, {"The following options are allowed:"} );
+ for( i32 i=0; i<option_count; i ++ )
+ $log( $info, $signed(i), {": "}, {options[i]} );
+ _fatal_exit();
+ return -1;
+}
+
i32 main( i32 argc, const c8 *argv[] )
{
_exit_init();
_options_init( argc, argv );
- const c8 *list_file = NULL;
-
- u64 processors = 4;
-
const c8 *arg;
+ bool use_tsan = 0;
if( _option_long( "tsan", "Build using thread sanitizer" ) )
- _metacompiler.thread_sanitizer = 1;
+ use_tsan = 1;
+ bool use_asan = 1;
if( _option_long( "asan", "Build using address sanitizer" ) )
- _metacompiler.address_sanitizer = 1;
+ use_asan = 1;
- if( _option_long( "no-pdb", "Build using address sanitizer" ) )
- _metacompiler.no_pdb = 1;
+ bool no_pdb = 0;
+ if( _option_long( "no-pdb", "Prevent compiler from outputing pdb files" ) )
+ no_pdb = 1;
- if( _option_long( "game", "Build using the game engine system" ) )
+#if 0
+ enum compiler
{
+ k_compiler_blob,
+ k_compiler_clang,
+ k_compiler_zigcc,
}
-
+ compiler = k_compiler_zigcc;
+ const c8 *compiler_names[] =
+ {
+ [k_compiler_blob] = "blob",
+ [k_compiler_clang] = "clang",
+ [k_compiler_zigcc] = "zig-cc",
+ };
if( (arg = _option_long_argument( "compiler", "zig, clang, gcc" )) )
{
+
}
+#endif
- if( (arg = _option_long_argument( "arch", "any, i386, x86_64" )) )
+ enum libc_version
{
+ k_libc_version_native = 0,
+ k_libc_version_2_23,
+ k_libc_version_count,
}
+ libc = k_libc_version_native;
+ const c8 *libc_names[] =
+ {
+ [k_libc_version_native] = "",
+ [k_libc_version_2_23] = "2.23"
+ };
+ if( (arg = _option_long_argument( "libc", "native, 2.23 (recommended)" )) )
+ libc = enum_read( libc_names, k_libc_version_count, arg );
+ enum architecture
+ {
+ k_architecture_native,
+ k_architecture_i386,
+ k_architecture_x86_64,
+ k_architecture_count,
+ }
+ arch = k_architecture_x86_64;
+ const c8 *architecture_names[] =
+ {
+ [k_architecture_native] = "native",
+ [k_architecture_i386] = "i386",
+ [k_architecture_x86_64] = "x86_64",
+ };
+ if( (arg = _option_long_argument( "arch", "native, i386, x86_64" )) )
+ arch = enum_read( architecture_names, k_architecture_count, arg );
+ ASSERT_CRITICAL( arch == k_architecture_x86_64 );
+
+ enum platform
+ {
+ k_platform_native,
+ k_platform_windows,
+ k_platform_linux,
+ k_platform_count,
+ }
+ platform = k_platform_linux;
+ const c8 *platform_names[] =
+ {
+ [k_platform_native] = "native",
+ [k_platform_windows] = "windows",
+ [k_platform_linux] = "linux",
+ };
+ if( (arg = _option_long_argument( "platform", "native, linux, windows" )) )
+ platform = enum_read( platform_names, k_platform_count, arg );
+
+ u64 processors = 4;
if( (arg = _option_argument( 'j', "CPU count <0-8>" )) )
{
struct stream arg_stream;
ASSERT_CRITICAL( string_parse_u64( &arg_stream, &processors ) == k_string_parse_ok );
}
- list_file = _option();
-
- //if( (arg = _option_long_argument( "platform",
+ const c8 *target_file_path = NULL;
+ target_file_path = _option();
+ ASSERT_CRITICAL( target_file_path );
_options_check_end();
stack_init( &_metacompiler.all, NULL, BYTES_MB(64), "Everything" );
- ASSERT_CRITICAL( list_file );
$log( $info, {"Building source tree"} );
- stretchy_init( &_source_list, sizeof(struct source_file) );
- _append_kv_list( list_file );
+ stretchy_init( &_source_list, sizeof(struct command) );
+ _append_kv_list( target_file_path );
+
+ buffer_copy( "project", 0, _metacompiler.project_name, sizeof(_metacompiler.project_name) );
u32 temp_frame = _start_temporary_frame();
{
- c8 *output_folder = realpath( list_file, NULL );
+ c8 *output_folder = realpath( target_file_path, NULL );
if( !output_folder )
{
- $log( $fatal, {"'"}, {list_file}, {"' "}, $errno() );
+ $log( $fatal, {"'"}, {target_file_path}, {"' "}, $errno() );
_fatal_exit();
}
if( s != -1 )
output_folder[s] = '\0';
+ struct stream tripple_string;
+ stream_open_stack( &tripple_string, _temporary_stack_allocator(), k_stream_null_terminate );
+ $v_string( &tripple_string, {architecture_names[arch]}, {"-"}, {platform_names[platform]} );
+ if( platform == k_platform_linux )
+ {
+ $v_string( &tripple_string, {"-gnu"} );
+ if( libc != k_libc_version_native )
+ $v_string( &tripple_string, {"."}, {libc_names[libc]} );
+ }
+
struct stream folder_string;
stream_open_stack( &folder_string, _temporary_stack_allocator(), k_stream_null_terminate );
- $v_string( &folder_string, {output_folder}, {"/bin/"}, {"project"}, {"-linux-x86_64-zig-cc"} );
+ $v_string( &folder_string, {output_folder}, {"/bin/"}, {_metacompiler.project_name}, {"-"}, $string(&tripple_string) );
free(output_folder);
system_call( string_get( &command_string ) );
-
stream_open_stack( &command_string, _temporary_stack_allocator(), k_stream_null_terminate );
$v_string( &command_string, {"taskset -c 0-"}, $unsigned(processors),
{" zig cc -Wall -Wno-unused-function -std=c99 -D_DEFAULT_SOURCE \\\n"},
{" -include \"common_api.h\" \\\n"} );
+ $v_string( &command_string, {" -target "}, $string(&tripple_string) );
+ $v_string( &command_string, {" \\\n"} );
+
for( u32 i=0; i<stretchy_count( &_source_list ); i ++ )
{
- struct source_file *source = stretchy_get( &_source_list, i );
+ struct command *source = stretchy_get( &_source_list, i );
if( source->type == k_source_include_path )
$v_string( &command_string, {" -I"}, $string(&source->path), {" \\\n"} );
}
for( u32 i=0; i<stretchy_count( &_source_list ); i ++ )
{
- struct source_file *source = stretchy_get( &_source_list, i );
+ struct command *source = stretchy_get( &_source_list, i );
if( source->type == k_source_c )
$v_string( &command_string, {" "}, $string(&source->path), {" \\\n"} );
}
- $v_string( &command_string, {"-o "}, $string( &folder_string ), {"/project"} );
+ $v_string( &command_string, {"-o "}, $string( &folder_string ), {"/"},
+ {_metacompiler.project_name}, {"-"}, $string(&tripple_string) );
system_call( string_get( &command_string ) );
}
_end_temporary_frame( temp_frame );