Linux can build now! Woo!

This commit is contained in:
Zac Pierson
2017-02-07 15:07:20 -06:00
parent 90ab448bca
commit 584869730a
2 changed files with 26 additions and 11 deletions
+9 -2
View File
@@ -330,8 +330,15 @@ void init_build_context(BuildContext *bc) {
#define linker_flag_x86 "" #define linker_flag_x86 ""
#else #else
// Linux, but also BSDs and the like. // Linux, but also BSDs and the like.
#define linker_flag_x64 "-m elf_x86_64" // NOTE(zangent): When clang is swapped out with ld as the linker,
#define linker_flag_x86 "-m elf_i386" // the commented flags here should be used. Until then, we'll have
// to use alternative build flags made for clang.
/*
#define linker_flag_x64 "-m elf_x86_64"
#define linker_flag_x86 "-m elf_i386"
*/
#define linker_flag_x64 "-arch x86-64"
#define linker_flag_x86 "-arch x86"
#endif #endif
if (str_eq(bc->ODIN_ARCH, str_lit("amd64"))) { if (str_eq(bc->ODIN_ARCH, str_lit("amd64"))) {
+16 -8
View File
@@ -383,14 +383,15 @@ int main(int argc, char **argv) {
// Unlike the Win32 linker code, the output_ext includes the dot, because // Unlike the Win32 linker code, the output_ext includes the dot, because
// typically executable files on *NIX systems don't have extensions. // typically executable files on *NIX systems don't have extensions.
char *output_ext = ".bin"; char *output_ext = "";
char *link_settings = ""; char *link_settings = "";
char *linker;
if (build_context.is_dll) { if (build_context.is_dll) {
// Shared libraries are .dylib on MacOS and .so on Linux. // Shared libraries are .dylib on MacOS and .so on Linux.
#if defined(GB_SYSTEM_OSX) #if defined(GB_SYSTEM_OSX)
output_ext = ".dylib"; output_ext = ".dylib";
#else #else
output_ext = ".so"; output_ext = ".so";
#endif #endif
link_settings = "-shared"; link_settings = "-shared";
@@ -399,6 +400,16 @@ int main(int argc, char **argv) {
link_settings = ""; link_settings = "";
} }
#if defined(GB_SYSTEM_OSX)
linker = "ld";
#else
// TODO(zangent): Figure out how to make ld work on Linux.
// It probably has to do with including the entire CRT, but
// that's quite a complicated issue to solve while remaining distro-agnostic.
// Clang can figure out linker flags for us, and that's good enough _for now_.
linker = "clang";
#endif
printf("Libs: %s\n", lib_str); printf("Libs: %s\n", lib_str);
// TODO(zangent): I'm not sure what to do with lib_str. // TODO(zangent): I'm not sure what to do with lib_str.
@@ -408,7 +419,7 @@ int main(int argc, char **argv) {
exit_code = system_exec_command_line_app("ld-link", true, exit_code = system_exec_command_line_app("ld-link", true,
"ld \"%.*s\".o -o \"%.*s%s\" %s " "%s \"%.*s\".o -o \"%.*s%s\" %s "
"-lc " "-lc "
" %.*s " " %.*s "
" %s " " %s "
@@ -416,11 +427,8 @@ int main(int argc, char **argv) {
// This sets a requirement of Mountain Lion and up, but the compiler doesn't work without this limit. // This sets a requirement of Mountain Lion and up, but the compiler doesn't work without this limit.
" -macosx_version_min 10.8.0 " " -macosx_version_min 10.8.0 "
" -e _main " " -e _main "
#else
" -e main -dynamic-linker /lib64/ld-linux-x86-64.so.2 "
#endif #endif
, , linker, LIT(output), LIT(output), output_ext,
LIT(output), LIT(output), output_ext,
lib_str, LIT(build_context.link_flags), lib_str, LIT(build_context.link_flags),
link_settings link_settings
); );