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