From dc7adde93812ca58adcaa0443699c5bb7b1d4f17 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Mon, 8 Mar 2021 19:42:12 -0500 Subject: [PATCH] auto set the rpath in mame64. I would prefer to do it after copying but the copy also codesigns. --- Ample.xcodeproj/project.pbxproj | 22 ++++++++ embedded/install_name_tool.pl | 89 +++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 embedded/install_name_tool.pl diff --git a/Ample.xcodeproj/project.pbxproj b/Ample.xcodeproj/project.pbxproj index e595a8e..ed51e63 100644 --- a/Ample.xcodeproj/project.pbxproj +++ b/Ample.xcodeproj/project.pbxproj @@ -665,6 +665,7 @@ B6BA257824E99BE9005FB8FF /* Frameworks */, B6BA257924E99BE9005FB8FF /* Resources */, B66236B124FDA443006CABD7 /* Embed Frameworks */, + B6152B5C25F6F4F800605E6E /* ShellScript */, B66236BB24FDA71D006CABD7 /* CopyFiles */, ); buildRules = ( @@ -903,6 +904,27 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + B6152B5C25F6F4F800605E6E /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n\ncd \"embedded\"\necho perl install_name_tool.pl --verbose mame64 \"@executable_path/../Frameworks\"\nperl install_name_tool.pl --verbose mame64 \"@executable_path/../Frameworks\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ B6841BCC251EC913006A5C39 /* Sources */ = { isa = PBXSourcesBuildPhase; diff --git a/embedded/install_name_tool.pl b/embedded/install_name_tool.pl new file mode 100644 index 0000000..01171e3 --- /dev/null +++ b/embedded/install_name_tool.pl @@ -0,0 +1,89 @@ +use strict; +use Getopt::Long; +use Data::Dumper; + +my $file; +my @rpaths; +my $path; +my $verbose = 0; +my $help = 0; +my $dry_run = 0; + +sub help($) { + print("Usage: install_name_tool.pl [--dry-run] [--verbose] exec-file rpath\n"); + exit(shift); +} + +GetOptions("help" => \$help, "verbose" => \$verbose, "dry-run" => \$dry_run); +help(0) if $help; +$verbose = 1 if $dry_run; + +help(1) unless scalar(@ARGV) == 2; +($file, $path) = @ARGV; + + +open(my $fh, "-|", "otool", "-l", $file); + + +# +#Load command 33 +# cmd LC_RPATH +# cmdsize 32 +# path ./Frameworks/ (offset 12) +# +# + + +my $cmd = ''; +while (<$fh>) { + chomp; + if ($_ =~ /^Load command/) { + $cmd = ''; + next; + } + if ($_ =~ /^\s+cmd ([A-Z_]+)$/) { + $cmd = $1; + next; + } + if ($cmd eq 'LC_RPATH' && $_ =~ /^\s+path (.+) \(offset \d+\)$/) { + push(@rpaths, $1); + } +} +close($fh); + +if ($verbose) { + print "current rpaths:\n"; + foreach(@rpaths) { + print($_ . "\n"); + } +} + +my @args; + +# equal or changeable. +if (scalar @rpaths == 1) { + exit(0) if $rpaths[0] eq $path; + push(@args, ("-change_rpath", ${rpaths[0]}, $path)) +} else { + + my @tmp; + @tmp = grep {$_ ne $path } @rpaths; + + foreach (@tmp) { + push(@args, ("-delete_rpath", $_)) + } + + + @tmp = grep {$_ eq $path } @rpaths; + if (!scalar @tmp) { + push(@args, ("-add_rpath", $path)); + } +} + +if (scalar @args) { + print( join(' ', "install_name_tool", @args, $file) . "\n") if $verbose; + exit(0) if $dry_run; + system("install_name_tool", @args, $file); + exit($?); +} +exit(0);