xref: /trunk/main/solenv/bin/macosx-change-install-names.pl (revision 45c5a00162811bd03b87fcb4fe9996782f2b59ec)
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         # BRANDBIN: the executable is the bundle launcher in Contents/MacOS,
37         # while the libraries are installed in Contents/program.
38         'app/BRANDBIN/URELIB' => '@executable_path/../program',
39         'app/BRANDBIN/OOO' => '@executable_path/../program',
40         # gbuild calls its SDK and build-tool executable layers SDKBIN and NONEBIN.
41         'app/SDKBIN/URELIB' => '@executable_path',
42         'app/NONEBIN/URELIB' => '@__VIA_LIBRARY_PATH__',
43         'app/NONEBIN/OOO' => '@__VIA_LIBRARY_PATH__',
44         'app/NONE/URELIB' => '@__VIA_LIBRARY_PATH__',
45         'app/NONE/OOO' => '@__VIA_LIBRARY_PATH__',
46         'app/NONE/NONE' => '@__VIA_LIBRARY_PATH__',
47         'shl/URELIB/URELIB' => '@loader_path',
48         'shl/OOO/URELIB' => '@loader_path',
49         'shl/OOO/OOO' => '@loader_path',
50         'shl/LOADER/LOADER' => '@loader_path',
51         # Extension libraries can live inside the installation or in an
52         # extension directory, so they cannot use @loader_path; the office
53         # libraries are always in Contents/program, one level up from the
54         # launcher in Contents/MacOS and from the helper binaries themselves.
55         'shl/OXT/URELIB' => '@executable_path/../program',
56         'shl/BOXT/URELIB' => '@executable_path/../program',
57         'shl/BOXT/OOO' => '@loader_path',
58         'shl/NONE/URELIB' => '@__VIA_LIBRARY_PATH__',
59         'shl/NONE/OOO' => '@__VIA_LIBRARY_PATH__',
60         'shl/NONE/NONE' => '@__VIA_LIBRARY_PATH__');
61
62#        ('app/UREBIN/URELIB' => '@executable_path/../lib',
63#         'app/OOO/URELIB' => '@executable_path/../ure-link/lib',
64#         'app/OOO/OOO' => '@executable_path',
65#         'app/SDK/URELIB' => '@executable_path/../../ure-link/lib',
66#         'app/BRAND/URELIB' => '@executable_path/../basis-link/ure-link/lib',
67#         'app/BRAND/OOO' => '@executable_path/../basis-link/program',
68#         'app/NONE/URELIB' => '@__VIA_LIBRARY_PATH__',
69#         'app/NONE/OOO' => '@__VIA_LIBRARY_PATH__',
70#         'app/NONE/NONE' => '@__VIA_LIBRARY_PATH__',
71#         'shl/URELIB/URELIB' => '@loader_path',
72#         'shl/OOO/URELIB' => '@loader_path/../ure-link/lib',
73#         'shl/OOO/OOO' => '@loader_path',
74#         'shl/LOADER/LOADER' => '@loader_path',
75#         'shl/OXT/URELIB' => '@executable_path/urelibs',
76#         'shl/BOXT/URELIB' => '@executable_path/urelibs',
77#         'shl/BOXT/OOO' => '@loader_path/../../../basis-link/program',
78#         'shl/NONE/URELIB' => '@__VIA_LIBRARY_PATH__',
79#         'shl/NONE/OOO' => '@__VIA_LIBRARY_PATH__',
80#         'shl/NONE/NONE' => '@__VIA_LIBRARY_PATH__');
81
82    my ($type, $loc1, $loc2) = @_;
83    my $act = $action{"$type/$loc1/$loc2"};
84    die "illegal combination $type/$loc1/$loc2" unless defined $act;
85    return $act;
86}
87
88@ARGV == 3 || @ARGV >= 2 && $ARGV[0] eq "extshl" or die
89  'Usage: app|shl|extshl UREBIN|URELIB|OOO|SDK|BRAND|BRANDBIN|OXT|BOXT|NONE|LOADER <filepath>*';
90$type = shift @ARGV;
91$loc = shift @ARGV;
92if ($type eq "SharedLibrary")
93{
94    $type = "shl";
95}
96if ($type eq "Executable")
97{
98    $type = "app"
99}
100if ($type eq "Library")
101{
102    $type = "shl"
103}
104if ($type eq "extshl")
105{
106    $type = "shl";
107    my $change = "";
108    my %inames;
109    foreach $file (@ARGV)
110    {
111        my $iname = otoolD($file);
112        (defined $iname ? $iname : $file . "\n") =~ m'^(.*?([^/]+))\n$' or
113            die "unexpected otool -D output";
114        $change .= " -change $1 " . action($type, $loc, $loc) . "/$2";
115        $inames{$file} = $2;
116    }
117    if( $loc eq "LOADER" )
118    {
119        foreach $file (@ARGV)
120        {
121            my $call = "${::CC_PATH}install_name_tool$change -id \@loader_path/$inames{$file} $file";
122            system($call) == 0 or die "cannot $call";
123        }
124    }
125    else
126    {
127        foreach $file (@ARGV)
128        {
129            my $call = "${::CC_PATH}install_name_tool$change -id \@_______$loc/$inames{$file} $file";
130            system($call) == 0 or die "cannot $call";
131        }
132    }
133}
134foreach $file (@ARGV)
135{
136    my $call = "${::CC_PATH}otool -L $file";
137    open(IN, "-|", $call) or die "cannot $call";
138    my $change = "";
139    while (<IN>)
140    {
141        $change .= " -change $1 " . action($type, $loc, $2) . "$3"
142            if m'^\s*(@_{7}([^/]+)(/.+)) \(compatibility version \d+\.\d+\.\d+, current version \d+\.\d+\.\d+\)\n$';
143    }
144    close(IN);
145    if ($change ne "")
146    {
147        $call = "${::CC_PATH}install_name_tool$change $file";
148        system($call) == 0 or die "cannot $call";
149    }
150}
151