1 konrad.r 1.1 #!/usr/bin/perl
2
3 use strict;
4 #use warnings;
5 my $HELP_FILE = "SetConfig_EnvVar.help";
6 my $STATUS_FILE = "env_var.status";
7 my $PC_FILE = "pegasus.pc";
8
9 my %component_hash = ();
10 my %component_value=();
11 my %define_type_hash=();
12 my %depend_on_hash=();
13 my %enable_component_hash=();
14 my %short_descr_hash=();
15 my %long_descr_hash=();
16 my %argument_list=();
17
18 # Load up the info
19 &parse_help_file();
20 # Check for any arguments
21 &parse_arguments();
22 konrad.r 1.1 # Check the OS?
23 &determine_platform();
24 # Check the source path
25 &determine_source_path();
26 # Check arguments (if they have a path)
27 &check_arguments();
28 # Start asking the user the questions.
29 &ask_user();
30 # Print out all the options.
31 &write_out_status($STATUS_FILE);
32 # Create the .pc file for PKG-CONFIG
33 &write_out_pkg($PC_FILE);
34 # Write out extra info.
35 &extra_info();
36
37 sub determine_source_path()
38 {
39 my $source_dir = $ENV{PWD};
40 if (-r "$source_dir/$0")
41 {
42 $component_value{"PEGASUS_ROOT"} = $source_dir;
43 konrad.r 1.1 }
44
45 }
46 sub which () {
47
48 my $execname = shift;
49 for (map {"$_/$execname"} split(/:/, $ENV{PATH}))
50 {
51 return $_ if (-e and -x);
52 }
53 }
54 sub determine_platform() {
55
56 my $uname="";
57 my $platform = "";
58 open UNAME,"uname -ms|" or die$!;
59 $uname = <UNAME>;
60 close UNAME;
61
62 #'uname -ms' for IA-64: "HP-UX ia64"
63 #'uname -ms' for PA-RISC: "HP-UX 9000/871"
64 konrad.r 1.1 #'uname -ms' for Sun Solaris: "SunOS sun4u"
65 #'uname -ms' for PPC64 Linux: "Linux ppc64"
66 #'uname -ms' for I64 Linux: "Linux ia64"
67 #'iname -ms' for PPC Linux: "Linux ppc"
68 #'uname -ms' for AMD64 Linux: "Linux x86_64"
69
70 if ($uname =~ /SunOS/)
71 {
72 $platform = "SOLARIS_SPARC_CC";
73 if (&which("gcc") =~ /gcc/)
74 {
75 $platform = "SOLARIS_SPARC_GNU";
76 }
77 }
78 if ($uname =~ /Linux/)
79 {
80 # Default value
81 $platform = "LINUX_IX86_GNU";
82 if ($uname =~ /ppc/i)
83 {
84 $platform = "LINUX_PPC_GNU";
85 konrad.r 1.1 }
86
87 if ($uname =~ /ia64/i)
88 {
89 $platform = "LINUX_IA64_GNU";
90 }
91 }
92 if ($uname =~ /AIX/)
93 {
94 $platform ="AIX_RS_IBMCXX";
95 }
96 if ($uname =~ /HP-UX/)
97 {
98 $platform = "HPUX_ACC";
99 if ($uname =~ /ia64/i)
100 {
101 $platform = "HPUX_IA64_ACC";
102 }
103 if ($uname =~ /9000/)
104 {
105 $platform = "HPUX_PARISC_ACC";
106 konrad.r 1.1 }
107 }
108 $component_value{"PEGASUS_PLATFORM"} = $platform;
109 }
110
111 sub extra_info() {
112
113 print "\n\n";
114 print "=================================================\n";
115 print "The PATH enviroment variables needs to be modified\n";
116 print "to have",$component_value{"PEGASUS_HOME"},"/bin\n";
117 print "if you wish to run the unit tests.\n";
118 print "\n";
119 print "You might also need to set this enviroment variable\n";
120 print "PEGASUS_ROOT=",$component_value{"PEGASUS_ROOT"},"\n";
121 print "=================================================\n";
122
123 }
124 sub write_out_pkg() {
125
126 }
127 konrad.r 1.1 sub write_out_status() {
128
129 my $output = shift;
130 my $c="";
131 open OUTPUT, ">$output" or die $!;
132
133 foreach $c (sort keys(%component_value))
134 {
135 print OUTPUT ("# ", $short_descr_hash{$c},"\n");
136 print OUTPUT ($c,"=",$component_value{$c},"\n");
137 }
138 close OUTPUT;
139
140 }
141 sub ask_user() {
142
143 my $c="";
144 my $d="";
145
146 my $loop_question=0;
147 foreach $c (sort keys(%component_hash))
148 konrad.r 1.1 {
149
150 # check in the $argument_list to see if this option
151 # has been passed in.
152 foreach $d (sort keys(%argument_list))
153 {
154 if ($d eq $enable_component_hash{$c})
155 {
156 #print $c," is set\n";
157 $component_value{$c}="Yes";
158 next;
159 }
160 }
161 if ($component_value{$c} eq "") {
162 # Ask the user.
163 print "\n--------------------\n";
164 print $long_descr_hash{$c},"\n";
165 $loop_question=1;
166 if ($define_type_hash{$c} eq "boolean")
167 {
168 do
169 konrad.r 1.1 {
170 print $c," [Y/n]: ";
171 $_ = <STDIN>;
172 if (/^y/i)
173 {
174 $component_value{$c}="Yes";
175 $loop_question=0;
176 }
177 if (/^n/i)
178 {
179 # Maybe ask the user again?
180 $loop_question=0;
181 }
182 if ($loop_question==1)
183 {
184 print "Please entry Y or N.\n";
185 }
186 } while ($loop_question==1);
187
188 }
189 if ($define_type_hash{$c} eq "path")
190 konrad.r 1.1 {
191 do
192 {
193 print $c, "[/usr/include/]: ";
194 $_ = <STDIN>;
195 chomp($_);
196 # Is the directory readable?
197 if (-r $_)
198 {
199 $loop_question=0;
200 $component_value{$c}=$_;
201 }
202 else
203 {
204 print "Path is not accessible. Please enter again.\n";
205 }
206 } while ($loop_question==1);
207
208 }
209 } # componet_value eq "";
210 }
211 konrad.r 1.1
212 }
213 sub check_arguments() {
214
215 my $c="";
216 foreach $c (sort keys(%argument_list))
217 {
218 if ($argument_list{$c} eq "") {
219 #print $c,"is not a PATH\n";
220 }
221 else
222 {
223 # Check the path
224 if (!(-r $argument_list{$c}))
225 {
226 print $c,"=",$argument_list{$c}," path cannot be accessed.\n"
227 }
228 }
229 }
230 }
231
232 konrad.r 1.1 sub print_help() {
233
234 my $c="";
235
236 print "Usage: ",$0," [OPTION]...\n";
237 print "\nArguments:\n";
238
239 foreach $c (sort keys(%component_hash)) {
240 print " ",$enable_component_hash{$c};
241 if ($define_type_hash{$c} =~ /path/)
242 {
243 print "=<directory>";
244 }
245 print "\t\t";
246 print $short_descr_hash{$c},"\n"
247 }
248 }
249
250 sub parse_arguments {
251
252 my $argnum = 0;
253 konrad.r 1.1 my @temp = ();
254 foreach $argnum (0..$#ARGV) {
255
256 if (lc($ARGV[$argnum]) =~ /--help/) {
257 &print_help();
258 exit (0);
259 }
260 if ($ARGV[$argnum] =~ /--/) {
261 # Two types:
262 # --<text>=<path>
263 # --text
264 # We need to extract the <text> and <path> to
265 # argument_list with <text> as key and
266 # <path> as value.
267 @temp = split(/=/, $ARGV[$argnum]);
268 $argument_list{$temp[0]}=$temp[1];
269 }
270 }
271
272 }
273 sub parse_help_file {
274 konrad.r 1.1
275 my $component = "";
276 my $token = "";
277 my @tokens = {};
278 my $state = 1;
279 open HELP_FILE, "$HELP_FILE" or die$!;
280
281 while (<HELP_FILE>) {
282 # Find component.
283 if (/[\d\w_]+[\s]?{/) {
284 s/[\s{]*//g;
285 $component_hash{$_}=$_;
286 $component=$_;
287 $depend_on_hash{$component} = "";
288 $long_descr_hash{$component} = "";
289 $state = 1;
290 }
291 if (/,/ || /}/) {
292 #remove the offending }
293 s/}//;
294 #remove any spaces in front of the string
295 konrad.r 1.1 s/\s//;
296 #get the tokens seperated by ,
297 @tokens=split (/,/,$_);
298 foreach $token (@tokens) {
299 # print "[",$state," ",$token, "]";
300
301 if ($state == 1) {
302 #<depend or (Boolean or Path)
303 # check for boolean or Path
304 if (lc($token) =~ /boolean/ || /path/){
305 #print "(",$token,")";
306 $define_type_hash{$component}=lc($token);
307 $state = 3;
308 }
309 else {
310 # check for "OPENSSL_HOME:<component>
311 if ($depend_on_hash{$component} eq ""){
312 $depend_on_hash{$component}=$token;
313 #print "(",$token,")";
314 }
315 }
316 konrad.r 1.1 }
317
318 elsif ($state == 3) { #--enable-<component>
319
320 if ($token =~ /--/) {
321 $enable_component_hash{$component}=$token;
322 $state =4;
323 }
324 }
325 elsif ($state == 4) {#short_desc
326
327 if (!($token =~ /\n/)) {
328 $short_descr_hash{$component}=$token;
329 $state=5;
330 }
331 }
332 elsif ($state == 5) {#long descr
333
334 $long_descr_hash{$component}=$long_descr_hash{$component}." ".$token;
335 }
336 } # foreach token
337 konrad.r 1.1
338 } #if /,/ or /}/
339 }
340 close (HELP_FILE);
341 }
|