| ... | @@ -31,6 +31,14 @@ static const char *get_libc_static_file(CodeGen *g, const char *file) { | ... | @@ -31,6 +31,14 @@ static const char *get_libc_static_file(CodeGen *g, const char *file) { |
| 31 | return buf_ptr(out_buf); | 31 | return buf_ptr(out_buf); |
| 32 | } | 32 | } |
| 33 | | 33 | |
| | 34 | static const char *get_o_file_extension(CodeGen *g) { |
| | 35 | if (g->zig_target.env_type == ZigLLVM_MSVC) { |
| | 36 | return ".obj"; |
| | 37 | } else { |
| | 38 | return ".o"; |
| | 39 | } |
| | 40 | } |
| | 41 | |
| 34 | static Buf *build_o(CodeGen *parent_gen, const char *oname) { | 42 | static Buf *build_o(CodeGen *parent_gen, const char *oname) { |
| 35 | Buf *source_basename = buf_sprintf("%s.zig", oname); | 43 | Buf *source_basename = buf_sprintf("%s.zig", oname); |
| 36 | Buf *std_dir_path = parent_gen->zig_std_dir; | 44 | Buf *std_dir_path = parent_gen->zig_std_dir; |
| ... | @@ -62,20 +70,13 @@ static Buf *build_o(CodeGen *parent_gen, const char *oname) { | ... | @@ -62,20 +70,13 @@ static Buf *build_o(CodeGen *parent_gen, const char *oname) { |
| 62 | } | 70 | } |
| 63 | | 71 | |
| 64 | codegen_add_root_code(child_gen, std_dir_path, source_basename, &source_code); | 72 | codegen_add_root_code(child_gen, std_dir_path, source_basename, &source_code); |
| 65 | Buf *o_out = buf_sprintf("%s.o", oname); | 73 | const char *o_ext = get_o_file_extension(child_gen); |
| | 74 | Buf *o_out = buf_sprintf("%s%s", oname, o_ext); |
| 66 | codegen_link(child_gen, buf_ptr(o_out)); | 75 | codegen_link(child_gen, buf_ptr(o_out)); |
| 67 | | 76 | |
| 68 | return o_out; | 77 | return o_out; |
| 69 | } | 78 | } |
| 70 | | 79 | |
| 71 | static const char *get_o_file_extension(CodeGen *g) { | | |
| 72 | if (g->zig_target.env_type == ZigLLVM_MSVC) { | | |
| 73 | return ".obj"; | | |
| 74 | } else { | | |
| 75 | return ".o"; | | |
| 76 | } | | |
| 77 | } | | |
| 78 | | | |
| 79 | static const char *get_exe_file_extension(CodeGen *g) { | 80 | static const char *get_exe_file_extension(CodeGen *g) { |
| 80 | if (g->zig_target.os == ZigLLVM_Win32) { | 81 | if (g->zig_target.os == ZigLLVM_Win32) { |
| 81 | return ".exe"; | 82 | return ".exe"; |
| ... | @@ -786,16 +787,21 @@ void codegen_link(CodeGen *g, const char *out_file) { | ... | @@ -786,16 +787,21 @@ void codegen_link(CodeGen *g, const char *out_file) { |
| 786 | fprintf(stderr, "-------\n"); | 787 | fprintf(stderr, "-------\n"); |
| 787 | } | 788 | } |
| 788 | | 789 | |
| 789 | if (buf_len(&lj.out_file) == 0) { | 790 | bool override_out_file = (buf_len(&lj.out_file) != 0); |
| | 791 | if (!override_out_file) { |
| 790 | assert(g->root_out_name); | 792 | assert(g->root_out_name); |
| | 793 | |
| 791 | buf_init_from_buf(&lj.out_file, g->root_out_name); | 794 | buf_init_from_buf(&lj.out_file, g->root_out_name); |
| 792 | buf_append_str(&lj.out_file, get_exe_file_extension(g)); | 795 | if (g->out_type == OutTypeExe) { |
| | 796 | buf_append_str(&lj.out_file, get_exe_file_extension(g)); |
| | 797 | } |
| 793 | } | 798 | } |
| 794 | | | |
| 795 | buf_init_from_buf(&lj.out_file_o, &lj.out_file); | 799 | buf_init_from_buf(&lj.out_file_o, &lj.out_file); |
| 796 | | 800 | |
| 797 | const char *o_ext = get_o_file_extension(g); | 801 | if (g->out_type != OutTypeObj || !override_out_file) { |
| 798 | buf_append_str(&lj.out_file_o, o_ext); | 802 | const char *o_ext = get_o_file_extension(g); |
| | 803 | buf_append_str(&lj.out_file_o, o_ext); |
| | 804 | } |
| 799 | | 805 | |
| 800 | char *err_msg = nullptr; | 806 | char *err_msg = nullptr; |
| 801 | if (LLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(&lj.out_file_o), | 807 | if (LLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(&lj.out_file_o), |