(file) Return to SetConfig_EnvVar CVS log (file) (dir) Up to [Pegasus] / pegasus

  1 konrad.r 1.1 #!/usr/bin/perl
  2 martin   1.5 #//%LICENSE////////////////////////////////////////////////////////////////
  3 marek    1.4 #// 
  4 martin   1.5 #// Licensed to The Open Group (TOG) under one or more contributor license
  5              #// agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  6              #// this work for additional information regarding copyright ownership.
  7              #// Each contributor licenses this file to you under the OpenPegasus Open
  8              #// Source License; you may not use this file except in compliance with the
  9              #// License.
 10              #// 
 11              #// Permission is hereby granted, free of charge, to any person obtaining a
 12              #// copy of this software and associated documentation files (the "Software"),
 13              #// to deal in the Software without restriction, including without limitation
 14              #// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 15              #// and/or sell copies of the Software, and to permit persons to whom the
 16              #// Software is furnished to do so, subject to the following conditions:
 17              #// 
 18              #// The above copyright notice and this permission notice shall be included
 19              #// in all copies or substantial portions of the Software.
 20              #// 
 21              #// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 22              #// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
 23              #// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 24              #// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 25 martin   1.5 #// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 26              #// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 27              #// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 28              #// 
 29              #//////////////////////////////////////////////////////////////////////////
 30 konrad.r 1.1 use strict;
 31              #use warnings;
 32              my $HELP_FILE = "SetConfig_EnvVar.help";
 33              my $STATUS_FILE = "env_var.status";
 34              my $PC_FILE = "pegasus.pc";
 35              
 36              my %component_hash = ();
 37              my %component_value=();
 38              my %define_type_hash=();
 39              my %depend_on_hash=();
 40              my %enable_component_hash=();
 41              my %short_descr_hash=();
 42              my %long_descr_hash=();
 43              my %argument_list=();
 44              
 45              # Load up the info
 46              &parse_help_file();
 47              # Check for any arguments
 48              &parse_arguments();
 49              # Check the OS?
 50              &determine_platform();
 51 konrad.r 1.1 # Check the source path
 52              &determine_source_path();
 53              # Check arguments (if they have a path)
 54              &check_arguments();
 55              # Start asking the user the questions.
 56              &ask_user();
 57              # Print out all the options.
 58              &write_out_status($STATUS_FILE);
 59              # Create the .pc file for PKG-CONFIG
 60              &write_out_pkg($PC_FILE);
 61              # Write out extra info.
 62              &extra_info();
 63              
 64              sub determine_source_path()
 65                {
 66                  my $source_dir = $ENV{PWD};
 67                  if (-r "$source_dir/$0")
 68              	{
 69                  	$component_value{"PEGASUS_ROOT"} = $source_dir;
 70              	}
 71                
 72 konrad.r 1.1   }
 73              sub which () {
 74              
 75                my $execname = shift;
 76                for (map {"$_/$execname"} split(/:/, $ENV{PATH}))
 77                  {
 78                    return $_ if (-e and -x);
 79                  }
 80              }
 81              sub determine_platform() {
 82              
 83                 my $uname="";
 84                 my $platform = "";
 85                 open UNAME,"uname -ms|" or die$!;
 86                 $uname = <UNAME>;
 87                 close UNAME;
 88              
 89              #'uname -ms' for IA-64: "HP-UX ia64"
 90              #'uname -ms' for PA-RISC: "HP-UX 9000/871"
 91              #'uname -ms' for Sun Solaris: "SunOS sun4u"
 92              #'uname -ms' for PPC64 Linux: "Linux ppc64"
 93 konrad.r 1.1 #'uname -ms' for I64 Linux: "Linux ia64"
 94              #'iname -ms' for PPC Linux: "Linux ppc"
 95              #'uname -ms' for AMD64 Linux: "Linux x86_64"
 96              
 97                 if ($uname =~ /SunOS/)
 98              	{
 99              	  $platform = "SOLARIS_SPARC_CC";
100              	  if (&which("gcc") =~ /gcc/)
101              	    {
102              	      $platform = "SOLARIS_SPARC_GNU";
103              	    }
104              	}
105                 if ($uname =~ /Linux/) 
106                   {
107                     # Default value
108                     $platform = "LINUX_IX86_GNU";
109                     if ($uname =~ /ppc/i)
110              	 {
111              	   $platform = "LINUX_PPC_GNU";
112              	 }
113                     
114 konrad.r 1.1        if ($uname =~ /ia64/i)
115              	 {
116              	   $platform = "LINUX_IA64_GNU";
117              	 }
118                   }
119                 if ($uname =~ /AIX/)
120              	{
121              	  $platform ="AIX_RS_IBMCXX";
122              	}
123                 if ($uname =~ /HP-UX/)
124              	{
125              	  $platform = "HPUX_ACC";
126              	  if ($uname =~ /ia64/i)
127              	    {
128              	      $platform = "HPUX_IA64_ACC";
129              	    }
130              	  if ($uname =~ /9000/)
131              	    {
132              	      $platform = "HPUX_PARISC_ACC";
133              	    }
134              	}
135 konrad.r 1.1    $component_value{"PEGASUS_PLATFORM"} = $platform;
136               }
137              
138              sub extra_info() {
139              
140                print "\n\n";
141                print "=================================================\n";
142 konrad.r 1.2   print "All your build options have been saved in ",$STATUS_FILE,"\n";
143                print "If you need to modify anything, please do so now.\n";
144                print "\nNOTE:\n";
145 konrad.r 1.1   print "The PATH enviroment variables needs to be modified\n";
146                print "to have",$component_value{"PEGASUS_HOME"},"/bin\n";
147                print "if you wish to run the unit tests.\n";
148                print "\n";
149                print "You might also need to set this enviroment variable\n";
150                print "PEGASUS_ROOT=",$component_value{"PEGASUS_ROOT"},"\n";
151 konrad.r 1.2   print "\n\nLastly, to compile OpenPegasus, type make\n";
152 konrad.r 1.1   print "=================================================\n";
153              
154              }
155              sub write_out_pkg() {
156              
157              }
158              sub write_out_status() {
159                
160                my $output = shift;
161                my $c="";
162                open OUTPUT, ">$output" or die $!;
163              
164                foreach $c (sort keys(%component_value))
165                  {
166                    print OUTPUT ("# ", $short_descr_hash{$c},"\n");
167 konrad.r 1.2 	  if ($component_value{$c} eq "No")
168              		{
169                    	print OUTPUT ("# ",$c,"=",$component_value{$c},"\n");
170              		}
171              	  else
172              		{
173                    	print OUTPUT ($c,"=",$component_value{$c},"\n");
174              		}
175 konrad.r 1.1     }
176                close OUTPUT;
177                
178              }
179              sub ask_user() {
180              
181                my $c="";
182                my $d="";
183 konrad.r 1.2   my $component_that_has_depend="";
184 konrad.r 1.1   my $loop_question=0;
185 konrad.r 1.2   my $pass=0;
186                my $skip=0;
187                my $search_for_dependants=0;
188              
189                foreach $pass (0..1) {
190                   if ($pass == 0) { 
191                	  print "=================================================\n";
192                	  print "All your build options will be saved in ",$STATUS_FILE," file.\n";
193                	  print "If you need to modify anything, you can do it after this program finishes..\n";
194                	  print "=================================================\n";
195                  }
196                  foreach $c (sort keys(%component_hash))
197                    {
198              	
199              	# check in the $argument_list to see if this option
200              	# has been passed in. But do it only on the first
201              	# pass
202              	if ($pass == 0) {
203              	  foreach $d (sort keys(%argument_list))
204              	    {	 
205              	      if ($d eq $enable_component_hash{$c})
206 konrad.r 1.2 		{
207              		  print $c," is set\n";
208              		  $component_value{$c}="Yes";
209              		  next;
210              		}
211              	  }
212              	}
213              	$skip = 0;
214              	# Does this build option have a dependency?
215              	if (!$depend_on_hash{$c} eq "" ) 
216              	  {
217              	  # Yes. Has the dependency been set?
218              	  if ($component_value{$depend_on_hash{$c}} eq "")
219 konrad.r 1.1 	    {
220 konrad.r 1.2 	      # It has not been set. Skip this pass.
221              	      #print "Skip, this build option - ",$c," is dependent (",$depend_on_hash{$c},")\n";
222              	      $skip =1;
223 konrad.r 1.1 	    }
224              	}
225 konrad.r 1.2    # if this is the second pass, ignore the flag options.
226                  if ($pass != 0) 
227                  {
228              	  if ($define_type_hash{$c} =~ /flag/)
229                    {
230                      $skip =1;
231                    }
232                  }
233              	if (($component_value{$c} eq "") && ($skip == 0)) {
234              	  # Ask the user.
235              	  print "\n--------------------\n";
236              	  print $long_descr_hash{$c},"\n";
237              	  $loop_question=1;
238                    $search_for_dependants=0;
239              	  if ($define_type_hash{$c} =~ /boolean/)
240              	    {
241              	      do
242              		{
243              		  print $c," [Y/n]: ";
244              		  $_ = <STDIN>;
245              		  if (/^y/i)
246 konrad.r 1.2 		    {
247              		      $component_value{$c}="Yes";
248                            # There are build options that are 'disable.' Meaning that 'yes'
249                            # sets all of the dependents to 'Yes' as well.
250              		      $loop_question=0;		   
251                           if ($c =~ /PEGASUS_DISABLE/i)
252                           {
253                              $search_for_dependants=1;
254                           } 
255              		    }
256              		  if (/^n/i)
257              		    {
258              		      # Maybe ask the user again?
259              		      $loop_question=0;
260              		      $component_value{$c}="No";
261                            # If the answer is No and it is a disable option, don't search
262                            # the dependatns. Why? B/c the user might want to disable some
263                            # more fine-grained options.
264                            if ($c =~ /PEGASUS_DISABLE/i)
265                            {
266                              $search_for_dependants=0;
267 konrad.r 1.2 			  } else
268                            {
269                              $search_for_dependants=1;
270                            }
271                           }
272              	      if ($search_for_dependants==1) {
273                            #print "Search for dependants of ",$c,"\n";
274              		      # Traverse through all the components to invalidate (set to No)
275              		      # the dependants.
276              		      foreach $component_that_has_depend (keys(%depend_on_hash))
277              			{
278              			  # Filter out all of those build options that do not have any dependents.
279              			  if (!$depend_on_hash{$component_that_has_depend} eq "")
280              			    {
281              			      #print " ",$depend_on_hash{$component_that_has_depend}," ? ",$c,"\n";
282              			      # Does the dependant build option equal to the we are searching for?
283              			      if ($depend_on_hash{$component_that_has_depend} eq $c) {
284              				#print "Found: ",$component_that_has_depend," depends on ",$c,"\n"; }
285              				$component_value{$component_that_has_depend}="No";
286              			      }
287              			    }
288 konrad.r 1.2 			}
289              		    }
290              		      if ($loop_question==1) 
291              			{
292              			  print "Please entry Y or N.\n";
293              			}
294 konrad.r 1.1 		} while ($loop_question==1);
295              
296 konrad.r 1.2 	    } # if type is boolean
297              	  
298              	  if ($define_type_hash{$c} =~ /flag/)
299                     {
300                       print $c,"[]: ";
301                       $_ = <STDIN>;
302                       chomp($_);
303                       $component_value{$c}=$_; 
304                     }
305              	  if ($define_type_hash{$c} =~ /path/)
306              	    {
307              	      do
308              		{
309              		  print $c, "[/usr/include/]: ";
310              		  $_ = <STDIN>;
311              		  chomp($_);
312              		  # Is the directory readable?
313              		  if (-r $_)
314              		    {
315              		      $loop_question=0;
316              		      $component_value{$c}=$_;
317 konrad.r 1.2 		    }
318              		  else
319              		    {
320              		      print "Path is not accessible. Please enter again.\n";
321 konrad.r 1.1 		    }		
322              		} while ($loop_question==1);
323 konrad.r 1.2 	      
324              	    }
325              	} # componet_value eq "";
326                    }
327                }
328 konrad.r 1.1 }
329 konrad.r 1.2   
330 konrad.r 1.1 sub check_arguments() {
331 konrad.r 1.2     
332 konrad.r 1.1   my $c="";
333                foreach $c (sort keys(%argument_list))
334                  {
335                     if ($argument_list{$c} eq "") {
336              	#print $c,"is not a PATH\n";
337                    }
338                    else 
339              	{
340              	  # Check the path
341              	  if (!(-r $argument_list{$c}))
342              	    {
343              	      print $c,"=",$argument_list{$c}," path cannot be accessed.\n"
344              	   }
345              	}
346                   }
347              }
348              
349              sub print_help() {
350              
351                 my $c="";
352                 
353 konrad.r 1.1    print "Usage: ",$0," [OPTION]...\n";
354                 print "\nArguments:\n";
355              
356                 foreach $c (sort keys(%component_hash)) {
357              	print "   ",$enable_component_hash{$c};
358 konrad.r 1.2 	if ($define_type_hash{$c} =~ /path/i) 
359 konrad.r 1.1 	{
360              		print "=<directory>";
361              	}
362 konrad.r 1.2 	if ($define_type_hash{$c} =~ /flag/i) 
363              	{
364              		print "=<flag>";
365              	}
366 konrad.r 1.1 	print "\t\t";
367              	print $short_descr_hash{$c},"\n"
368                 }
369              }
370              
371              sub parse_arguments {
372              
373                my $argnum = 0;
374                my @temp = ();
375                foreach $argnum (0..$#ARGV) {
376                
377 konrad.r 1.2     if (lc($ARGV[$argnum]) =~ /--help/i) {
378 konrad.r 1.1       &print_help();
379                    exit (0);
380                  }
381                  if ($ARGV[$argnum] =~ /--/) {
382                    # Two types:
383                    # --<text>=<path>
384                    # --text
385                    # We need to extract the <text> and <path> to
386                    # argument_list with <text> as key and
387                    # <path> as value.
388                    @temp = split(/=/, $ARGV[$argnum]);
389                    $argument_list{$temp[0]}=$temp[1];
390                  }
391                }
392              
393              }
394              sub parse_help_file  {
395              
396                 my $component = "";
397                 my $token = "";
398                 my @tokens = {};
399 konrad.r 1.1    my $state = 1;
400                 open HELP_FILE, "$HELP_FILE" or die$!;
401              
402                 while (<HELP_FILE>) {
403              	# Find component.
404              	if (/[\d\w_]+[\s]?{/) {
405              		s/[\s{]*//g;
406              		$component_hash{$_}=$_;
407              		$component=$_;
408              		$depend_on_hash{$component} = "";
409              		$long_descr_hash{$component} = "";
410              		$state = 1;
411                      }
412              	if (/,/ || /}/) {
413              	  #remove the offending }
414              	   s/}//;
415              	  #remove any spaces in front of the string
416              	   s/\s//;
417              	  #get the tokens seperated by ,
418              	   @tokens=split (/,/,$_);
419              	   foreach $token (@tokens) {
420 konrad.r 1.1 #		print "[",$state," ",$token, "]";
421              
422              		if ($state == 1) { 
423              		  #<depend or (Boolean or Path)
424 konrad.r 1.2 		  #new option: flag
425 konrad.r 1.1 		  # check for boolean or Path
426 konrad.r 1.2 		   if (lc($token) =~ /boolean/ || /path/i || /flag/i){
427 konrad.r 1.1 			#print "(",$token,")";
428              			$define_type_hash{$component}=lc($token);
429              			$state = 3;
430              		    }
431              		    else {
432              		      # check for "OPENSSL_HOME:<component>
433              		      if ($depend_on_hash{$component} eq ""){
434              			$depend_on_hash{$component}=$token;
435              			#print "(",$token,")";
436              		      }
437              		    }
438              	         }
439              
440              		elsif ($state == 3) { #--enable-<component>
441              
442              		  if ($token =~ /--/) {
443              		    $enable_component_hash{$component}=$token;
444              		    $state =4;
445              		  }
446              		}
447              		elsif ($state == 4) {#short_desc
448 konrad.r 1.1 
449              		  if (!($token =~ /\n/)) {
450              		    $short_descr_hash{$component}=$token;
451              		    $state=5;
452              		  }
453              		}
454              		elsif ($state == 5) {#long descr
455              
456              		  $long_descr_hash{$component}=$long_descr_hash{$component}." ".$token;
457              		}
458              	      } # foreach token
459              	
460              	 } #if /,/ or /}/
461                    }
462                 close (HELP_FILE);
463              }
464 konrad.r 1.2 

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2