mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-18 20:02:22 -07:00
Add -build-mode=obj
This commit is contained in:
@@ -81,6 +81,12 @@ struct QueryDataSetSettings {
|
||||
bool compact;
|
||||
};
|
||||
|
||||
enum BuildModeKind {
|
||||
BuildMode_Executable,
|
||||
BuildMode_DynamicLibrary,
|
||||
BuildMode_Object,
|
||||
};
|
||||
|
||||
|
||||
// This stores the information for the specify architecture of this build
|
||||
struct BuildContext {
|
||||
@@ -114,7 +120,7 @@ struct BuildContext {
|
||||
String llc_flags;
|
||||
String target_triplet;
|
||||
String link_flags;
|
||||
bool is_dll;
|
||||
BuildModeKind build_mode;
|
||||
bool generate_docs;
|
||||
i32 optimization_level;
|
||||
bool show_timings;
|
||||
|
||||
+1
-1
@@ -4131,7 +4131,7 @@ void check_parsed_files(Checker *c) {
|
||||
|
||||
|
||||
TIME_SECTION("check entry point");
|
||||
if (!build_context.is_dll) {
|
||||
if (build_context.build_mode == BuildMode_Executable) {
|
||||
Scope *s = c->info.init_scope;
|
||||
GB_ASSERT(s != nullptr);
|
||||
GB_ASSERT(s->flags&ScopeFlag_Init);
|
||||
|
||||
+4
-4
@@ -12137,7 +12137,7 @@ void ir_gen_tree(irGen *s) {
|
||||
|
||||
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
if (build_context.is_dll && !has_dll_main) {
|
||||
if (build_context.build_mode == BuildMode_DynamicLibrary && !has_dll_main) {
|
||||
// DllMain :: proc(inst: rawptr, reason: u32, reserved: rawptr) -> i32
|
||||
String name = str_lit("DllMain");
|
||||
Type *proc_params = alloc_type_tuple();
|
||||
@@ -12208,7 +12208,7 @@ void ir_gen_tree(irGen *s) {
|
||||
ir_emit_return(proc, v_one32);
|
||||
}
|
||||
#endif
|
||||
if (!(build_context.is_dll && !has_dll_main)) {
|
||||
if (!(build_context.build_mode == BuildMode_DynamicLibrary && !has_dll_main)) {
|
||||
// main :: proc(argc: i32, argv: ^^u8) -> i32
|
||||
String name = str_lit("main");
|
||||
|
||||
@@ -12287,7 +12287,7 @@ void ir_gen_tree(irGen *s) {
|
||||
}
|
||||
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
// if (!m->build_context->is_dll && !has_win_main) {
|
||||
// if (m->build_context->build_mode != BuildMode_DynamicLibrary && !has_win_main) {
|
||||
// // proc WinMain(inst, prev: rawptr, cmd_line: ^byte, cmd_show: i32) -> i32
|
||||
// String name = str_lit("WinMain");
|
||||
// Type *proc_params = alloc_type_tuple();
|
||||
@@ -12331,7 +12331,7 @@ void ir_gen_tree(irGen *s) {
|
||||
// ir_emit_return(proc, v_one32);
|
||||
// ir_end_procedure_body(proc);
|
||||
// }
|
||||
if (!build_context.is_dll && build_context.no_crt) {
|
||||
if (build_context.build_mode != BuildMode_DynamicLibrary && build_context.no_crt) {
|
||||
s->print_chkstk = true;
|
||||
|
||||
{
|
||||
|
||||
+4
-8
@@ -2382,10 +2382,8 @@ void ir_print_proc(irFileBuffer *f, irModule *m, irProcedure *proc) {
|
||||
} else {
|
||||
ir_write_byte(f, '\n');
|
||||
ir_write_str_lit(f, "define ");
|
||||
if (build_context.is_dll) {
|
||||
if (proc->is_export) {
|
||||
ir_write_str_lit(f, "dllexport ");
|
||||
}
|
||||
if (proc->is_export) {
|
||||
ir_write_str_lit(f, "dllexport ");
|
||||
}
|
||||
// if (!proc->is_export && !proc->is_foreign && !proc->is_entry_point) {
|
||||
// ir_write_string(f, "internal ");
|
||||
@@ -2735,10 +2733,8 @@ void print_llvm_ir(irGen *ir) {
|
||||
if (g->is_foreign) {
|
||||
ir_write_string(f, str_lit("external "));
|
||||
}
|
||||
if (build_context.is_dll) {
|
||||
if (g->is_export) {
|
||||
ir_write_string(f, str_lit("dllexport "));
|
||||
}
|
||||
if (g->is_export) {
|
||||
ir_write_string(f, str_lit("dllexport "));
|
||||
}
|
||||
|
||||
if (g->is_private) {
|
||||
|
||||
@@ -11594,7 +11594,7 @@ void lb_generate_code(lbGenerator *gen) {
|
||||
}*/
|
||||
}
|
||||
|
||||
if (!(build_context.is_dll && !has_dll_main)) {
|
||||
if (!(build_context.build_mode == BuildMode_DynamicLibrary && !has_dll_main)) {
|
||||
Type *params = alloc_type_tuple();
|
||||
Type *results = alloc_type_tuple();
|
||||
|
||||
|
||||
+31
-15
@@ -195,7 +195,7 @@ i32 linker_stage(lbGenerator *gen) {
|
||||
|
||||
|
||||
|
||||
if (build_context.is_dll) {
|
||||
if (build_context.build_mode == BuildMode_DynamicLibrary) {
|
||||
output_ext = "dll";
|
||||
link_settings = gb_string_append_fmt(link_settings, " /DLL");
|
||||
} else {
|
||||
@@ -346,7 +346,7 @@ i32 linker_stage(lbGenerator *gen) {
|
||||
String output_ext = {};
|
||||
char const *link_settings = "";
|
||||
char const *linker;
|
||||
if (build_context.is_dll) {
|
||||
if (build_context.build_mode == BuildMode_DynamicLibrary) {
|
||||
// Shared libraries are .dylib on MacOS and .so on Linux.
|
||||
#if defined(GB_SYSTEM_OSX)
|
||||
output_ext = STR_LIT(".dylib");
|
||||
@@ -969,9 +969,11 @@ bool parse_build_flags(Array<String> args) {
|
||||
}
|
||||
|
||||
if (str == "dll" || str == "shared") {
|
||||
build_context.is_dll = true;
|
||||
build_context.build_mode = BuildMode_DynamicLibrary;
|
||||
} else if (str == "obj" || str == "object") {
|
||||
build_context.build_mode = BuildMode_Object;
|
||||
} else if (str == "exe") {
|
||||
build_context.is_dll = false;
|
||||
build_context.build_mode = BuildMode_Executable;
|
||||
} else {
|
||||
gb_printf_err("Unknown build mode '%.*s'\n", LIT(str));
|
||||
bad_flags = true;
|
||||
@@ -1208,12 +1210,14 @@ void remove_temp_files(String output_base) {
|
||||
} while (0)
|
||||
EXT_REMOVE(".ll");
|
||||
EXT_REMOVE(".bc");
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
EXT_REMOVE(".obj");
|
||||
EXT_REMOVE(".res");
|
||||
#else
|
||||
EXT_REMOVE(".o");
|
||||
#endif
|
||||
if (build_context.build_mode != BuildMode_Object) {
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
EXT_REMOVE(".obj");
|
||||
EXT_REMOVE(".res");
|
||||
#else
|
||||
EXT_REMOVE(".o");
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef EXT_REMOVE
|
||||
}
|
||||
@@ -1602,9 +1606,11 @@ int main(int arg_count, char const **arg_ptr) {
|
||||
}
|
||||
lb_generate_code(&gen);
|
||||
|
||||
i32 linker_stage_exit_count = linker_stage(&gen);
|
||||
if (linker_stage_exit_count != 0) {
|
||||
return linker_stage_exit_count;
|
||||
if (build_context.build_mode != BuildMode_Object) {
|
||||
i32 linker_stage_exit_count = linker_stage(&gen);
|
||||
if (linker_stage_exit_count != 0) {
|
||||
return linker_stage_exit_count;
|
||||
}
|
||||
}
|
||||
|
||||
if (build_context.show_timings) {
|
||||
@@ -1697,6 +1703,16 @@ int main(int arg_count, char const **arg_ptr) {
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
if (build_context.build_mode == BuildMode_Object) {
|
||||
// Ignore the linker
|
||||
if (build_context.show_timings) {
|
||||
show_timings(&checker, timings);
|
||||
}
|
||||
|
||||
remove_temp_files(output_base);
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
if (build_context.cross_compiling && selected_target_metrics->metrics == &target_essence_amd64) {
|
||||
#ifdef GB_SYSTEM_UNIX
|
||||
system_exec_command_line_app("linker", "x86_64-essence-gcc \"%.*s.o\" -o \"%.*s\" %.*s",
|
||||
@@ -1752,7 +1768,7 @@ int main(int arg_count, char const **arg_ptr) {
|
||||
|
||||
|
||||
|
||||
if (build_context.is_dll) {
|
||||
if (build_context.build_mode == BuildMode_DynamicLibrary) {
|
||||
output_ext = "dll";
|
||||
link_settings = gb_string_append_fmt(link_settings, "/DLL");
|
||||
} else {
|
||||
@@ -1904,7 +1920,7 @@ int main(int arg_count, char const **arg_ptr) {
|
||||
String output_ext = {};
|
||||
char const *link_settings = "";
|
||||
char const *linker;
|
||||
if (build_context.is_dll) {
|
||||
if (build_context.build_mode == BuildMode_DynamicLibrary) {
|
||||
// Shared libraries are .dylib on MacOS and .so on Linux.
|
||||
#if defined(GB_SYSTEM_OSX)
|
||||
output_ext = STR_LIT(".dylib");
|
||||
|
||||
Reference in New Issue
Block a user