diff --git a/kdesrc-build-setup b/kdesrc-build-setup new file mode 100755 index 0000000..59deb9d --- /dev/null +++ b/kdesrc-build-setup @@ -0,0 +1,349 @@ +#!/usr/bin/env perl + +use strict; +use 5.010; +use IO::Pipe; + +sub runDialogExecutable +{ + my (@args) = @_; + + # Allow for 2 more file descriptors (on top of the normally allowed 0, 1, + # 2) to survive the upcoming exec + # See "SYSTEM_FD_MAX" in perldoc:perlvar + $^F = 4; + + my $pipe = new IO::Pipe; + my $pid; + + if ($pid = fork()) { + # Parent + $pipe->reader(); + + my $output = <$pipe>; + + waitpid $pid, 0; + my $result = ($? >> 8); + $pipe->close(); + + # dialog uses -1 as an exit code, Perl gets just the standard 8 bits + # the rest of UNIX uses... + die "Canceled the dialog" if $result == 255; + return $output || $result; + } + elsif (defined $pid) { + # Child + $pipe->writer(); + my $outputFd = $pipe->fileno(); + + print "Using fd $outputFd"; + exec ('dialog', '--output-fd', $outputFd, + '--backtitle', 'kdesrc-build setup', + @args); + } + else { + die "Unable to fork? $!"; + } +} + +sub getUserInput +{ + my $prompt = shift; + my $default = shift; + + my @args = qw/--inputbox 8 50/; + splice @args, 1, 0, $prompt; + push @args, $default if $default; + + return runDialogExecutable(@args); +} + +sub getMenuOption +{ + my ($prompt, @opts) = @_; + @opts = @{$opts[0]} if ref $opts[0] eq 'ARRAY'; + + my @args = qw/--menu 20 70 18/; + splice @args, 1, 0, $prompt; + + while(my ($k, $v) = splice (@opts, 0, 2)) { + push @args, $k, $v; + } + + return runDialogExecutable(@args); +} + +sub showInfo +{ + my $message = shift; + my @args = qw/--msgbox 20 62/; + splice @args, 1, 0, $message; + + return runDialogExecutable(@args); +} + +sub getYesNoAnswer +{ + my $prompt = shift; + my @args = qw/--yesno 8 55/; + splice @args, 1, 0, $prompt; + + return runDialogExecutable(@args) == 0; +} + +sub getDirectory +{ + my $dir = shift; + my @args = qw/--dselect 20 70/; + splice @args, 1, 0, $dir; + + return runDialogExecutable(@args); +} + +sub getListOptions +{ + my ($prompt, $opts, $enabled) = @_; + die "\$opts not a hash ref" unless (ref $opts eq 'ARRAY'); + die "\$enabled not a hash ref" unless (ref $enabled eq 'HASH'); + + my @args = qw/--checklist 20 70 18/; + splice @args, 1, 0, $prompt; + splice @args, 0, 0, qw/--output-separator ,/; + + while (my ($k, $v) = splice(@{$opts}, 0, 2)) { + push (@args, $k, $v, (exists ${$enabled}{$k} ? 'on' : 'off')); + } + + my $output = runDialogExecutable(@args); + + # Filter out empty results, remove quotes. + return map { m/^"(.*)"$/ } (grep { length $_ } (split(/,/, $output))); +} + +showInfo(< 'Just simple applications or modules', + kde => '"Bleeding-edge" KDE software, using system libraries', + all => '"Bleeding-edge" KDE and Qt software', + ]); +my $installDir = getMenuOption('Where do you want to install the software?', + [ + home => "$ENV{HOME}/kde4 (default)", + custom => "Custom location, chosen next screen", + ]); + +if ($installDir eq 'custom') { + $installDir = getDirectory('/usr/local/kde4'); +} +else { + $installDir = "~/kde4"; +} + +my @chosenModules = getListOptions( + "Which major module groups do you want to build?", + [ + qt => 'The Qt library', + framework => 'KDE Framework libraries/runtime (required)', + workspace => 'KDE Plasma Desktop and workspace', + base => 'Essential KDE applications', + pim => 'Personal Information Management software', + ], + { + framework => 1, + workspace => 1, + base => 1, + }, +); + +my $numCpus = getUserInput( + 'How many CPU cores do you wish to use for building?', '2'); + +open my $output, '>', '/tmp/kdesrc-buildrc' or die "$!"; + +print $output <