forked from odit/rv042
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv-setup.pl
executable file
·170 lines (145 loc) · 3.77 KB
/
env-setup.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/perl
use strict;
use Getopt::Long;
use Cwd;
use Env qw(PATH);
# Strip shell argument off of remaining args. Do this first
# as some machines (SL3) list shell as '-bash', which if left
# on will confuse getoptions
my $shell = shift(@ARGV);
# Clean up empty args we get from wrapper script
my $tmp;
while (!$tmp && scalar(@ARGV))
{
$tmp = pop(@ARGV);
push(@ARGV, $tmp) if $tmp;
}
my $octeon_model;
my $octeon_root;
# process command line options
my $runtime_model_flag = 0;
my $verbose = 0;
GetOptions("runtime-model!" => \$runtime_model_flag,
"verbose!" => \$verbose,
);
if (scalar(@ARGV) > 1 || scalar(@ARGV) < 1)
{
usage();
print 'echo ""';
exit;
}
elsif (scalar(@ARGV) == 2)
{
$octeon_root = $ARGV[1];
}
else
{
$octeon_root = cwd();
}
$octeon_model = $ARGV[0];
sub usage
{
warn "Usage: source ./env-setup <OCTEON_MODEL> [--runtime-model] ...\n";
warn " OCTEON_MODEL: Model of Octeon to build and simulate for.\n";
warn " --runtime-model: enables runtime model detection build option by setting environment variable.\n";
warn " use --noruntime-model to clear environment variable if desired.\n";
warn " --verbose: be verbose about what the script is doing\n";
}
my %env_hash; # Hash to fill with env variables to set
my @env_clear; #list of environment variables to clear
my $key;
my $extra_path = "$octeon_root/tools/bin:$octeon_root/host/bin";
# validate OCTEON_MODEL. Warn but proceed if if octeon-models.txt is not present.
if (open(FH, "$octeon_root/octeon-models.txt"))
{
my @models = <FH>;
my ($match) = grep(/^$octeon_model$/, @models);
if (!$match)
{
warn "ERROR: $octeon_model is not a valid OCTEON_MODEL value. Please see \$OCTEON_ROOT/octeon-models.txt for list\n";
print "echo ERROR: $octeon_model is not a valid OCTEON_MODEL value. Please see \\\$OCTEON_ROOT/octeon-models.txt for list\n";
exit;
}
}
else
{
warn 'Warning: unable to open file $OCTEON_ROOT/octeon-models.txt, can\'t validate OCTEON_MODEL\n';
}
# Set up hash of environment variables to set
$env_hash{'OCTEON_MODEL'} = $octeon_model;
$env_hash{'OCTEON_ROOT'} = $octeon_root;
if (!($PATH=~ /^$extra_path/))
{
$env_hash{'PATH'} = $extra_path.':$PATH';
warn "Updating PATH, adding $extra_path to beginning.\n" if ($verbose);
}
else
{
warn "Not updating PATH - OCTEON SDK dirs already present.\n" if ($verbose);
}
# Clear the the env variable if not needed
if ($runtime_model_flag)
{
$env_hash{'OCTEON_CPPFLAGS_GLOBAL_ADD'} = '-DUSE_RUNTIME_MODEL_CHECKS=1';
}
else
{
push(@env_clear, 'OCTEON_CPPFLAGS_GLOBAL_ADD');
}
#print out what we are doing
if ($verbose)
{
foreach $key (keys(%env_hash))
{
warn "Setting $key to ".'"'."$env_hash{$key}".'"'."\n";
}
if (@env_clear)
{
foreach $key (@env_clear)
{
warn "Unsetting $key\n";
}
}
}
# Generate environment setting command based on shell
my $env_cmd;
if ($shell =~ /csh$/) # csh and tcsh
{
foreach $key (keys(%env_hash))
{
$env_cmd .= "setenv $key ".'"'."$env_hash{$key}".'"'.';';
}
if (@env_clear)
{
foreach $key (@env_clear)
{
$env_cmd .= ";unsetenv $key ";
}
}
$env_cmd .= "\n";
warn "CSH command: $env_cmd\n" if ($verbose);
print $env_cmd;
}
elsif ($shell =~ /bash$/ || $shell =~ /ksh$/ || $shell =~ /sh$/)
{
$env_cmd = 'export ';
foreach $key (keys(%env_hash))
{
$env_cmd .= "$key=".'"'."$env_hash{$key}".'"'.' ';
}
if (@env_clear)
{
$env_cmd .= ";export ";
foreach $key (@env_clear)
{
$env_cmd .= "-n $key ";
}
}
$env_cmd .= "\n";
warn "BASH command: $env_cmd\n" if ($verbose);
print $env_cmd;
}
else
{
print "echo Unsupported shell\n";
}