1#************************************************************** 2# 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance 9# with the License. You may obtain a copy of the License at 10# 11# http://www.apache.org/licenses/LICENSE-2.0 12# 13# Unless required by applicable law or agreed to in writing, 14# software distributed under the License is distributed on an 15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16# KIND, either express or implied. See the License for the 17# specific language governing permissions and limitations 18# under the License. 19# 20#************************************************************** 21 22 23 24use lib ("$ENV{SOLARENV}/bin/modules"); 25use macosxotoolhelper; 26 27sub action($$$) 28{ 29 my %action = 30 ('app/UREBIN/URELIB' => '@executable_path/../lib', 31 'app/OOO/URELIB' => '@executable_path/../ure-link/lib', 32 'app/OOO/OOO' => '@executable_path', 33 'app/SDK/URELIB' => '@executable_path/../../ure-link/lib', 34 'app/BRAND/URELIB' => '@executable_path/../basis-link/ure-link/lib', 35 'app/BRAND/OOO' => '@executable_path/../basis-link/program', 36 'app/NONE/URELIB' => '@__VIA_LIBRARY_PATH__', 37 'app/NONE/OOO' => '@__VIA_LIBRARY_PATH__', 38 'app/NONE/NONE' => '@__VIA_LIBRARY_PATH__', 39 'shl/URELIB/URELIB' => '@loader_path', 40 'shl/OOO/URELIB' => '@loader_path/../ure-link/lib', 41 'shl/OOO/OOO' => '@loader_path', 42 'shl/LOADER/LOADER' => '@loader_path', 43 'shl/OXT/URELIB' => '@executable_path/urelibs', 44 'shl/BOXT/URELIB' => '@executable_path/urelibs', 45 'shl/BOXT/OOO' => '@loader_path/../../../basis-link/program', 46 'shl/NONE/URELIB' => '@__VIA_LIBRARY_PATH__', 47 'shl/NONE/OOO' => '@__VIA_LIBRARY_PATH__', 48 'shl/NONE/NONE' => '@__VIA_LIBRARY_PATH__'); 49 my ($type, $loc1, $loc2) = @_; 50 my $act = $action{"$type/$loc1/$loc2"}; 51 die "illegal combination $type/$loc1/$loc2" unless defined $act; 52 return $act; 53} 54 55@ARGV == 3 || @ARGV >= 2 && $ARGV[0] eq "extshl" or die 56 'Usage: app|shl|extshl UREBIN|URELIB|OOO|SDK|BRAND|OXT|BOXT|NONE|LOADER <filepath>*'; 57$type = shift @ARGV; 58$loc = shift @ARGV; 59if ($type eq "SharedLibrary") 60{ 61 $type = "shl"; 62} 63if ($type eq "Executable") 64{ 65 $type = "app" 66} 67if ($type eq "Library") 68{ 69 $type = "shl" 70} 71if ($type eq "extshl") 72{ 73 $type = "shl"; 74 my $change = ""; 75 my %inames; 76 foreach $file (@ARGV) 77 { 78 my $iname = otoolD($file); 79 (defined $iname ? $iname : $file . "\n") =~ m'^(.*?([^/]+))\n$' or 80 die "unexpected otool -D output"; 81 $change .= " -change $1 " . action($type, $loc, $loc) . "/$2"; 82 $inames{$file} = $2; 83 } 84 if( $loc eq "LOADER" ) 85 { 86 foreach $file (@ARGV) 87 { 88 my $call = "install_name_tool$change -id \@loader_path/$inames{$file} $file"; 89 system($call) == 0 or die "cannot $call"; 90 } 91 } 92 else 93 { 94 foreach $file (@ARGV) 95 { 96 my $call = "install_name_tool$change -id \@__________________________________________________$loc/$inames{$file} $file"; 97 system($call) == 0 or die "cannot $call"; 98 } 99 } 100} 101foreach $file (@ARGV) 102{ 103 my $call = "otool -L $file"; 104 open(IN, "-|", $call) or die "cannot $call"; 105 my $change = ""; 106 while (<IN>) 107 { 108 $change .= " -change $1 " . action($type, $loc, $2) . "$3" 109 if m'^\s*(@_{50}([^/]+)(/.+)) \(compatibility version \d+\.\d+\.\d+, current version \d+\.\d+\.\d+\)\n$'; 110 } 111 close(IN); 112 if ($change ne "") 113 { 114 $call = "install_name_tool$change $file"; 115 system($call) == 0 or die "cannot $call"; 116 } 117} 118