#!/usr/bin/perl use strict; use CGI qw/:standard *table/; my $q = new CGI; my $pwd = $q->param('pwd'); $pwd =~ /\/([^\/]*)$/; my $name = $1; my $configure = './configure'; my @ignores = ('--quiet,', '--version', '--help'); my $outputfilename = "doConfig"; sub my_print { print $_[0]; print OUT $_[0]; } if ($q->param('GO')) { print header('text/plain'); open OUT, "> $pwd/$outputfilename" or print "cannot open file $pwd/$outputfilename
\n"; my_print "#!/bin/sh\n"; if (my $CC = $q->param('CC')) { my_print "CC=$CC \\\n"; } if (my $CXX = $q->param('CXX')) { my_print "CXX=$CXX \\\n"; } my_print "./configure \\\n"; my %params = $q->Vars; foreach (keys %params) { next unless (/^_(.*)/); my $key = $1; my $yes = $q->param($_); next if ($yes eq 'default'); if ($yes eq 'no') { s/enable/disable/ || s/disable/enable/ || s/without/with/ || s/with/without/; } my $arg = $q->param("${key}_arg"); if ($arg) { my_print " --$key=$arg \\\n"; } else { my_print " --$key \\\n"; } } my_print "\n"; system("chmod 755 $pwd/doConfig"); exit; } print header, start_html(-title => "configure $name"); print p("configure $name"); unless (-x "$pwd/$configure") { print "executable configure file not found."; exit; } chdir $pwd; my %arghash; if(-e $outputfilename){ my $conf; open(CACHE, "<$outputfilename") || die "$outputfilename: $!\n"; while(){ chomp; next unless /^[ \t]+--([^ ]+)/; $conf = $1; my ($cmd, $arg) = $conf =~ /(.+)=(.+)$/; $cmd = $conf if ($cmd eq ''); $arghash{$cmd} = "x$arg"; # messy } close(CACHE); } my @lines = split /\n/, `$configure --help`; print start_form, start_table, "\n"; for (my $i = 0; $i < $#lines; $i++) { next unless ($lines[$i] =~ /^\s*(--[^\s]*)\s*(.*)/); my $conf = $1; my $desc = $2; while ($lines[$i+1] =~ /^\s+([^\s-].*)/) { $i++; $desc .= " $1"; } my $ignore = 0; foreach (@ignores) { $ignore = 1 if ($conf =~ /$_/); } next if ($ignore); print "$conf$desc\n"; $conf =~ /^--([^=\[]*)(\[*=*)/; my $confname = $1; my $needarg = $2; my $yes = 'default'; my $arg = $arghash{$confname}; if($arg ne ''){ $yes = "yes"; $arg = substr($arg, 1); # remove 'x' } else { my $confrev = $confname; if($confrev !~ s/enable/disable/){ if($confrev !~ s/disable/enable/){ if($confrev !~ s/without/with/){ $confrev =~ s/with/without/; } } } $arg = $arghash{$confrev}; if($arg ne ''){ $yes = "no"; $arg = substr($arg, 1); # remove 'x' } } print "", radio_group("_$confname", ['yes', 'no', 'default'], $yes), "", ; if ($needarg) { print textfield("${confname}_arg", $arg); } print "

\n"; } print "CC", textfield("CC"), "", "CXX", textfield("CXX"), "", ; print end_table, hidden("pwd", $pwd), submit('GO'), end_form; print end_html;