holyc compile
authorhgn <hgodden00@gmail.com>
Sun, 6 Nov 2022 01:02:02 +0000 (01:02 +0000)
committerhgn <hgodden00@gmail.com>
Sun, 6 Nov 2022 01:02:02 +0000 (01:02 +0000)
src/vg/vg.h
src/vg/vg_build.h [new file with mode: 0644]
src/vg/vg_log.h
src/vg/vg_mem.h
src/vg/vg_opt.h
src/vg/vg_platform.h

index de119709bd34df35483d224190dcc7ee771996a0..aee5808db1a0d208dea695cb1a4d6fdb0f57b6bf 100644 (file)
@@ -150,6 +150,14 @@ static VG_THREAD_LOCAL struct vg_thread_info vg_thread_info;
 #endif
 
 VG_STATIC void vg_fatal_exit_loop( const char *error );
+VG_STATIC void vg_required( void *ptr, const char *path )
+{
+   if( !ptr )
+   {
+      vg_fatal_exit_loop( path );
+   }
+}
+
 
 VG_STATIC void vg_ensure_engine_running(void)
 {
diff --git a/src/vg/vg_build.h b/src/vg/vg_build.h
new file mode 100644 (file)
index 0000000..1bf2dba
--- /dev/null
@@ -0,0 +1,268 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "vg/vg_log.h"
+
+struct compiler_info
+{
+   char name[64],
+        file[512],
+        link[512],
+        library[512],
+        include[512],
+        build_dir[512],
+        executable[512];
+
+   enum optimization_profile
+   {
+      k_optimization_profile_debug,
+      k_optimization_profile_release
+   }
+   optimization_profile;
+
+   enum target_file
+   {
+      k_target_file_game,
+      k_target_file_server
+   }
+   target_file;
+
+   enum compiler
+   {
+      k_compiler_clang,
+      k_compiler_gcc,
+      k_compiler_mingw
+   }
+   compiler;
+}
+
+static vg_compiler;
+
+void vg_build_syscall(const char *fmt, ...)
+{
+   va_list args;
+   va_start( args, fmt );
+
+       char call[4096];
+       vsnprintf( call, vg_list_size( call ), fmt, args );
+
+   va_end( args );
+
+   puts( call );
+
+   if( system(call) )
+      exit(0);
+}
+
+void vg_build_object( const char *file )
+{
+   strcat( vg_compiler.file, file );
+}
+
+void vg_build_library_dir( const char *ldir )
+{
+   strcat( vg_compiler.library, ldir );
+}
+
+void vg_build_link( const char *link )
+{
+   strcat( vg_compiler.link, link );
+}
+
+void vg_build_include( const char *inc )
+{
+   strcat( vg_compiler.include, inc );
+}
+
+const char *vg_compiler_str(void)
+{
+   return (const char *[]){ "clang", "gcc", "i686-w64-mingw32-gcc" }
+                          [vg_compiler.compiler];
+}
+
+void vg_build_start( const char *name, enum compiler compiler )
+{
+   vg_compiler.file[0] = '\0';
+   vg_compiler.link[0] = '\0';
+   vg_compiler.include[0] = '\0';
+   vg_compiler.library[0] = '\0';
+   vg_compiler.compiler = compiler;
+
+   strcpy( vg_compiler.name, name );
+
+   snprintf( vg_compiler.build_dir, 512, 
+                                    "bin/%s-%s",
+                                    name,
+                                    vg_compiler_str() );
+
+   vg_build_syscall( "mkdir -p %s", vg_compiler.build_dir );
+   vg_build_include( "-I. -I./vg/src " );
+   vg_build_library_dir( "-L. " );
+}
+
+void vg_build_add_link_for_graphics(void)
+{
+   if( (vg_compiler.compiler == k_compiler_gcc) || 
+       (vg_compiler.compiler == k_compiler_clang ) )
+   {
+      vg_build_link( "-lGL -lglfw3 -lX11 -lXxf86vm -lXrandr -lXi -ldl " );
+   }
+   else
+   {
+      vg_build_link( "-lglfw3dll -lopengl32 -static -mwindows " );
+   }
+
+   vg_build_object( "vg/dep/glad/glad.c " );
+   vg_build_link( "-lm -pthread " );
+   vg_build_library_dir( "-L./vg/dep/glfw " );
+}
+
+void vg_build_add_link_for_game(void)
+{
+   if( (vg_compiler.compiler == k_compiler_gcc) ||
+       (vg_compiler.compiler == k_compiler_clang ) )
+   {
+      vg_build_link( "-lsteam_api " );
+      vg_build_object( "vg/dep/dr_soft/miniaudio." );
+   }
+   else
+   {
+      vg_build_link( "vg/dep/steam/steam_api.dll " );
+      vg_build_object( "vg/dep/dr_soft/miniaudio." );
+   }
+
+   vg_build_object( vg_compiler_str() );
+   vg_build_object( ".o " );
+
+   vg_build_include( "-I./vg/dep " );
+   vg_build_library_dir( "-L./vg/dep/steam " );
+}
+
+void vg_build_bin_dependency_file( const char *src )
+{
+   vg_build_syscall( "cp %s %s", src, vg_compiler.build_dir );
+}
+
+void vg_build_symbolic_link( const char *folder, const char *bin_name )
+{
+   char dest[512];
+   snprintf( dest, 512, "%s/%s", vg_compiler.build_dir, bin_name );
+
+   if( !access( dest, F_OK ) )
+      vg_build_syscall( "unlink %s", dest );
+
+   vg_build_syscall( "ln -srf %s %s", folder, dest );
+}
+
+void vg_build_copy_graphics_dependencies(void)
+{
+   if( vg_compiler.compiler == k_compiler_mingw )
+   {
+      vg_build_bin_dependency_file( "vg/dep/glfw/glfw3.dll" );
+   }
+}
+
+void vg_build_copy_game_dependencies(void)
+{
+   if( (vg_compiler.compiler == k_compiler_gcc) || 
+       (vg_compiler.compiler == k_compiler_clang) )
+   {
+      vg_build_bin_dependency_file( "vg/dep/steam/libsteam_api.so" );
+   }
+   else
+   {
+      vg_build_bin_dependency_file( "vg/dep/steam/steam_api.dll" );
+   }
+}
+
+void vg_build_mode_release(void)
+{
+   vg_compiler.optimization_profile = k_optimization_profile_release;
+}
+
+void vg_build_mode_debug(void)
+{
+   vg_compiler.optimization_profile = k_optimization_profile_debug;
+}
+
+void vg_build_miniaudio(void)
+{
+   vg_build_syscall( "ccache %s -O3\\\n"
+                     "   -c vg/dep/dr_soft/miniaudio_impl.c\\\n"
+                     "   -o vg/dep/dr_soft/miniaudio.%s.o",
+                     vg_compiler_str(), vg_compiler_str() );
+}
+
+void vg_build(void)
+{
+   char cmd[4096];
+   cmd[0] = '\0';
+
+   /* Compiler */
+   strcat( cmd, "ccache " );
+   strcat( cmd, vg_compiler_str() );
+   strcat( cmd, " -std=gnu99 -D_REENTRANT \\\n" );
+
+   /* Debugging information */
+   if( vg_compiler.optimization_profile == k_optimization_profile_debug )
+   {
+      strcat( cmd, "   -O0 -ggdb3 -fno-omit-frame-pointer " );
+
+      if( (vg_compiler.compiler == k_compiler_gcc) ||
+          (vg_compiler.compiler == k_compiler_clang ) )
+      {
+         strcat( cmd, "-rdynamic -fsanitize=address " );
+      }
+
+      strcat( cmd, "\\\n" );
+   }
+   else
+   {
+      strcat( cmd, "   -O3 -DVG_RELEASE\\\n" );
+   }
+
+   /* Warnings */
+   strcat( cmd, 
+      "   -Wall\\\n"
+      "     -Wno-unused-function -Wno-unused-variable\\\n"
+      "     -Wno-unused-command-line-argument -Wno-unused-but-set-variable\\\n"
+   );
+
+   /* Include */
+   strcat( cmd, "   " );
+   strcat( cmd, vg_compiler.include );
+   strcat( cmd, "\\\n" );
+
+   /* Library */
+   strcat( cmd, "   " );
+   strcat( cmd, vg_compiler.library );
+   strcat( cmd, "\\\n" );
+
+   /* Targets */
+   strcat( cmd, "   " );
+   strcat( cmd, vg_compiler.file );
+   strcat( cmd, "\\\n" );
+
+   /* Output */
+   strcat( cmd, "   -o " );
+   vg_compiler.executable[0] = '\0';
+   strcat( vg_compiler.executable, vg_compiler.build_dir );
+   strcat( vg_compiler.executable, "/" );
+   strcat( vg_compiler.executable, vg_compiler.name );
+
+   if( vg_compiler.compiler == k_compiler_mingw )
+      strcat( vg_compiler.executable, ".exe" );
+
+   strcat( cmd, vg_compiler.executable );
+   strcat( cmd, "\\\n" );
+
+   /* Link */
+   strcat( cmd, "   " );
+   strcat( cmd, vg_compiler.link );
+   strcat( cmd, "\\\n" );
+
+   strcat( cmd, "   -Wl,-rpath=./" );
+
+   vg_build_syscall( cmd );
+}
index b430a31d352c6c0d91dd14e66a82e5886f2eaa6a..5fbe631e82c60414a0e6c7ad055bde622db3ea00 100644 (file)
@@ -52,7 +52,7 @@ VG_STATIC void vg_log_write( FILE *file, const char *prefix,
 {
    vg_mutex_lock( &log_print_mutex );
 
-       char buffer[512];
+       char buffer[ 4096 ];
        int i, j;
        
        for( i=0; i<vg_list_size( buffer ); i ++ )
index 8406b3342002f7bbbe9bf3ef2289333a9f86746e..3a7a49da06814fe9c2c7d1d1b082ee6cc6a8ed5a 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef VG_MEM_H
 #define VG_MEM_H
 
+#include "vg.h"
 #include "vg_stdint.h"
 #include "vg_platform.h"
 
@@ -85,6 +86,7 @@ struct vg_linear_allocator
 };
 #pragma pack(pop)
 
+VG_STATIC void vg_fatal_exit_loop( const char *error );
 VG_STATIC void vg_error(const char *fmt, ...);
 VG_STATIC void vg_info(const char *fmt, ...);
 
index 41494bddac33ca3bea11c8d750cced1db03890e9..a11f2c02cf3c1a5d0f623392c02646b97b4859d4 100644 (file)
@@ -5,7 +5,9 @@
 #ifndef VG_OPT_H
 #define VG_OPT_H
 
+#include <stdlib.h>
 #include "vg/vg_platform.h"
+#include "vg/vg_log.h"
 
 /* 
  * Supported:
index d4ac5e422c2f1920790fabe053b3158e56cf5c29..c81d3474600e048f2117c73c406471ef0ba678ba 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef VG_PLATFORM_H
 #define VG_PLATFORM_H
 
-#include "vg.h"
+//#include "vg.h"
 #include "vg_stdint.h"
 
 /* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */
@@ -80,15 +80,6 @@ VG_STATIC void vg_strncpy( const char *src, char *dst, u32 len )
    }
 }
 
-VG_STATIC void vg_fatal_exit_loop( const char *error );
-VG_STATIC void vg_required( void *ptr, const char *path )
-{
-   if( !ptr )
-   {
-      vg_fatal_exit_loop( path );
-   }
-}
-
 #define VG_REQUIRED_ASSET( TYPE, DECL, FN, PATH, ... )                         \
    TYPE DECL = FN( PATH,##__VA_ARGS__ );                                       \
    vg_required( DECL, "Resource is required but failed to load: '" PATH "'" );