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', 31 'app/OOO/URELIB' => '@executable_path/', 32 'app/OOO/OOO' => '@executable_path', 33 'app/SDK/URELIB' => '@executable_path', 34 'app/BRAND/URELIB' => '@executable_path', 35 'app/BRAND/OOO' => '@executable_path', 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', 41 'shl/OOO/OOO' => '@loader_path', 42 'shl/LOADER/LOADER' => '@loader_path', 43 'shl/OXT/URELIB' => '@executable_path', 44 'shl/BOXT/URELIB' => '@executable_path', 45 'shl/BOXT/OOO' => '@loader_path', 46 'shl/NONE/URELIB' => '@__VIA_LIBRARY_PATH__', 47 'shl/NONE/OOO' => '@__VIA_LIBRARY_PATH__', 48 'shl/NONE/NONE' => '@__VIA_LIBRARY_PATH__'); 49 50# ('app/UREBIN/URELIB' => '@executable_path/../lib', 51# 'app/OOO/URELIB' => '@executable_path/../ure-link/lib', 52# 'app/OOO/OOO' => '@executable_path', 53# 'app/SDK/URELIB' => '@executable_path/../../ure-link/lib', 54# 'app/BRAND/URELIB' => '@executable_path/../basis-link/ure-link/lib', 55# 'app/BRAND/OOO' => '@executable_path/../basis-link/program', 56# 'app/NONE/URELIB' => '@__VIA_LIBRARY_PATH__', 57# 'app/NONE/OOO' => '@__VIA_LIBRARY_PATH__', 58# 'app/NONE/NONE' => '@__VIA_LIBRARY_PATH__', 59# 'shl/URELIB/URELIB' => '@loader_path', 60# 'shl/OOO/URELIB' => '@loader_path/../ure-link/lib', 61# 'shl/OOO/OOO' => '@loader_path', 62# 'shl/LOADER/LOADER' => '@loader_path', 63# 'shl/OXT/URELIB' => '@executable_path/urelibs', 64# 'shl/BOXT/URELIB' => '@executable_path/urelibs', 65# 'shl/BOXT/OOO' => '@loader_path/../../../basis-link/program', 66# 'shl/NONE/URELIB' => '@__VIA_LIBRARY_PATH__', 67# 'shl/NONE/OOO' => '@__VIA_LIBRARY_PATH__', 68# 'shl/NONE/NONE' => '@__VIA_LIBRARY_PATH__'); 69 70 my ($type, $loc1, $loc2) = @_; 71 my $act = $action{"$type/$loc1/$loc2"}; 72 die "illegal combination $type/$loc1/$loc2" unless defined $act; 73 return $act; 74} 75 76@ARGV == 3 || @ARGV >= 2 && $ARGV[0] eq "extshl" or die 77 'Usage: app|shl|extshl UREBIN|URELIB|OOO|SDK|BRAND|OXT|BOXT|NONE|LOADER <filepath>*'; 78$type = shift @ARGV; 79$loc = shift @ARGV; 80if ($type eq "SharedLibrary") 81{ 82 $type = "shl"; 83} 84if ($type eq "Executable") 85{ 86 $type = "app" 87} 88if ($type eq "Library") 89{ 90 $type = "shl" 91} 92if ($type eq "extshl") 93{ 94 $type = "shl"; 95 my $change = ""; 96 my %inames; 97 foreach $file (@ARGV) 98 { 99 my $iname = otoolD($file); 100 (defined $iname ? $iname : $file . "\n") =~ m'^(.*?([^/]+))\n$' or 101 die "unexpected otool -D output"; 102 $change .= " -change $1 " . action($type, $loc, $loc) . "/$2"; 103 $inames{$file} = $2; 104 } 105 if( $loc eq "LOADER" ) 106 { 107 foreach $file (@ARGV) 108 { 109 my $call = "${::CC_PATH}install_name_tool$change -id \@loader_path/$inames{$file} $file"; 110 system($call) == 0 or die "cannot $call"; 111 } 112 } 113 else 114 { 115 foreach $file (@ARGV) 116 { 117 my $call = "${::CC_PATH}install_name_tool$change -id \@__________________________________________________$loc/$inames{$file} $file"; 118 system($call) == 0 or die "cannot $call"; 119 } 120 } 121} 122foreach $file (@ARGV) 123{ 124 my $call = "${::CC_PATH}otool -L $file"; 125 open(IN, "-|", $call) or die "cannot $call"; 126 my $change = ""; 127 while (<IN>) 128 { 129 $change .= " -change $1 " . action($type, $loc, $2) . "$3" 130 if m'^\s*(@_{50}([^/]+)(/.+)) \(compatibility version \d+\.\d+\.\d+, current version \d+\.\d+\.\d+\)\n$'; 131 } 132 close(IN); 133 if ($change ne "") 134 { 135 $call = "${::CC_PATH}install_name_tool$change $file"; 136 system($call) == 0 or die "cannot $call"; 137 } 138} 139