xref: /openbsd-src/usr.bin/libtool/LT/Util.pm (revision 91f110e064cd7c194e59e019b83bb7496c1c84d4)
1# $OpenBSD: Util.pm,v 1.5 2012/07/10 12:24:45 espie Exp $
2
3# Copyright (c) 2007-2010 Steven Mestdagh <steven@openbsd.org>
4# Copyright (c) 2012 Marc Espie <espie@openbsd.org>
5#
6# Permission to use, copy, modify, and distribute this software for any
7# purpose with or without fee is hereby granted, provided that the above
8# copyright notice and this permission notice appear in all copies.
9#
10# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
18use strict;
19use warnings;
20package LT::Util;
21require Exporter;
22our @ISA = qw(Exporter);
23our @EXPORT = qw(reverse_zap_duplicates_ref abs_dir $ltdir $version shortdie);
24use File::Basename;
25use Cwd;
26
27our $ltdir = '.libs';
28our $version = '1.5.26'; # pretend to be this version of libtool
29
30# walk a list from back to front, removing any duplicates
31# this should make sure a library's dependencies are behind the library itself
32sub reverse_zap_duplicates_ref
33{
34	my $arglist = shift;
35	my $h = {};
36	my $r = [];
37	for my $el (reverse @$arglist) {
38		next if defined $h->{$el};
39		unshift @$r, $el;
40		$h->{$el} = 1;
41	}
42	return $r;
43}
44
45sub abs_dir
46{
47	my $a = shift;
48	return dirname(Cwd::abs_path($a));
49}
50
51sub shortdie
52{
53	$SIG{__DIE__} = 'DEFAULT';
54	die @_;
55}
56
571;
58