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

File: [Pegasus] / pegasus / Attic / SetConfig_EnvVar (download)
Revision: 1.1, Wed Jul 28 15:32:36 2004 UTC (19 years, 9 months ago) by konrad.r
Branch: MAIN
CVS Tags: pegasus25BeforeLicenseUpdate, SLPPERFINST-root, SLPPERFINST-branch, RELEASE_2_4_3, RELEASE_2_4_2, RELEASE_2_4_1-BETA3, RELEASE_2_4_1-BETA2, RELEASE_2_4_1-BETA1, RELEASE_2_4_1, RELEASE_2_4_0-RC3, RELEASE_2_4_0-RC2, RELEASE_2_4_0, RELEASE_2_4-root, RELEASE_2_4-branch, PEP217_PRE_BRANCH, PEP217_POST_BRANCH, PEP217_BRANCH, PEP214ROOT, PEP214BRANCH, PEP214-root, PEP214-branch, PEP213_SIZE_OPTIMIZATIONS, PEP-214B-root, PEG25_IBM_5_16_05, IBM_241_April1405, CQL_2_5_BRANCH, CHUNKTESTDONE_PEP140
PEP#: 182
TITLE:  Configuration script enhancement

DESCRIPTION:
Adding new files.

#!/usr/bin/perl

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 "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";

}
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");
      print OUTPUT ($c,"=",$component_value{$c},"\n");
    }
  close OUTPUT;
  
}
sub ask_user() {

  my $c="";
  my $d="";

  my $loop_question=0;
  foreach $c (sort keys(%component_hash))
    {
      
      # check in the $argument_list to see if this option
      # has been passed in.
      foreach $d (sort keys(%argument_list))
	{	 
	  if ($d eq $enable_component_hash{$c})
	    {
	      #print $c," is set\n";
	      $component_value{$c}="Yes";
	      next;
	    }
	}
      if ($component_value{$c} eq "") {
	# Ask the user.
	print "\n--------------------\n";
	print $long_descr_hash{$c},"\n";
	$loop_question=1;
	if ($define_type_hash{$c} eq "boolean")
	  {
	    do
	      {
		print $c," [Y/n]: ";
		$_ = <STDIN>;
		if (/^y/i)
		  {
		    $component_value{$c}="Yes";
		    $loop_question=0;		    
		  }
		if (/^n/i)
		  {
		    # Maybe ask the user again?
		    $loop_question=0;
		  }
		if ($loop_question==1) 
		  {
		    print "Please entry Y or N.\n";
		  }
		} while ($loop_question==1);

	  }
	if ($define_type_hash{$c} eq "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/) 
	{
		print "=<directory>";
	}
	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/) {
      &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)
		  # check for boolean or Path
		   if (lc($token) =~ /boolean/ || /path/){
			#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);
}

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2