xref: /trunk/main/solenv/bin/macosx-dylib-link-list.pl (revision 9ff3e22531fe821dc01eb80c3b7fce8ee067d164)
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 locate($)
28{
29    my ($lib) = @_;
30    my $dir;
31    foreach $dir (@dirs)
32    {
33        my $path = "$dir/$lib";
34        if (-e $path)
35        {
36            return $path;
37        }
38    }
39    return;
40}
41
42sub handle($$)
43{
44    my ($from, $to) = @_;
45    # wrap -dylib_file in -Wl so that hopefully any used tool whatsoever (e.g.,
46    # libtool generated from xmlsec1-1.2.6/configure included in
47    # libxmlsec/download/xmlsec1-1.2.6.tar.gz:1.3) passes it through to the
48    # linker:
49    !($from =~ /,/ || $to =~ /,/) or
50        die "$from:$to contains commas and cannot go into -Wl";
51    print " -Wl,-dylib_file,$from:$to";
52    $done{$from} = 1;
53    push(@todo, $to) if (grep {$_ eq $to} @todo) == 0;
54}
55
56foreach (@ARGV) { push(@dirs, $1) if /^-L(.*)$/; }
57foreach (@ARGV)
58{
59    if (/^-l(.*)$/)
60    {
61        my $loc = locate("lib$1.dylib");
62        # A makefile's STDLIBS/STDSHL lists can legitimately name the same
63        # library twice (accumulated from more than one variable). Unlike
64        # the @todo loop below, this pass had no dedup guard, so a repeated
65        # -lfoo emitted the same -dylib_file entry twice; ld then reports
66        # that entry as "recursively loading" instead of just ignoring the
67        # duplicate.
68        if (defined $loc && otoolD($loc) =~ m'^(@.+/.+)\n$')
69        {
70            handle($1, $loc) unless defined $done{$1};
71        }
72    }
73}
74foreach $file (@todo)
75{
76    my $call = "${::CC_PATH}otool -L $file";
77    open(IN, "-|", $call) or die "cannot $call";
78    while (<IN>)
79    {
80        if (m'^\s*(@.+/([^/]+)) \(compatibility version \d+\.\d+\.\d+, current version \d+\.\d+\.\d+\)\n$')
81        {
82            my $full = $1;
83            my $loc = locate($2);
84            if (defined $loc)
85            {
86                handle($full, $loc) unless defined $done{$full};
87            }
88            else
89            {
90                die "unknown $full (from $file)";
91            }
92        }
93    }
94    close(IN);
95}
96print "\n";
97