]> git.saurik.com Git - apple/system_cmds.git/blame - arch.tproj/arch_helper.pl
system_cmds-550.10.tar.gz
[apple/system_cmds.git] / arch.tproj / arch_helper.pl
CommitLineData
34d340d7
A
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
33use strict;
34use File::Basename ();
35use File::Path ();
36use File::Spec;
37use IO::File;
38
39my $ArchSettings = '/System/Library/archSettings';
40my %Known = (
41 '/usr/bin' => '/usr/archexec',
42 '/usr/local/bin' => '/usr/local/archexec',
43);
44my $MyName = File::Basename::basename($0);
45
46sub usage {
47 print STDERR <<USAGE;
48Usage: $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.
55USAGE
56 exit 1;
57}
58
59usage() unless scalar(@ARGV) == 2;
60my($vol, $dir, $file) = File::Spec->splitpath($ARGV[0]); # unix assumes $vol we be empty
61$dir = File::Spec->canonpath($dir);
62my $new = $Known{$dir};
63die "$MyName: Unsupported directory $dir\n" unless defined($new);
64my $dstroot = $ARGV[1];
65die "$MyName: $dstroot: Not a full path\n" unless File::Spec->file_name_is_absolute($dstroot);
66File::Path::mkpath(File::Spec->join($dstroot, $new), 1, 0755);
67File::Path::mkpath(File::Spec->join($dstroot, $ArchSettings), 1, 0755);
68my $execpath = File::Spec->canonpath(File::Spec->join($new, $file));
69my $do = File::Spec->join($dstroot, $dir, $file);
70my $dn = File::Spec->join($dstroot, $execpath);
71rename($do, $dn) or die "$MyName: Can't move $file to $dn: $!\n";
72print "renamed $do -> $dn\n";
73my $l = File::Spec->abs2rel('/usr/bin/arch', $dir);
74symlink($l, $do) or die "$MyName: Can't symlink $do -> $l: $!\n";
75print "symlink $do -> $l\n";
76my $plist = File::Spec->join($dstroot, $ArchSettings, $file . '.plist');
77my $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>
96PLIST
97$p->close();
98print "created $plist\n";