1c81ca2caSespie# ex:ts=8 sw=4: 2*0a6aab58Sespie# $OpenBSD: Install.pm,v 1.9 2023/07/08 08:15:32 espie Exp $ 3c81ca2caSespie# 4c81ca2caSespie# Copyright (c) 2007-2010 Steven Mestdagh <steven@openbsd.org> 5c81ca2caSespie# Copyright (c) 2012 Marc Espie <espie@openbsd.org> 6c81ca2caSespie# 7c81ca2caSespie# Permission to use, copy, modify, and distribute this software for any 8c81ca2caSespie# purpose with or without fee is hereby granted, provided that the above 9c81ca2caSespie# copyright notice and this permission notice appear in all copies. 10c81ca2caSespie# 11c81ca2caSespie# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12c81ca2caSespie# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13c81ca2caSespie# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14c81ca2caSespie# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15c81ca2caSespie# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16c81ca2caSespie# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17c81ca2caSespie# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18*0a6aab58Sespieuse v5.36; 19c81ca2caSespie 20c81ca2caSespiepackage LT::Mode::Install; 2164a5d04fSespieour @ISA = qw(LT::Mode); 22c81ca2caSespie 23c81ca2caSespieuse LT::Util; 24f98ddbc5Sespieuse LT::Trace; 25c81ca2caSespieuse Getopt::Std; 26c81ca2caSespieuse File::Basename; 27c81ca2caSespie 28*0a6aab58Sespiesub help($) 29ec47798dSespie{ 30ec47798dSespie print <<"EOH"; 31ec47798dSespie 32ec47798dSespieUsage: $0 --mode=install [cp|install] [parameters] source dest 33ec47798dSespieInstall executables/libraries. 34ec47798dSespieEOH 35ec47798dSespie} 36ec47798dSespie 37*0a6aab58Sespie# don't care about gp or ltconfig for install ! 38*0a6aab58Sespiesub run($class, $ltprog, $, $) 39c81ca2caSespie{ 40c81ca2caSespie # we just parse the options in order to find the actual arguments 41c81ca2caSespie my @argvcopy = @ARGV; 42c81ca2caSespie my %install_opts; 43f98ddbc5Sespie tsay {"ltprog[-1] = $$ltprog[-1]"}; 44f418c875Sespie if ($$ltprog[-1] =~ m/install([.-](sh|check|wrapper))?$/) { 45c81ca2caSespie getopts('BbCcdf:g:m:o:pSs', \%install_opts); 46c81ca2caSespie if (@ARGV < 2 && (!defined $install_opts{'d'} && @ARGV == 1)) { 47c81ca2caSespie die "Wrong number of arguments for install\n"; 48c81ca2caSespie } 49c81ca2caSespie } elsif ($$ltprog[-1] =~ m/cp$/) { 50c81ca2caSespie getopts('HLPRfipr', \%install_opts); 51c81ca2caSespie if (@ARGV < 2) { 52c81ca2caSespie die "Wrong number of arguments for install\n"; 53c81ca2caSespie } 54c81ca2caSespie } else { 55c81ca2caSespie die "Unsupported install program $$ltprog[-1]\n"; 56c81ca2caSespie } 57c81ca2caSespie my @instopts = @argvcopy[0 .. (@argvcopy - @ARGV - 1)]; 58c81ca2caSespie my $dst = pop @ARGV; 59c81ca2caSespie my @src = @ARGV; 60c81ca2caSespie my $dstdir; 61c81ca2caSespie if (-d $dst) { 62c81ca2caSespie $dstdir = $dst; 63c81ca2caSespie } else { 64c81ca2caSespie # dst is not a directory, i.e. a file 65c81ca2caSespie if (@src > 1) { 66c81ca2caSespie # XXX not really libtool's task to check this 67c81ca2caSespie die "Multiple source files combined with file destination.\n"; 68c81ca2caSespie } else { 69dfdae2a0Sespie $dstdir = dirname($dst); 70c81ca2caSespie } 71c81ca2caSespie } 72c81ca2caSespie foreach my $s (@src) { 73dfdae2a0Sespie my $dstfile = basename($s); 74c81ca2caSespie # resolve symbolic links, so we don't try to test later 75c81ca2caSespie # whether the symlink is a program wrapper etc. 76c81ca2caSespie if (-l $s) { 77c81ca2caSespie $s = readlink($s) or die "Cannot readlink $s: $!\n"; 78c81ca2caSespie } 79dfdae2a0Sespie my $srcdir = dirname($s); 80dfdae2a0Sespie my $srcfile = basename($s); 81f98ddbc5Sespie tsay {"srcdir = $srcdir\nsrcfile = $srcfile"}; 82f98ddbc5Sespie tsay {"dstdir = $dstdir\ndstfile = $dstfile"}; 83c81ca2caSespie if ($srcfile =~ m/^\S+\.la$/) { 84c81ca2caSespie require LT::LaFile; 85c81ca2caSespie LT::LaFile->install($s, $dstdir, $ltprog, \@instopts, $install_opts{'s'}); 86c81ca2caSespie } elsif (-f "$srcdir/$ltdir/$srcfile" && is_wrapper($s)) { 87c81ca2caSespie require LT::Program; 88c81ca2caSespie LT::Program->install($s, $dst, $ltprog, \@instopts); 89c81ca2caSespie } else { 90c81ca2caSespie LT::Exec->install(@$ltprog, @instopts, $s, $dst); 91c81ca2caSespie } 92c81ca2caSespie } 93f98ddbc5Sespie if (defined $install_opts{d}) { 94c81ca2caSespie LT::Exec->install(@$ltprog, @instopts, @ARGV); 95c81ca2caSespie } 96c81ca2caSespie} 97c81ca2caSespie 98*0a6aab58Sespiesub is_wrapper($program) 99c81ca2caSespie{ 100c81ca2caSespie open(my $pw, '<', $program) or die "Cannot open $program: $!\n"; 10128252c27Safresh1 my $line = <$pw>; 102dfdae2a0Sespie # if the first line isn't a shell, don't even bother 10328252c27Safresh1 return 0 unless $line =~ m/^\#\!/; 104dfdae2a0Sespie my $i = 0; 10528252c27Safresh1 while (my $line = <$pw>) { 10628252c27Safresh1 return 1 if $line =~ m/wrapper\sfor/; 107dfdae2a0Sespie last if $i++ > 10; 108dfdae2a0Sespie } 109dfdae2a0Sespie return 0; 110c81ca2caSespie} 111c81ca2caSespie 112c81ca2caSespie1; 113