Browse Source

Merge pull request #330 from thebirk/fix-out-linux

Fixed -out dropping extension on linux. Issue #305
gingerBill 6 years ago
parent
commit
141da818ba
1 changed files with 17 additions and 7 deletions
  1. 17 7
      src/main.cpp

+ 17 - 7
src/main.cpp

@@ -1056,15 +1056,15 @@ int main(int arg_count, char **arg_ptr) {
 
 
 		// 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 = "";
+		String output_ext = {};
 		char *link_settings = "";
 		char *link_settings = "";
 		char *linker;
 		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 = STR_LIT(".dylib");
 			#else
 			#else
-				output_ext = ".so";
+				output_ext = STR_LIT(".so");
 			#endif
 			#endif
 
 
 			link_settings = "-shared";
 			link_settings = "-shared";
@@ -1073,6 +1073,14 @@ int main(int arg_count, char **arg_ptr) {
 			link_settings = "";
 			link_settings = "";
 		}
 		}
 
 
+		if (build_context.out_filepath.len > 0) {
+			//NOTE(thebirk): We have a custom -out arguments, so we should use the extension from that
+			isize pos = string_extension_position(build_context.out_filepath);
+			if (pos > 0) {
+				output_ext = substring(build_context.out_filepath, pos, build_context.out_filepath.len);
+			}
+		}
+
 		#if defined(GB_SYSTEM_OSX)
 		#if defined(GB_SYSTEM_OSX)
 			linker = "ld";
 			linker = "ld";
 		#else
 		#else
@@ -1088,7 +1096,7 @@ int main(int arg_count, char **arg_ptr) {
 		#endif
 		#endif
 
 
 		exit_code = system_exec_command_line_app("ld-link", true,
 		exit_code = system_exec_command_line_app("ld-link", true,
-			"%s \"%.*s.o\" -o \"%.*s%s\" %s "
+			"%s \"%.*s.o\" -o \"%.*s%.*s\" %s "
 			" %s "
 			" %s "
 			" %.*s "
 			" %.*s "
 			" %s "
 			" %s "
@@ -1101,7 +1109,7 @@ int main(int arg_count, char **arg_ptr) {
 				// This points the linker to where the entry point is
 				// This points the linker to where the entry point is
 				" -e _main "
 				" -e _main "
 			#endif
 			#endif
-			, linker, LIT(output_base), LIT(output_base), output_ext,
+			, linker, LIT(output_base), LIT(output_base), LIT(output_ext),
 			lib_str,
 			lib_str,
 			str_eq_ignore_case(cross_compile_target, str_lit("Essence")) ? "-lfreetype -lglue" : "-lc -lm",
 			str_eq_ignore_case(cross_compile_target, str_lit("Essence")) ? "-lfreetype -lglue" : "-lc -lm",
 			LIT(build_context.link_flags),
 			LIT(build_context.link_flags),
@@ -1134,8 +1142,10 @@ int main(int arg_count, char **arg_ptr) {
 		remove_temp_files(output_base);
 		remove_temp_files(output_base);
 
 
 		if (run_output) {
 		if (run_output) {
-			output_base = path_to_full_path(heap_allocator(), output_base);
-			system_exec_command_line_app("odin run", false, "\"%.*s\" %.*s", LIT(output_base), LIT(run_args_string));
+			//NOTE(thebirk): This whole thing is a little leaky
+			String complete_path = concatenate_strings(heap_allocator(), output_base, output_ext);
+			complete_path = path_to_full_path(heap_allocator(), complete_path);
+			system_exec_command_line_app("odin run", false, "\"%.*s\" %.*s", LIT(complete_path), LIT(run_args_string));
 		}
 		}
 	#endif
 	#endif
 #endif
 #endif