]> git.saurik.com Git - apple/system_cmds.git/blob - arch.tproj/arch_helper.pl
system_cmds-431.tar.gz
[apple/system_cmds.git] / arch.tproj / arch_helper.pl
1 #!/usr/bin/perl -w
2 #
3 # Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
4 #
5 # @APPLE_LICENSE_HEADER_START@
6 #
7 # This file contains Original Code and/or Modifications of Original Code
8 # as defined in and that are subject to the Apple Public Source License
9 # Version 2.0 (the 'License'). You may not use this file except in
10 # compliance with the License. Please obtain a copy of the License at
11 # http://www.opensource.apple.com/apsl/ and read it before using this
12 # file.
13 #
14 # The Original Code and all software distributed under the License are
15 # distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 # EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 # INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 # Please see the License for the specific language governing rights and
20 # limitations under the License.
21 #
22 # @APPLE_LICENSE_HEADER_END@
23 #
24 # arch_helper.pl is a perl script that automates the process of wrapping
25 # a command (in the DSTROOT) to use the architecture selection feature of
26 # the arch command. The first argument is the full path (relative to root)
27 # of the command, and the second argument is the DSTROOT. arch_helper.pl
28 # will move the command to a new directory in the DSTROOT, create a symbolic
29 # link from to old command path to the arch command, and create a plist file
30 # in /System/Library/archSettings to default to 32-bit over 64-bit
31 # architectures.
32
33 use strict;
34 use File::Basename ();
35 use File::Path ();
36 use File::Spec;
37 use IO::File;
38
39 my $ArchSettings = '/System/Library/archSettings';
40 my %Known = (
41 '/usr/bin' => '/usr/archexec',
42 '/usr/local/bin' => '/usr/local/archexec',
43 );
44 my $MyName = File::Basename::basename($0);
45
46 sub usage {
47 print STDERR <<USAGE;
48 Usage: $MyName prog_path dstroot
49 $MyName takes prog_path (full path relative to the dstroot)
50 and dstroot, and moves the program to the corresponding archexec
51 directory. It then creates a symbolic from prog_path to the arch
52 command. Finally, a plist file is created in
53 /System/Library/archSettings to default to using the 32-bit
54 architectures.
55 USAGE
56 exit 1;
57 }
58
59 usage() unless scalar(@ARGV) == 2;
60 my($vol, $dir, $file) = File::Spec->splitpath($ARGV[0]); # unix assumes $vol we be empty
61 $dir = File::Spec->canonpath($dir);
62 my $new = $Known{$dir};
63 die "$MyName: Unsupported directory $dir\n" unless defined($new);
64 my $dstroot = $ARGV[1];
65 die "$MyName: $dstroot: Not a full path\n" unless File::Spec->file_name_is_absolute($dstroot);
66 File::Path::mkpath(File::Spec->join($dstroot, $new), 1, 0755);
67 File::Path::mkpath(File::Spec->join($dstroot, $ArchSettings), 1, 0755);
68 my $execpath = File::Spec->canonpath(File::Spec->join($new, $file));
69 my $do = File::Spec->join($dstroot, $dir, $file);
70 my $dn = File::Spec->join($dstroot, $execpath);
71 rename($do, $dn) or die "$MyName: Can't move $file to $dn: $!\n";
72 print "renamed $do -> $dn\n";
73 my $l = File::Spec->abs2rel('/usr/bin/arch', $dir);
74 symlink($l, $do) or die "$MyName: Can't symlink $do -> $l: $!\n";
75 print "symlink $do -> $l\n";
76 my $plist = File::Spec->join($dstroot, $ArchSettings, $file . '.plist');
77 my $p = IO::File->new($plist, 'w') or die "$MyName: $plist: $!\n";
78 $p->print( <<PLIST );
79 <?xml version="1.0" encoding="UTF-8"?>
80 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
81 <plist version="1.0">
82 <dict>
83 <key>ExecutablePath</key>
84 <string>$execpath</string>
85 <key>PreferredOrder</key>
86 <array>
87 <string>i386</string>
88 <string>x86_64</string>
89 <string>ppc</string>
90 <string>ppc64</string>
91 </array>
92 <key>PropertyListVersion</key>
93 <string>1.0</string>
94 </dict>
95 </plist>
96 PLIST
97 $p->close();
98 print "created $plist\n";