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