use strict;
use File::Basename ();
use File::Path ();
use File::Spec;
use IO::File;
my $ArchSettings = '/System/Library/archSettings';
my %Known = (
'/usr/bin' => '/usr/archexec',
'/usr/local/bin' => '/usr/local/archexec',
);
my $MyName = File::Basename::basename($0);
sub usage {
print STDERR <<USAGE;
Usage: $MyName prog_path dstroot
$MyName takes prog_path (full path relative to the dstroot)
and dstroot, and moves the program to the corresponding archexec
directory. It then creates a symbolic from prog_path to the arch
command. Finally, a plist file is created in
/System/Library/archSettings to default to using the 32-bit
architectures.
USAGE
exit 1;
}
usage() unless scalar(@ARGV) == 2;
my($vol, $dir, $file) = File::Spec->splitpath($ARGV[0]); $dir = File::Spec->canonpath($dir);
my $new = $Known{$dir};
die "$MyName: Unsupported directory $dir\n" unless defined($new);
my $dstroot = $ARGV[1];
die "$MyName: $dstroot: Not a full path\n" unless File::Spec->file_name_is_absolute($dstroot);
File::Path::mkpath(File::Spec->join($dstroot, $new), 1, 0755);
File::Path::mkpath(File::Spec->join($dstroot, $ArchSettings), 1, 0755);
my $execpath = File::Spec->canonpath(File::Spec->join($new, $file));
my $do = File::Spec->join($dstroot, $dir, $file);
my $dn = File::Spec->join($dstroot, $execpath);
rename($do, $dn) or die "$MyName: Can't move $file to $dn: $!\n";
print "renamed $do -> $dn\n";
my $l = File::Spec->abs2rel('/usr/bin/arch', $dir);
symlink($l, $do) or die "$MyName: Can't symlink $do -> $l: $!\n";
print "symlink $do -> $l\n";
my $plist = File::Spec->join($dstroot, $ArchSettings, $file . '.plist');
my $p = IO::File->new($plist, 'w') or die "$MyName: $plist: $!\n";
$p->print( <<PLIST );
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ExecutablePath</key>
<string>$execpath</string>
<key>PreferredOrder</key>
<array>
<string>i386</string>
<string>x86_64</string>
<string>ppc</string>
<string>ppc64</string>
</array>
<key>PropertyListVersion</key>
<string>1.0</string>
</dict>
</plist>
PLIST
$p->close();
print "created $plist\n";