-
Notifications
You must be signed in to change notification settings - Fork 1
/
SetConfig_EnvVar
executable file
·464 lines (423 loc) · 11.8 KB
/
SetConfig_EnvVar
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
#!/usr/bin/perl
#//%2005////////////////////////////////////////////////////////////////////////
#//
#// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
#// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
#// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
#// IBM Corp.; EMC Corporation, The Open Group.
#// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
#// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
#// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
#// EMC Corporation; VERITAS Software Corporation; The Open Group.
#//
#// Permission is hereby granted, free of charge, to any person obtaining a copy
#// of this software and associated documentation files (the "Software"), to
#// deal in the Software without restriction, including without limitation the
#// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
#// sell copies of the Software, and to permit persons to whom the Software is
#// furnished to do so, subject to the following conditions:
#//
#// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
#// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
#// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
#// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
#// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
#// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
#// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
#// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#//
#//==============================================================================
use strict;
#use warnings;
my $HELP_FILE = "SetConfig_EnvVar.help";
my $STATUS_FILE = "env_var.status";
my $PC_FILE = "pegasus.pc";
my %component_hash = ();
my %component_value=();
my %define_type_hash=();
my %depend_on_hash=();
my %enable_component_hash=();
my %short_descr_hash=();
my %long_descr_hash=();
my %argument_list=();
# Load up the info
&parse_help_file();
# Check for any arguments
&parse_arguments();
# Check the OS?
&determine_platform();
# Check the source path
&determine_source_path();
# Check arguments (if they have a path)
&check_arguments();
# Start asking the user the questions.
&ask_user();
# Print out all the options.
&write_out_status($STATUS_FILE);
# Create the .pc file for PKG-CONFIG
&write_out_pkg($PC_FILE);
# Write out extra info.
&extra_info();
sub determine_source_path()
{
my $source_dir = $ENV{PWD};
if (-r "$source_dir/$0")
{
$component_value{"PEGASUS_ROOT"} = $source_dir;
}
}
sub which () {
my $execname = shift;
for (map {"$_/$execname"} split(/:/, $ENV{PATH}))
{
return $_ if (-e and -x);
}
}
sub determine_platform() {
my $uname="";
my $platform = "";
open UNAME,"uname -ms|" or die$!;
$uname = <UNAME>;
close UNAME;
#'uname -ms' for IA-64: "HP-UX ia64"
#'uname -ms' for PA-RISC: "HP-UX 9000/871"
#'uname -ms' for Sun Solaris: "SunOS sun4u"
#'uname -ms' for PPC64 Linux: "Linux ppc64"
#'uname -ms' for I64 Linux: "Linux ia64"
#'iname -ms' for PPC Linux: "Linux ppc"
#'uname -ms' for AMD64 Linux: "Linux x86_64"
if ($uname =~ /SunOS/)
{
$platform = "SOLARIS_SPARC_CC";
if (&which("gcc") =~ /gcc/)
{
$platform = "SOLARIS_SPARC_GNU";
}
}
if ($uname =~ /Linux/)
{
# Default value
$platform = "LINUX_IX86_GNU";
if ($uname =~ /ppc/i)
{
$platform = "LINUX_PPC_GNU";
}
if ($uname =~ /ia64/i)
{
$platform = "LINUX_IA64_GNU";
}
}
if ($uname =~ /AIX/)
{
$platform ="AIX_RS_IBMCXX";
}
if ($uname =~ /HP-UX/)
{
$platform = "HPUX_ACC";
if ($uname =~ /ia64/i)
{
$platform = "HPUX_IA64_ACC";
}
if ($uname =~ /9000/)
{
$platform = "HPUX_PARISC_ACC";
}
}
$component_value{"PEGASUS_PLATFORM"} = $platform;
}
sub extra_info() {
print "\n\n";
print "=================================================\n";
print "All your build options have been saved in ",$STATUS_FILE,"\n";
print "If you need to modify anything, please do so now.\n";
print "\nNOTE:\n";
print "The PATH enviroment variables needs to be modified\n";
print "to have",$component_value{"PEGASUS_HOME"},"/bin\n";
print "if you wish to run the unit tests.\n";
print "\n";
print "You might also need to set this enviroment variable\n";
print "PEGASUS_ROOT=",$component_value{"PEGASUS_ROOT"},"\n";
print "\n\nLastly, to compile OpenPegasus, type make\n";
print "=================================================\n";
}
sub write_out_pkg() {
}
sub write_out_status() {
my $output = shift;
my $c="";
open OUTPUT, ">$output" or die $!;
foreach $c (sort keys(%component_value))
{
print OUTPUT ("# ", $short_descr_hash{$c},"\n");
if ($component_value{$c} eq "No")
{
print OUTPUT ("# ",$c,"=",$component_value{$c},"\n");
}
else
{
print OUTPUT ($c,"=",$component_value{$c},"\n");
}
}
close OUTPUT;
}
sub ask_user() {
my $c="";
my $d="";
my $component_that_has_depend="";
my $loop_question=0;
my $pass=0;
my $skip=0;
my $search_for_dependants=0;
foreach $pass (0..1) {
if ($pass == 0) {
print "=================================================\n";
print "All your build options will be saved in ",$STATUS_FILE," file.\n";
print "If you need to modify anything, you can do it after this program finishes..\n";
print "=================================================\n";
}
foreach $c (sort keys(%component_hash))
{
# check in the $argument_list to see if this option
# has been passed in. But do it only on the first
# pass
if ($pass == 0) {
foreach $d (sort keys(%argument_list))
{
if ($d eq $enable_component_hash{$c})
{
print $c," is set\n";
$component_value{$c}="Yes";
next;
}
}
}
$skip = 0;
# Does this build option have a dependency?
if (!$depend_on_hash{$c} eq "" )
{
# Yes. Has the dependency been set?
if ($component_value{$depend_on_hash{$c}} eq "")
{
# It has not been set. Skip this pass.
#print "Skip, this build option - ",$c," is dependent (",$depend_on_hash{$c},")\n";
$skip =1;
}
}
# if this is the second pass, ignore the flag options.
if ($pass != 0)
{
if ($define_type_hash{$c} =~ /flag/)
{
$skip =1;
}
}
if (($component_value{$c} eq "") && ($skip == 0)) {
# Ask the user.
print "\n--------------------\n";
print $long_descr_hash{$c},"\n";
$loop_question=1;
$search_for_dependants=0;
if ($define_type_hash{$c} =~ /boolean/)
{
do
{
print $c," [Y/n]: ";
$_ = <STDIN>;
if (/^y/i)
{
$component_value{$c}="Yes";
# There are build options that are 'disable.' Meaning that 'yes'
# sets all of the dependents to 'Yes' as well.
$loop_question=0;
if ($c =~ /PEGASUS_DISABLE/i)
{
$search_for_dependants=1;
}
}
if (/^n/i)
{
# Maybe ask the user again?
$loop_question=0;
$component_value{$c}="No";
# If the answer is No and it is a disable option, don't search
# the dependatns. Why? B/c the user might want to disable some
# more fine-grained options.
if ($c =~ /PEGASUS_DISABLE/i)
{
$search_for_dependants=0;
} else
{
$search_for_dependants=1;
}
}
if ($search_for_dependants==1) {
#print "Search for dependants of ",$c,"\n";
# Traverse through all the components to invalidate (set to No)
# the dependants.
foreach $component_that_has_depend (keys(%depend_on_hash))
{
# Filter out all of those build options that do not have any dependents.
if (!$depend_on_hash{$component_that_has_depend} eq "")
{
#print " ",$depend_on_hash{$component_that_has_depend}," ? ",$c,"\n";
# Does the dependant build option equal to the we are searching for?
if ($depend_on_hash{$component_that_has_depend} eq $c) {
#print "Found: ",$component_that_has_depend," depends on ",$c,"\n"; }
$component_value{$component_that_has_depend}="No";
}
}
}
}
if ($loop_question==1)
{
print "Please entry Y or N.\n";
}
} while ($loop_question==1);
} # if type is boolean
if ($define_type_hash{$c} =~ /flag/)
{
print $c,"[]: ";
$_ = <STDIN>;
chomp($_);
$component_value{$c}=$_;
}
if ($define_type_hash{$c} =~ /path/)
{
do
{
print $c, "[/usr/include/]: ";
$_ = <STDIN>;
chomp($_);
# Is the directory readable?
if (-r $_)
{
$loop_question=0;
$component_value{$c}=$_;
}
else
{
print "Path is not accessible. Please enter again.\n";
}
} while ($loop_question==1);
}
} # componet_value eq "";
}
}
}
sub check_arguments() {
my $c="";
foreach $c (sort keys(%argument_list))
{
if ($argument_list{$c} eq "") {
#print $c,"is not a PATH\n";
}
else
{
# Check the path
if (!(-r $argument_list{$c}))
{
print $c,"=",$argument_list{$c}," path cannot be accessed.\n"
}
}
}
}
sub print_help() {
my $c="";
print "Usage: ",$0," [OPTION]...\n";
print "\nArguments:\n";
foreach $c (sort keys(%component_hash)) {
print " ",$enable_component_hash{$c};
if ($define_type_hash{$c} =~ /path/i)
{
print "=<directory>";
}
if ($define_type_hash{$c} =~ /flag/i)
{
print "=<flag>";
}
print "\t\t";
print $short_descr_hash{$c},"\n"
}
}
sub parse_arguments {
my $argnum = 0;
my @temp = ();
foreach $argnum (0..$#ARGV) {
if (lc($ARGV[$argnum]) =~ /--help/i) {
&print_help();
exit (0);
}
if ($ARGV[$argnum] =~ /--/) {
# Two types:
# --<text>=<path>
# --text
# We need to extract the <text> and <path> to
# argument_list with <text> as key and
# <path> as value.
@temp = split(/=/, $ARGV[$argnum]);
$argument_list{$temp[0]}=$temp[1];
}
}
}
sub parse_help_file {
my $component = "";
my $token = "";
my @tokens = {};
my $state = 1;
open HELP_FILE, "$HELP_FILE" or die$!;
while (<HELP_FILE>) {
# Find component.
if (/[\d\w_]+[\s]?{/) {
s/[\s{]*//g;
$component_hash{$_}=$_;
$component=$_;
$depend_on_hash{$component} = "";
$long_descr_hash{$component} = "";
$state = 1;
}
if (/,/ || /}/) {
#remove the offending }
s/}//;
#remove any spaces in front of the string
s/\s//;
#get the tokens seperated by ,
@tokens=split (/,/,$_);
foreach $token (@tokens) {
# print "[",$state," ",$token, "]";
if ($state == 1) {
#<depend or (Boolean or Path)
#new option: flag
# check for boolean or Path
if (lc($token) =~ /boolean/ || /path/i || /flag/i){
#print "(",$token,")";
$define_type_hash{$component}=lc($token);
$state = 3;
}
else {
# check for "OPENSSL_HOME:<component>
if ($depend_on_hash{$component} eq ""){
$depend_on_hash{$component}=$token;
#print "(",$token,")";
}
}
}
elsif ($state == 3) { #--enable-<component>
if ($token =~ /--/) {
$enable_component_hash{$component}=$token;
$state =4;
}
}
elsif ($state == 4) {#short_desc
if (!($token =~ /\n/)) {
$short_descr_hash{$component}=$token;
$state=5;
}
}
elsif ($state == 5) {#long descr
$long_descr_hash{$component}=$long_descr_hash{$component}." ".$token;
}
} # foreach token
} #if /,/ or /}/
}
close (HELP_FILE);
}