summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add/OpenBSD/SharedLibs.pm
blob: b633d915d774c75f642d0d6a63ffe643efc51774 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# ex:ts=8 sw=4:
# $OpenBSD: SharedLibs.pm,v 1.57 2010/12/24 10:31:59 espie Exp $
#
# Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

use strict;
use warnings;

use OpenBSD::Paths;
use OpenBSD::LibSpec;

package OpenBSD::PackingElement;

sub mark_available_lib
{
}

package OpenBSD::PackingElement::Lib;

sub mark_available_lib
{
	my ($self, $pkgname, $state) = @_;
	OpenBSD::SharedLibs::register_libname($self->fullname,
	    $pkgname, $state);
}

package OpenBSD::SharedLibs;
use File::Basename;
use OpenBSD::Error;

our $repo = OpenBSD::LibRepo->new;

sub register_library
{
	my ($lib, $pkgname) = @_;
	$repo->register($lib, $pkgname);
}

sub register_libname
{
	my ($name, $pkgname, $state) = @_;
	my $lib = OpenBSD::Library->from_string($name);
	if ($lib->is_valid) {
		register_library($lib, $pkgname);
	} else {
		$state->errsay("Bogus library in #1: #2", $pkgname, $name)
		    unless $pkgname eq 'system';
	}

}

my $done_plist = {};

sub system_dirs
{
	return OpenBSD::Paths->library_dirs;
}

sub add_libs_from_system
{
	my ($destdir, $state) = @_;
	return if $done_plist->{'system'};
	$done_plist->{'system'} = 1;
	for my $dirname (system_dirs()) {
		opendir(my $dir, $destdir.$dirname."/lib") or next;
		while (my $d = readdir($dir)) {
			next unless $d =~ m/\.so/;
			register_libname("$dirname/lib/$d", 'system', $state);
		}
		closedir($dir);
	}
}

sub add_libs_from_installed_package
{
	my ($pkgname, $state) = @_;
	return if $done_plist->{$pkgname};
	$done_plist->{$pkgname} = 1;
	my $plist = OpenBSD::PackingList->from_installation($pkgname,
	    \&OpenBSD::PackingList::LibraryOnly);
	return if !defined $plist;

	$plist->mark_available_lib($pkgname, $state);
}

sub add_libs_from_plist
{
	my ($plist, $state) = @_;
	my $pkgname = $plist->pkgname;
	return if $done_plist->{$pkgname};
	$done_plist->{$pkgname} = 1;
	$plist->mark_available_lib($pkgname, $state);
}

sub lookup_libspec
{
	my ($base, $spec) = @_;
	return $spec->lookup($repo, $base);
}

my $printed = {};

sub report_problem
{
	my ($state, $spec) = @_;
	my $name = $spec->to_string;
	my $base = $state->{localbase};
	my $approx = $spec->lookup_stem($repo);

	my $r = "";
	if (!$spec->is_valid) {
		$r = "| bad library specification\n";
	} elsif (!defined $approx) {
 		$r = "| not found anywhere\n";
	} else {
		for my $bad (@$approx) {
			my $ouch = $spec->no_match($bad, $base);
			$ouch //= "not reachable";
			$r .= "| ".$bad->to_string." (".$bad->origin."): ".
			    $ouch."\n";
		}
	}
	if (!defined $printed->{$name} || $printed->{$name} ne $r) {
		$printed->{$name} = $r;
		$state->errsay("|library #1 not found", $name);
		$state->print("#1", $r);
	}
}

1;