2 #//%2006////////////////////////////////////////////////////////////////////////
4 #// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
5 #// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
6 #// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
7 #// IBM Corp.; EMC Corporation, The Open Group.
8 #// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
9 #// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
10 #// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
11 #// EMC Corporation; VERITAS Software Corporation; The Open Group.
12 #// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
13 #// EMC Corporation; Symantec Corporation; The Open Group.
15 #// Permission is hereby granted, free of charge, to any person obtaining a copy
16 #// of this software and associated documentation files (the "Software"), to
17 #// deal in the Software without restriction, including without limitation the
18 #// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
19 #// sell copies of the Software, and to permit persons to whom the Software is
20 #// furnished to do so, subject to the following conditions:
22 #// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
23 #// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
24 #// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
25 #// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
26 #// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27 #// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 #// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 #// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 #//================================================================================
34 my $HELP_FILE = "SetConfig_EnvVar.help";
35 my $STATUS_FILE = "env_var.status";
36 my $PC_FILE = "pegasus.pc";
38 my %component_hash = ();
39 my %component_value=();
40 my %define_type_hash=();
41 my %depend_on_hash=();
42 my %enable_component_hash=();
43 my %short_descr_hash=();
44 my %long_descr_hash=();
49 # Check for any arguments
52 &determine_platform();
53 # Check the source path
54 &determine_source_path();
55 # Check arguments (if they have a path)
57 # Start asking the user the questions.
59 # Print out all the options.
60 &write_out_status($STATUS_FILE);
61 # Create the .pc file for PKG-CONFIG
62 &write_out_pkg($PC_FILE);
63 # Write out extra info.
66 sub determine_source_path()
68 my $source_dir = $ENV{PWD};
69 if (-r "$source_dir/$0")
71 $component_value{"PEGASUS_ROOT"} = $source_dir;
78 for (map {"$_/$execname"} split(/:/, $ENV{PATH}))
80 return $_ if (-e and -x);
83 sub determine_platform() {
87 open UNAME,"uname -ms|" or die$!;
91 #'uname -ms' for IA-64: "HP-UX ia64"
92 #'uname -ms' for PA-RISC: "HP-UX 9000/871"
93 #'uname -ms' for Sun Solaris: "SunOS sun4u"
94 #'uname -ms' for PPC64 Linux: "Linux ppc64"
95 #'uname -ms' for I64 Linux: "Linux ia64"
96 #'iname -ms' for PPC Linux: "Linux ppc"
97 #'uname -ms' for AMD64 Linux: "Linux x86_64"
99 if ($uname =~ /SunOS/)
101 $platform = "SOLARIS_SPARC_CC";
102 if (&which("gcc") =~ /gcc/)
104 $platform = "SOLARIS_SPARC_GNU";
107 if ($uname =~ /Linux/)
110 $platform = "LINUX_IX86_GNU";
111 if ($uname =~ /ppc/i)
113 $platform = "LINUX_PPC_GNU";
116 if ($uname =~ /ia64/i)
118 $platform = "LINUX_IA64_GNU";
123 $platform ="AIX_RS_IBMCXX";
125 if ($uname =~ /HP-UX/)
127 $platform = "HPUX_ACC";
128 if ($uname =~ /ia64/i)
130 $platform = "HPUX_IA64_ACC";
132 if ($uname =~ /9000/)
134 $platform = "HPUX_PARISC_ACC";
137 $component_value{"PEGASUS_PLATFORM"} = $platform;
143 print "=================================================\n";
144 print "All your build options have been saved in ",$STATUS_FILE,"\n";
145 print "If you need to modify anything, please do so now.\n";
147 print "The PATH enviroment variables needs to be modified\n";
148 print "to have",$component_value{"PEGASUS_HOME"},"/bin\n";
149 print "if you wish to run the unit tests.\n";
151 print "You might also need to set this enviroment variable\n";
152 print "PEGASUS_ROOT=",$component_value{"PEGASUS_ROOT"},"\n";
153 print "\n\nLastly, to compile OpenPegasus, type make\n";
154 print "=================================================\n";
157 sub write_out_pkg() {
160 sub write_out_status() {
164 open OUTPUT, ">$output" or die $!;
166 foreach $c (sort keys(%component_value))
168 print OUTPUT ("# ", $short_descr_hash{$c},"\n");
169 if ($component_value{$c} eq "No")
171 print OUTPUT ("# ",$c,"=",$component_value{$c},"\n");
175 print OUTPUT ($c,"=",$component_value{$c},"\n");
185 my $component_that_has_depend="";
189 my $search_for_dependants=0;
191 foreach $pass (0..1) {
193 print "=================================================\n";
194 print "All your build options will be saved in ",$STATUS_FILE," file.\n";
195 print "If you need to modify anything, you can do it after this program finishes..\n";
196 print "=================================================\n";
198 foreach $c (sort keys(%component_hash))
201 # check in the $argument_list to see if this option
202 # has been passed in. But do it only on the first
205 foreach $d (sort keys(%argument_list))
207 if ($d eq $enable_component_hash{$c})
209 print $c," is set\n";
210 $component_value{$c}="Yes";
216 # Does this build option have a dependency?
217 if (!$depend_on_hash{$c} eq "" )
219 # Yes. Has the dependency been set?
220 if ($component_value{$depend_on_hash{$c}} eq "")
222 # It has not been set. Skip this pass.
223 #print "Skip, this build option - ",$c," is dependent (",$depend_on_hash{$c},")\n";
227 # if this is the second pass, ignore the flag options.
230 if ($define_type_hash{$c} =~ /flag/)
235 if (($component_value{$c} eq "") && ($skip == 0)) {
237 print "\n--------------------\n";
238 print $long_descr_hash{$c},"\n";
240 $search_for_dependants=0;
241 if ($define_type_hash{$c} =~ /boolean/)
249 $component_value{$c}="Yes";
250 # There are build options that are 'disable.' Meaning that 'yes'
251 # sets all of the dependents to 'Yes' as well.
253 if ($c =~ /PEGASUS_DISABLE/i)
255 $search_for_dependants=1;
260 # Maybe ask the user again?
262 $component_value{$c}="No";
263 # If the answer is No and it is a disable option, don't search
264 # the dependatns. Why? B/c the user might want to disable some
265 # more fine-grained options.
266 if ($c =~ /PEGASUS_DISABLE/i)
268 $search_for_dependants=0;
271 $search_for_dependants=1;
274 if ($search_for_dependants==1) {
275 #print "Search for dependants of ",$c,"\n";
276 # Traverse through all the components to invalidate (set to No)
278 foreach $component_that_has_depend (keys(%depend_on_hash))
280 # Filter out all of those build options that do not have any dependents.
281 if (!$depend_on_hash{$component_that_has_depend} eq "")
283 #print " ",$depend_on_hash{$component_that_has_depend}," ? ",$c,"\n";
284 # Does the dependant build option equal to the we are searching for?
285 if ($depend_on_hash{$component_that_has_depend} eq $c) {
286 #print "Found: ",$component_that_has_depend," depends on ",$c,"\n"; }
287 $component_value{$component_that_has_depend}="No";
292 if ($loop_question==1)
294 print "Please entry Y or N.\n";
296 } while ($loop_question==1);
298 } # if type is boolean
300 if ($define_type_hash{$c} =~ /flag/)
305 $component_value{$c}=$_;
307 if ($define_type_hash{$c} =~ /path/)
311 print $c, "[/usr/include/]: ";
314 # Is the directory readable?
318 $component_value{$c}=$_;
322 print "Path is not accessible. Please enter again.\n";
324 } while ($loop_question==1);
327 } # componet_value eq "";
332 sub check_arguments() {
335 foreach $c (sort keys(%argument_list))
337 if ($argument_list{$c} eq "") {
338 #print $c,"is not a PATH\n";
343 if (!(-r $argument_list{$c}))
345 print $c,"=",$argument_list{$c}," path cannot be accessed.\n"
355 print "Usage: ",$0," [OPTION]...\n";
356 print "\nArguments:\n";
358 foreach $c (sort keys(%component_hash)) {
359 print " ",$enable_component_hash{$c};
360 if ($define_type_hash{$c} =~ /path/i)
362 print "=<directory>";
364 if ($define_type_hash{$c} =~ /flag/i)
369 print $short_descr_hash{$c},"\n"
373 sub parse_arguments {
377 foreach $argnum (0..$#ARGV) {
379 if (lc($ARGV[$argnum]) =~ /--help/i) {
383 if ($ARGV[$argnum] =~ /--/) {
387 # We need to extract the <text> and <path> to
388 # argument_list with <text> as key and
390 @temp = split(/=/, $ARGV[$argnum]);
391 $argument_list{$temp[0]}=$temp[1];
396 sub parse_help_file {
402 open HELP_FILE, "$HELP_FILE" or die$!;
404 while (<HELP_FILE>) {
406 if (/[\d\w_]+[\s]?{/) {
408 $component_hash{$_}=$_;
410 $depend_on_hash{$component} = "";
411 $long_descr_hash{$component} = "";
415 #remove the offending }
417 #remove any spaces in front of the string
419 #get the tokens seperated by ,
420 @tokens=split (/,/,$_);
421 foreach $token (@tokens) {
422 # print "[",$state," ",$token, "]";
425 #<depend or (Boolean or Path)
427 # check for boolean or Path
428 if (lc($token) =~ /boolean/ || /path/i || /flag/i){
429 #print "(",$token,")";
430 $define_type_hash{$component}=lc($token);
434 # check for "OPENSSL_HOME:<component>
435 if ($depend_on_hash{$component} eq ""){
436 $depend_on_hash{$component}=$token;
437 #print "(",$token,")";
442 elsif ($state == 3) { #--enable-<component>
444 if ($token =~ /--/) {
445 $enable_component_hash{$component}=$token;
449 elsif ($state == 4) {#short_desc
451 if (!($token =~ /\n/)) {
452 $short_descr_hash{$component}=$token;
456 elsif ($state == 5) {#long descr
458 $long_descr_hash{$component}=$long_descr_hash{$component}." ".$token;