Refactor link flag creation for nix systems

This commit is contained in:
gingerBill
2022-03-08 11:13:59 +00:00
parent 29e660b16f
commit 17dab04422
+31 -26
View File
@@ -475,34 +475,39 @@ i32 linker_stage(lbGenerator *gen) {
} }
} }
result = system_exec_command_line_app("ld-link", gbString platform_lib_str = gb_string_make(heap_allocator(), "");
"clang -Wno-unused-command-line-argument %s -o \"%.*s%.*s\" %s " defer (gb_string_free(platform_lib_str));
" %s " #if defined(GB_SYSTEM_OSX)
" %.*s " platform_lib_str = gb_string_appendc(platform_lib_str, "-lSystem -lm -Wl,-syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -L/usr/local/lib");
" %.*s " #else
" %s " platform_lib_str = gb_string_appendc(platform_lib_str, "-lc -lm");
#if defined(GB_SYSTEM_OSX) #endif
// This sets a requirement of Mountain Lion and up, but the compiler doesn't work without this limit.
// NOTE: If you change this (although this minimum is as low as you can go with Odin working) #if defined(GB_SYSTEM_OSX)
// make sure to also change the 'mtriple' param passed to 'opt' // This sets a requirement of Mountain Lion and up, but the compiler doesn't work without this limit.
#if defined(GB_CPU_ARM) // NOTE: If you change this (although this minimum is as low as you can go with Odin working)
" -mmacosx-version-min=12.0.0 " // make sure to also change the 'mtriple' param passed to 'opt'
#else #if defined(GB_CPU_ARM)
" -mmacosx-version-min=10.8.0 " link_settings = gb_string_appendc(link_settings, " -mmacosx-version-min=12.0.0 ");
#endif
// This points the linker to where the entry point is
" -e _main "
#endif
, object_files, LIT(output_base), LIT(output_ext),
#if defined(GB_SYSTEM_OSX)
"-lSystem -lm -Wl,-syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -L/usr/local/lib",
#else #else
"-lc -lm", link_settings = gb_string_appendc(link_settings, " -mmacosx-version-min=10.8.0 ");
#endif #endif
lib_str, // This points the linker to where the entry point is
LIT(build_context.link_flags), link_settings = gb_string_appendc(link_settings, " -e _main ");
LIT(build_context.extra_linker_flags), #endif
link_settings);
gbString link_command_line = gb_string_make(heap_allocator(), "clang -Wno-unused-command-line-argument ");
defer (gb_string_free(link_command_line));
link_command_line = gb_string_appendc(link_command_line, object_files);
link_command_line = gb_string_append_fmt(link_command_line, " -o \"%.*s%.*s\" ", LIT(output_base), LIT(output_ext));
link_command_line = gb_string_append_fmt(link_command_line, " %s ", platform_lib_str);
link_command_line = gb_string_append_fmt(link_command_line, " %s ", lib_str);
link_command_line = gb_string_append_fmt(link_command_line, " %.*s ", LIT(build_context.link_flags));
link_command_line = gb_string_append_fmt(link_command_line, " %.*s ", LIT(build_context.extra_linker_flags));
link_command_line = gb_string_append_fmt(link_command_line, " %s ", link_settings);
result = system_exec_command_line_app("ld-link", link_command_line);
if (result) { if (result) {
return result; return result;