-
Notifications
You must be signed in to change notification settings - Fork 21
/
env-setup.pl
executable file
·216 lines (187 loc) · 5.15 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/usr/bin/perl
use strict;
use Getopt::Long;
use Cwd;
use Env qw(PATH __OCTEON_SHELL_TEST__);
# Determine if we should use setenv or export for variables.
# The shell name that is passed as an argument is unreliable,
# sometimes just contains '-su'
my $use_setenv = 0;
$use_setenv = 1 if ($__OCTEON_SHELL_TEST__ == 2);
# 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 = 1;
my $verbose = 0;
my $enable_checks_flag = 0;
my $little_endian_flag = 0;
my $liquidio_flag = 0;
GetOptions("runtime-model!" => \$runtime_model_flag,
"verbose!" => \$verbose,
"checks!" => \$enable_checks_flag,
"little-endian!" => \$little_endian_flag,
"liquidio!" => \$liquidio_flag,
);
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] [--checks] ...\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 " Default is --runtime-model.\n";
warn " --checks: Enables various consistancy and programming checks in CVMX.\n";
warn " Use --nochecks to clear environment variable if desired.\n";
warn " Default is --nochecks.\n";
warn " --little-endian: Uses little endian toolchain for building applications.\n";
warn " --verbose: Be verbose about what the script is doing\n";
warn " Default is --noverbose.\n";
warn "\n";
warn "The env-setup script must be invoked from the root directory of the SDK install,\n";
warn "as it sets OCTEON_ROOT to be the directory that it is invoked in.\n";
warn "\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/tools-le/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 \"`column $octeon_root/octeon-models.txt`\"";
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);
}
my $global_add = "";
if ($runtime_model_flag)
{
$global_add .= ' -DUSE_RUNTIME_MODEL_CHECKS=1';
}
if ($enable_checks_flag)
{
$global_add .= ' -DCVMX_ENABLE_PARAMETER_CHECKING=1 -DCVMX_ENABLE_CSR_ADDRESS_CHECKING=1 -DCVMX_ENABLE_POW_CHECKS=1';
}
else
{
$global_add .= ' -DCVMX_ENABLE_PARAMETER_CHECKING=0 -DCVMX_ENABLE_CSR_ADDRESS_CHECKING=0 -DCVMX_ENABLE_POW_CHECKS=0';
}
if ($global_add)
{
$env_hash{'OCTEON_CPPFLAGS_GLOBAL_ADD'} = $global_add;
}
else
{
push(@env_clear, 'OCTEON_CPPFLAGS_GLOBAL_ADD');
}
if ($little_endian_flag)
{
$env_hash{'OCTEON_LE'} = $little_endian_flag;
}
else
{
push(@env_clear, 'OCTEON_LE');
}
if ($liquidio_flag)
{
$env_hash{'OCTEON_LIQUIDIO'} = 1
}
else
{
push(@env_clear, 'OCTEON_LIQUIDIO');
}
#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 ($use_setenv) # 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;
}
else
{
$env_cmd = 'export ';
foreach $key (keys(%env_hash))
{
$env_cmd .= "$key=".'"'."$env_hash{$key}".'"'.' ';
}
if (@env_clear)
{
$env_cmd .= ";export ";
foreach $key (@env_clear)
{
# ksh doesn't support -n, so we just clear the variable
$env_cmd .= "$key= ";
}
}
$env_cmd .= "\n";
warn "SH command: $env_cmd\n" if ($verbose);
print $env_cmd;
}