mirrored from https://gitlab.com/afif/bond
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bondcmd.pl
68 lines (52 loc) · 1.61 KB
/
bondcmd.pl
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
#!/usr/bin/perl
use strict;
use warnings;
use Cwd 'abs_path';
sub main {
my $prefix = abs_path($ARGV[0]);
my %variables = (
PATH => ['sbin', 'bin'],
MANPATH => ['share/man'],
LIBRARY_PATH => ['lib'],
LD_LIBRARY_PATH => ['lib'],
CPATH => ['include'],
PERL5LIB => ['lib/perl5/site_perl'],
GEM_PATH => [''],
R_LIBS => ['lib/R/site-library'],
);
my ($python_ver) = `python --version` =~ /Python (\d+\.\d+)/;
if ($python_ver ne "") {
$variables{'PYTHONPATH'} = ["lib/python$python_ver/site-packages"];
}
my $env_command;
foreach my $var (keys %variables) {
# Initialize empty variables to have a single colon.
# This is important for variables like MANPATH, which use the extra
# colon as a placeholder for the default search path.
$ENV{$var} = ':' if !defined $ENV{$var};
foreach my $element (@{$variables{$var}}) {
$ENV{$var} = "$prefix/$element:$ENV{$var}"
}
$env_command .= generate_export_cmd($var, $ENV{$var});
}
Make:
# * Make is special and has a weird way of defining its include environment
# variable. See:
# <http://lists.gnu.org/archive/html/help-make/2016-05/msg00013.html>
#
# * Make's include directory is shared with C/C++ headers.
$ENV{'MAKEFLAGS'} = '' if !defined $ENV{'MAKEFLAGS'};
foreach my $element (@{$variables{'CPATH'}}) {
$ENV{'MAKEFLAGS'} = "-I$prefix/$element $ENV{'MAKEFLAGS'}";
}
$env_command .= generate_export_cmd('MAKEFLAGS', $ENV{'MAKEFLAGS'});
print $env_command;
}
sub generate_export_cmd {
my (
$variable,
$value,
) = @_;
return "export $variable=\"$value\"\n";
}
exit(main(@ARGV));