ok
authorhgn <hgodden00@gmail.com>
Thu, 25 Sep 2025 20:08:30 +0000 (20:08 +0000)
committerhgn <hgodden00@gmail.com>
Thu, 25 Sep 2025 20:08:30 +0000 (20:08 +0000)
source/foundation/logging.c
source/foundation/options.c
source/tools/metacompiler.c

index 9f5f778853cc04186c8b0e3ef6f0d6bde8b1c7f5..f8f69994f2f77ce9111df033ce5b127d71211e6e 100644 (file)
@@ -30,8 +30,18 @@ struct stream *_log_event( u32 type, const c8 *code_location )
 {
    struct stream *output = _get_console_stream();
    string_append( output, KBLK );
+
+   u32 line_start = output->offset;
+
+   i32 s = buffer_last_index( code_location, '/', 0 );
+   if( s != -1 )
+   {
+      string_append( output, "..." );
+      code_location += s+1;
+   }
    string_append( output, code_location );
-   while( output->offset < 32 ) string_append_c8( output, ' ' );
+
+   while( (output->offset-line_start) < 32 ) string_append_c8( output, ' ' );
         if( type == $error )   string_append( output, KRED "ERR|" );
    else if( type == $warning ) string_append( output, KYEL "WRN|" );
    else if( type == $ok )      string_append( output, KGRN "OK |" );
index 2d2554affcb4db5e2578527a70c035ce37fa0f5d..9a98b9ba322d305f296404479aa9b68cbbbf3dec 100644 (file)
@@ -217,18 +217,10 @@ static struct argument *_argument_get_named( enum argument_type type, const c8 *
       struct argument *arg = &_options.arguments[ i ];
       if( arg->type == type )
       {
-         for( u32 j=0; arg->name_length; j ++ )
+         if( compare_buffers( arg->name, arg->name_length, name, 0 ) )
          {
-            c8 ca = name[j], cb = arg->name[j];
-            if( ca == cb ) 
-            {
-               if( ca == 0 ) 
-               {
-                  arg->used = 0xffffffff;
-                  return arg;
-               }
-            }
-            else break;
+            arg->used = 0xffffffff;
+            return arg;
          }
       }
    }
index b1416386687ec3a32abf8db58145feda1b9f48f8..d68281671e6d466b0350fb932df38f664256fa17 100644 (file)
@@ -2,19 +2,15 @@
 
 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
@@ -41,12 +37,12 @@ void _parse_kv_block( struct keyvalues *kvs, u32 block, const c8 *folder )
          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 );
@@ -55,7 +51,7 @@ void _parse_kv_block( struct keyvalues *kvs, u32 block, const c8 *folder )
 
          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 );
@@ -110,37 +106,109 @@ void system_call( const c8 *call )
    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;
@@ -148,27 +216,28 @@ i32 main( i32 argc, const c8 *argv[] )
       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();
       }
 
@@ -176,9 +245,19 @@ i32 main( i32 argc, const c8 *argv[] )
       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);
 
@@ -188,27 +267,30 @@ i32 main( i32 argc, const c8 *argv[] )
       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 );