aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2022-03-08 17:12:28 +0000
committerGitHub <noreply@github.com>2022-03-08 17:12:28 +0000
commit2b43387a9d8a1c50c4b7c10a504877afff9b7ebd (patch)
tree380d6b756a70013f788fbacd798a2804e1b2d64b /src
parent29e660b16f18df2c3d6781fef5d1baa3faac0c94 (diff)
parent17dab044224c8c464cbbc5840ab1592d59f0a6a0 (diff)
Merge pull request #1597 from odin-lang/nix-linker-flags-improvement
Refactor link flag creation for nix systems
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp57
1 files changed, 31 insertions, 26 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 8db3a09ec..1e1e957cb 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -475,34 +475,39 @@ i32 linker_stage(lbGenerator *gen) {
}
}
- result = system_exec_command_line_app("ld-link",
- "clang -Wno-unused-command-line-argument %s -o \"%.*s%.*s\" %s "
- " %s "
- " %.*s "
- " %.*s "
- " %s "
- #if defined(GB_SYSTEM_OSX)
- // 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)
- // make sure to also change the 'mtriple' param passed to 'opt'
- #if defined(GB_CPU_ARM)
- " -mmacosx-version-min=12.0.0 "
- #else
- " -mmacosx-version-min=10.8.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",
+ gbString platform_lib_str = gb_string_make(heap_allocator(), "");
+ defer (gb_string_free(platform_lib_str));
+ #if defined(GB_SYSTEM_OSX)
+ platform_lib_str = gb_string_appendc(platform_lib_str, "-lSystem -lm -Wl,-syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -L/usr/local/lib");
+ #else
+ platform_lib_str = gb_string_appendc(platform_lib_str, "-lc -lm");
+ #endif
+
+ #if defined(GB_SYSTEM_OSX)
+ // 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)
+ // make sure to also change the 'mtriple' param passed to 'opt'
+ #if defined(GB_CPU_ARM)
+ link_settings = gb_string_appendc(link_settings, " -mmacosx-version-min=12.0.0 ");
#else
- "-lc -lm",
+ link_settings = gb_string_appendc(link_settings, " -mmacosx-version-min=10.8.0 ");
#endif
- lib_str,
- LIT(build_context.link_flags),
- LIT(build_context.extra_linker_flags),
- link_settings);
+ // This points the linker to where the entry point is
+ link_settings = gb_string_appendc(link_settings, " -e _main ");
+ #endif
+
+ 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) {
return result;