xref: /openbsd-src/usr.bin/libtool/LT/LoFile.pm (revision f41ccc36c98bb70900c901ba8385dbb26f3cea97)
1*f41ccc36Sespie# $OpenBSD: LoFile.pm,v 1.6 2023/07/06 08:29:26 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*f41ccc36Sespieuse v5.36;
19dd9b5fdeSespie
20dd9b5fdeSespiepackage LT::LoFile;
21dd9b5fdeSespieuse parent qw(LT::LaLoFile);
22dd9b5fdeSespieuse File::Basename;
23dd9b5fdeSespieuse LT::Util;
24dd9b5fdeSespie
25dd9b5fdeSespie# write a libtool object file
26*f41ccc36Sespiesub write($self, $filename)
27dd9b5fdeSespie{
28dd9b5fdeSespie	my $picobj = $self->stringize('picobj');
29dd9b5fdeSespie	my $nonpicobj = $self->stringize('nonpicobj');
30dd9b5fdeSespie
31dd9b5fdeSespie	my $name = basename $filename;
32dd9b5fdeSespie
33dd9b5fdeSespie	open(my $lo, '>', $filename) or die "Cannot write $filename: $!\n";
34b5f8d823Sjasper	say "creating $filename" if $main::verbose;
35dd9b5fdeSespie	print $lo <<EOF
36dd9b5fdeSespie# $name - a libtool object file
37b5f8d823Sjasper# Generated by libtool $version
38dd9b5fdeSespie#
39dd9b5fdeSespiepic_object='$picobj'
40dd9b5fdeSespienon_pic_object='$nonpicobj'
41dd9b5fdeSespieEOF
42dd9b5fdeSespie;
43dd9b5fdeSespie}
44dd9b5fdeSespie
45*f41ccc36Sespiesub compile($self, $compiler, $odir, $args)
46dd9b5fdeSespie{
47d9d84c96Sespie	mkdir "$odir/$ltdir" unless -d "$odir/$ltdir";
48dd9b5fdeSespie	if (defined $self->{picobj}) {
49dd9b5fdeSespie		my @cmd = @$compiler;
50d9d84c96Sespie		push @cmd, @$args if @$args;
51d1c91ecfSespie		push @cmd, @{$self->{picflags}}, '-o';
52dd9b5fdeSespie		my $o = ($odir eq '.') ? '' : "$odir/";
53dd9b5fdeSespie		$o .= $self->{picobj};
54dd9b5fdeSespie		push @cmd, $o;
55dd9b5fdeSespie		LT::Exec->compile(@cmd);
56dd9b5fdeSespie	}
57dd9b5fdeSespie	if (defined $self->{nonpicobj}) {
58dd9b5fdeSespie		my @cmd = @$compiler;
59d9d84c96Sespie		push @cmd, @$args if @$args;
60d1c91ecfSespie		push @cmd, @{$self->{nonpicflags}}, '-o';
61dd9b5fdeSespie		my $o = ($odir eq '.') ? '' : "$odir/";
62dd9b5fdeSespie		$o .= $self->{nonpicobj};
63dd9b5fdeSespie		push @cmd, $o;
64dd9b5fdeSespie		LT::Exec->compile(@cmd);
65dd9b5fdeSespie	}
66dd9b5fdeSespie}
67dd9b5fdeSespie
68dd9b5fdeSespie1;
69