#!/usr/bin/perl #//%LICENSE//////////////////////////////////////////////////////////////// #// #// Licensed to The Open Group (TOG) under one or more contributor license #// agreements. Refer to the OpenPegasusNOTICE.txt file distributed with #// this work for additional information regarding copyright ownership. #// Each contributor licenses this file to you under the OpenPegasus Open #// Source License; you may not use this file except in compliance with the #// License. #// #// 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 = ; 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]: "; $_ = ; 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,"[]: "; $_ = ; chomp($_); $component_value{$c}=$_; } if ($define_type_hash{$c} =~ /path/) { do { print $c, "[/usr/include/]: "; $_ = ; 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 "="; } if ($define_type_hash{$c} =~ /flag/i) { print "="; } 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 # We need to extract the and to # argument_list with as key and # 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 () { # 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) { # if ($depend_on_hash{$component} eq ""){ $depend_on_hash{$component}=$token; #print "(",$token,")"; } } } elsif ($state == 3) { #--enable- 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); }