Skip to content

Commit

Permalink
Do not assume architecture dir, specify by environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
joncampbell123 committed Aug 29, 2023
1 parent 07dc679 commit 32149b0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
5 changes: 3 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions src/tool/mach-o-matic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include <string>

std::string arch_prefix = "arm64";

using namespace std;

bool str_startswith(const char *str,const char *starts) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 32149b0

Please sign in to comment.