From 32149b0709602dba052e29f1f077eeb322934e8d Mon Sep 17 00:00:00 2001 From: Jonathan Campbell Date: Tue, 29 Aug 2023 03:29:38 -0700 Subject: [PATCH] Do not assume architecture dir, specify by environment variable --- Makefile.am | 5 +++-- src/tool/mach-o-matic.cpp | 21 ++++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Makefile.am b/Makefile.am index 4a591c49b69..b5342d91f4a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -60,9 +60,10 @@ dosbox-x.app: $(MACOS_BINARIES) contrib/macos/dosbox.icns src/tool/mach-o-matic done # Fix the linker search paths of the libraries we copied @for dir in dosbox-x.app/Contents/MacOS/arm64 dosbox-x.app/Contents/MacOS/x86_64; do \ - if [ `ls $$dir/*.dylib 2>/dev/null | wc -l` -gt 0 ]; then \ + if [ `ls $$dir/*.dylib 2>/dev/null | wc -l` -gt 0 ]; then \ + arpf=`basename $$dir`; \ for dylib in $$dir/*.dylib; do \ - [ -f "$$dylib" ] && src/tool/mach-o-matic "$$dylib" || exit 1; \ + [ -f "$$dylib" ] && (ARCHPREF=$$arpf src/tool/mach-o-matic "$$dylib") || exit 1; \ done; \ fi; \ done diff --git a/src/tool/mach-o-matic.cpp b/src/tool/mach-o-matic.cpp index c41a5fd0832..b498ed01f21 100644 --- a/src/tool/mach-o-matic.cpp +++ b/src/tool/mach-o-matic.cpp @@ -22,6 +22,8 @@ #include +std::string arch_prefix = "arm64"; + using namespace std; bool str_startswith(const char *str,const char *starts) { @@ -40,25 +42,25 @@ string dylib_replace(string path) { fn = s; if (str_startswith(s,"/opt/homebrew/")) - return string("@executable_path/arm64/") + fn; + return string("@executable_path/") + arch_prefix + "/" + fn; if (str_startswith(s,"/usr/local/Homebrew/")) - return string("@executable_path/x86_64/") + fn; + return string("@executable_path/") + arch_prefix + "/" + fn; if (str_startswith(s,"/usr/local/lib/")) - return string("@executable_path/x86_64/") + fn; + return string("@executable_path/") + arch_prefix + "/" + fn; if (str_startswith(s,"/usr/local/opt/")) - return string("@executable_path/x86_64/") + fn; + return string("@executable_path/") + arch_prefix + "/" + fn; if (str_startswith(s,"/usr/local/Cellar/")) - return string("@executable_path/x86_64/") + fn; + return string("@executable_path/") + arch_prefix + "/" + fn; if (str_startswith(s,"@loader_path/")) { /* often in Brew followed by ../../.. etc */ s = fn; while (!strncmp(s,"../",3)) s += 3; printf("'%s' = '%s'\n",path.c_str(),s); - return string("@executable_path/arm64/") + s; + return string("@executable_path/") + arch_prefix + "/" + s; } if (str_startswith(s,"@rpath/")) - return string("@executable_path/arm64/") + fn; + return string("@executable_path/") + arch_prefix + "/" + fn; return path; } @@ -104,6 +106,11 @@ int main(int argc,char **argv) { return 1; } + { + char *x = getenv("ARCHPREF"); + if (x != NULL) arch_prefix = x; + } + fpath = argv[1]; if (lstat(fpath.c_str(),&st) != 0) { fprintf(stderr,"Cannot stat %s\n",fpath.c_str());