summaryrefslogtreecommitdiffstats
path: root/lang/perl5/files/use.perl
blob: 08cef70c7ab36827d726897241e1122a1de084da (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
#! %%PREFIX%%/bin/perl -w
# $FreeBSD$
use strict;

# XXX what to do with perldoc, pelbug, perlcc ??

sub usage
{
	print STDERR <<EOF;
Usage:
  $0 port       -> /usr/bin/perl is the perl5 port
  $0 system     -> /usr/bin/perl is the system perl
EOF
	exit 2;
}

@ARGV == 1 or usage();
if ($ARGV[0] eq 'port') {
	switch_to_port();
} elsif ($ARGV[0] eq 'system') {
	switch_to_system();
} else {
	usage();
}
exit 0;

sub switch_to_system
{
	my $port_perl = '%%PREFIX%%/bin/perl';
	$port_perl =~ tr|/|/|s;

	# protect against cases where people use PREFIX=/usr
	if ($port_perl ne '/usr/bin/perl') {
		unlink '/usr/bin/perl', '/usr/bin/suidperl',
			'/usr/bin/perl%%PERL_VERSION%%';

		link '/usr/bin/perl5', '/usr/bin/perl';
		link '/usr/bin/sperl5', '/usr/bin/suidperl';
	}

	open MK, ">> /etc/make.conf" or die "/etc/make.conf: $!";
	print MK <<EOF;
# -- use.perl generated deltas -- #
# Created: @{[scalar localtime]}
# Setting to use base system perl:
.undef PERL_VER
.undef PERL_VERSION
.undef PERL_ARCH
.undef NOPERL

EOF
	close MK;
}

sub switch_to_port
{
	my $port_perl = '%%PREFIX%%/bin/perl';
	$port_perl =~ tr|/|/|s;

	# protect against cases where people use PREFIX=/usr
	if ($port_perl ne '/usr/bin/perl') {
		unlink '/usr/bin/perl', '/usr/bin/suidperl',
			'/usr/bin/perl%%PERL_VERSION%%';

		symlink '%%PREFIX%%/bin/perl', '/usr/bin/perl';
		symlink '%%PREFIX%%/bin/suidperl', '/usr/bin/suidperl';
		symlink '%%PREFIX%%/bin/perl', '/usr/bin/perl%%PERL_VERSION%%';
	}

	open MK, ">> /etc/make.conf" or die "/etc/make.conf: $!";
	print MK <<EOF;
# -- use.perl generated deltas -- #
# Created: @{[scalar localtime]}
# Setting to use base perl from ports:
PERL_VER=%%PERL_VER%%
PERL_VERSION=%%PERL_VERSION%%
PERL_ARCH=%%PERL_ARCH%%
NOPERL=yo

EOF
	close MK;
}
OpenPOWER on IntegriCloud