20 #if defined(__APPLE__)
21 # include <sys/stat.h>
25 const std::string &compiler_or_linker,
26 const std::string &goto_binary_file,
27 const std::string &output_file,
28 bool building_executable,
35 #if defined(__linux__) || defined(__FreeBSD_kernel__)
37 (void)building_executable;
39 std::string objcopy_cmd;
43 objcopy_cmd = compiler_or_linker;
44 objcopy_cmd.erase(objcopy_cmd.size() - 2);
45 objcopy_cmd +=
"objcopy";
48 objcopy_cmd =
"objcopy";
52 message.debug() <<
"merging " << output_file <<
" and " << goto_binary_file
53 <<
" using " << objcopy_cmd
59 std::vector<std::string> objcopy_argv = {
61 "--remove-section",
"goto-cc",
62 "--add-section",
"goto-cc=" + goto_binary_file, output_file};
64 result =
run(objcopy_argv[0], objcopy_argv);
71 message.error() <<
"Remove failed: " << std::strerror(errno)
74 result = remove_result;
77 #elif defined(__APPLE__)
80 message.debug() <<
"merging " << output_file <<
" and " << goto_binary_file
81 <<
" using " << (building_executable ?
"lipo" :
"ld")
84 if(building_executable)
88 std::vector<std::string> lipo_argv = {
89 "lipo", output_file,
"-create",
"-arch",
"hppa7100LC", goto_binary_file,
90 "-output", output_file };
92 result =
run(lipo_argv[0], lipo_argv);
99 mode_t current_umask = umask(0);
100 umask(current_umask);
101 int chmod_result = chmod(
102 output_file.c_str(), (S_IRWXU | S_IRWXG | S_IRWXO) & ~current_umask);
103 if(chmod_result != 0)
105 message.error() <<
"Setting execute permissions failed: "
107 result = chmod_result;
114 std::vector<std::string> ld_argv = {
"ld",
124 result =
run(ld_argv[0], ld_argv);
128 bool remove_result =
file_remove(goto_binary_file);
131 message.error() <<
"Remove failed: " << std::strerror(errno)
134 result = remove_result;
139 (void)compiler_or_linker;
140 (void)goto_binary_file;
142 (void)building_executable;
143 message.error() <<
"binary merging not implemented for this platform"