xref: /openbsd-src/usr.bin/libtool/LT/Program.pm (revision 0a6aab58a9ecdd9d26650fde0b817a724ac8dbc6)
1*0a6aab58Sespie# $OpenBSD: Program.pm,v 1.20 2023/07/08 08:15:32 espie Exp $
2dd9b5fdeSespie
3dd9b5fdeSespie# Copyright (c) 2007-2010 Steven Mestdagh <steven@openbsd.org>
4b8664c47Sespie# Copyright (c) 2012 Marc Espie <espie@openbsd.org>
5dd9b5fdeSespie#
6dd9b5fdeSespie# Permission to use, copy, modify, and distribute this software for any
7dd9b5fdeSespie# purpose with or without fee is hereby granted, provided that the above
8dd9b5fdeSespie# copyright notice and this permission notice appear in all copies.
9dd9b5fdeSespie#
10dd9b5fdeSespie# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11dd9b5fdeSespie# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12dd9b5fdeSespie# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13dd9b5fdeSespie# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14dd9b5fdeSespie# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15dd9b5fdeSespie# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16dd9b5fdeSespie# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17dd9b5fdeSespie
18*0a6aab58Sespieuse v5.36;
19dd9b5fdeSespie
20dd9b5fdeSespiepackage LT::Program;
21dd9b5fdeSespieuse File::Basename;
22dd9b5fdeSespieuse LT::Archive;
23dd9b5fdeSespieuse LT::Util;
24f98ddbc5Sespieuse LT::Trace;
25dd9b5fdeSespie
26*0a6aab58Sespiesub new($class)
27dd9b5fdeSespie{
28dd9b5fdeSespie	bless {}, $class;
29dd9b5fdeSespie}
30dd9b5fdeSespie
31dd9b5fdeSespie# write a wrapper script for an executable so it can be executed within
32dd9b5fdeSespie# the build directory
33*0a6aab58Sespiesub write_wrapper($self)
34dd9b5fdeSespie{
35dd9b5fdeSespie	my $program = $self->{outfilepath};
36fc08f4fdSespie	my $pfile = basename($program);
37dd9b5fdeSespie	my $realprogram = $ltdir . '/' . $pfile;
38dd9b5fdeSespie	open(my $pw, '>', $program) or die "Cannot write $program: $!\n";
39dd9b5fdeSespie	print $pw <<EOF
40dd9b5fdeSespie#!/bin/sh
41dd9b5fdeSespie
42dd9b5fdeSespie# $program - wrapper for $realprogram
43dd9b5fdeSespie# Generated by libtool $version
44dd9b5fdeSespie
45dd9b5fdeSespieargdir=`dirname \$0`
46dd9b5fdeSespieif test -f "\$argdir/$realprogram"; then
47dd9b5fdeSespie    # Add our own library path to LD_LIBRARY_PATH
48dd9b5fdeSespie    LD_LIBRARY_PATH=\$argdir/$ltdir
49dd9b5fdeSespie    export LD_LIBRARY_PATH
50dd9b5fdeSespie
51dd9b5fdeSespie    # Run the actual program with our arguments.
52dd9b5fdeSespie    exec "\$argdir/$realprogram" \${1+"\$\@"}
53dd9b5fdeSespie
54dd9b5fdeSespie    echo "\$0: cannot exec $program \${1+"\$\@"}"
55dd9b5fdeSespie    exit 1
56dd9b5fdeSespieelse
57dd9b5fdeSespie    echo "\$0: error: \\\`\$argdir/$realprogram' does not exist." 1>&2
58dd9b5fdeSespie    exit 1
59dd9b5fdeSespiefi
60dd9b5fdeSespieEOF
61dd9b5fdeSespie;
62dd9b5fdeSespie	close($pw);
63dd9b5fdeSespie	chmod 0755, $program;
64dd9b5fdeSespie}
65dd9b5fdeSespie
66*0a6aab58Sespiesub install($class, $src, $dst, $instprog, $instopts)
67fc08f4fdSespie{
68fc08f4fdSespie	my $srcdir = dirname $src;
69fc08f4fdSespie	my $srcfile = basename $src;
70fc08f4fdSespie	my $realpath = "$srcdir/$ltdir/$srcfile";
71fc08f4fdSespie	LT::Exec->install(@$instprog, @$instopts, $realpath, $dst);
72fc08f4fdSespie}
73fc08f4fdSespie
74dd9b5fdeSespie1;
75