Do not assume architecture dir, specify by environment variable

This commit is contained in:
Jonathan Campbell 2023-08-29 03:29:38 -07:00
parent 07dc679fb6
commit 32149b0709
2 changed files with 17 additions and 9 deletions

View File

@ -60,9 +60,10 @@ dosbox-x.app: $(MACOS_BINARIES) contrib/macos/dosbox.icns src/tool/mach-o-matic
done done
# Fix the linker search paths of the libraries we copied # 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 \ @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 \ 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; \ done; \
fi; \ fi; \
done done

View File

@ -22,6 +22,8 @@
#include <string> #include <string>
std::string arch_prefix = "arm64";
using namespace std; using namespace std;
bool str_startswith(const char *str,const char *starts) { bool str_startswith(const char *str,const char *starts) {
@ -40,25 +42,25 @@ string dylib_replace(string path) {
fn = s; fn = s;
if (str_startswith(s,"/opt/homebrew/")) 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/")) 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/")) 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/")) 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/")) 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 */ if (str_startswith(s,"@loader_path/")) { /* often in Brew followed by ../../.. etc */
s = fn; s = fn;
while (!strncmp(s,"../",3)) s += 3; while (!strncmp(s,"../",3)) s += 3;
printf("'%s' = '%s'\n",path.c_str(),s); 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/")) if (str_startswith(s,"@rpath/"))
return string("@executable_path/arm64/") + fn; return string("@executable_path/") + arch_prefix + "/" + fn;
return path; return path;
} }
@ -104,6 +106,11 @@ int main(int argc,char **argv) {
return 1; return 1;
} }
{
char *x = getenv("ARCHPREF");
if (x != NULL) arch_prefix = x;
}
fpath = argv[1]; fpath = argv[1];
if (lstat(fpath.c_str(),&st) != 0) { if (lstat(fpath.c_str(),&st) != 0) {
fprintf(stderr,"Cannot stat %s\n",fpath.c_str()); fprintf(stderr,"Cannot stat %s\n",fpath.c_str());