File: kdesrc-build-setup

package info (click to toggle)
kdesrc-build 1.15.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 704 kB
  • ctags: 344
  • sloc: perl: 5,915; xml: 180; makefile: 10; sh: 9
file content (492 lines) | stat: -rwxr-xr-x 13,017 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
#!/usr/bin/env perl

# Script to create a configuration file for kdesrc-build.
#
# Copyright © 2011 Michael Pyne. <mpyne@kde.org>
# Home page: http://kdesrc-build.kde.org/
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

use strict;
use 5.010;
use IO::Pipe;
use File::Copy;
use File::Temp qw/tempfile/;

our $VERSION = 0.02; # Not user-visible yet.

sub clearScreen
{
    require POSIX;
    my $termios = POSIX::Termios->new();
    $termios->getattr(1); # Get STDOUT attributes

    require Term::Cap;
    my $terminal = Term::Cap->Tgetent({OSPEED => $termios->getospeed});

    # Force the clear characters to be output immediately.
    # Otherwise it might overlap with other output, like error messages.
    local $| = 1;

    print $terminal->Tputs('cl', 0);

    return 0;
}

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...
        if ($? == -1) {
            clearScreen();
            die "Failed to run dialog(1): $@";
        }
        elsif ($result == 255) {
            clearScreen();
            die "Canceled the dialog";
        }
        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, '--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)));
}

# The 'dialog(1)' program is required, verify it exists before going
# further.
# We use the --help option since it doesn't send weird terminal characters to the screen
# and it's supported on dialog and Debian's dialog replacement called whiptail.
system('dialog', '--help') == 0 or do {
    my $osError = "$!";

    say "Unable to run the dialog(1) program, it is required for this setup script.";
    if ($? == -1) {
        say "\tThe program wouldn't even run, due to error: $osError";
    }
    else {
        say "\tProgram ran, but exited with error: ", $? >> 8;
    }

    exit 1;
};

showInfo(<<EOF);
This program sets up a base kdesrc-build configuration to
use.

It can be modified as you wish later. Before the form is
presented, you will be asked if you would like an
explanation of the kdesrc-build file layout.  It is
recommended to read this if you are not already familiar
with building software.
EOF

if (getYesNoAnswer('See the tutorial?')) {
    showInfo(<<EOF);
kdesrc-build must download source code from the KDE
repositories.  This source code is then compiled, in the
"build directory". Once complete, this compiled code is
installed to its final location, the "install directory".

This program will only configure the install location, but
all directories are configurable.

The space requirements vary, but typically the build
directory will require 3-5 times as much space as the
corresponding source directory. The space required of
installed software will be less than the build directory.
EOF
}

my $dev = getYesNoAnswer('Do you already have commit ' .
    'access to the KDE repositories?');

if ($dev) {
    $dev = getUserInput("What is your KDE identity username (for SVN access)?");
}

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');

my $outputFileName = "$ENV{HOME}/.kdesrc-buildrc";
my $output; # Will be output filehandle.

while (-e $outputFileName) {
    (my $printableName = $outputFileName) =~ s/^$ENV{HOME}/~/;
    my $outputChoice = getMenuOption(
        "$printableName already exists, what do you want to do?",
        [
            backup => 'Make a backup, then overwrite with the new configuration',
            custom => 'Write the new configuration to a different file',
            cancel => 'Cancel setup',
        ],
    );

    if ($outputChoice eq 'cancel') {
        showInfo('Setup canceled');
        exit 0;
    }

    if ($outputChoice eq 'custom') {
        $outputFileName = getUserInput('Enter desired configuration file name.');
        $outputFileName =~ s/^~/$ENV{HOME}/;
    }

    if ($outputChoice eq 'backup') {

        copy($outputFileName, "$outputFileName~") or do {
            my $error = "$!";
            showInfo(<<EOF);
Failed to make backup of $outputFileName, due to error $error.
Configuration will be written to a temporary file instead.
EOF

            ($output, $outputFileName) = tempfile("kdesrc-buildrc-XXXX");
        };

        last;
    }
}

# Filehandle could already be opened as a tempfile.
if (!$output) {
    open ($output, '>', $outputFileName) or do {
        my $error = "$!";
        showInfo (<<EOF);
Unable to open output file $outputFileName for writing due to error $error.
EOF
        die "$!";
    }
}

print $output <<EOF;
# Autogenerated by kdesrc-build-setup. You may modify this file if desired.
global

EOF

if (grep { /^qt$/ } @chosenModules) {
    print $output <<EOF;
    # The path to your Qt installation.
    qtdir ~/qt4

EOF
}

print $output <<EOF;
    # KDE install directory
    kdedir $installDir

    # Directory for downloaded source code
    source-dir ~/kdesrc

    # Directory to build KDE into before installing
    build-dir build

    # Use multiple cores for building. Other options to GNU make may also be
    # set.
    make-options -j$numCpus

EOF

if ($dev) {
    print $output <<EOF;
    # Login to use for SVN. Anonymous SVN can be used by just deleting this
    # line.
    svn-server svn+ssh://$dev\@svn.kde.org/home/kde

EOF
}

print $output <<EOF;
end global

EOF

if (grep /^qt$/, @chosenModules) {
    print $output <<EOF;
module qt
    configure-flags -fast -debug -system-zlib -system-libpng -system-libjpeg \\
                    -plugin-sql-mysql -no-phonon \\
                    -dbus -webkit -nomake examples -nomake demos

    # KDE's unmodified copy of Qt is used by default since git.kde.org supports
    # cloning the module more reliably than gitorious. To use standard Qt as
    # provided by Nokia, comment the following line and uncomment the next
    # repository line.
    repository kde:qt

    # Nokia's Qt. Note that gitorious has had known issues checking out large
    # git modules such as Qt. If there are failures try using KDE's qt (see
    # above).
    # repository git://gitorious.org/qt/qt.git

    branch 4.8
end module

EOF
}

if (grep /^framework$/, @chosenModules) {
    print $output <<EOF;
# These encompass modules that are not directly a part of KDE proper but are
# required or highly recommended for the KDE framework and are developed in
# the KDE source repository.
module-set framework-support
    repository kde-projects

    use-modules automoc cagibi attica soprano polkit-qt-1
end module-set

# Phonon provides the KDE multimedia layer. It requires an appropriate backend
# to be installed to actually implement multimedia.
module-set framework-phonon
    repository kde-projects

    use-modules phonon/phonon phonon-gstreamer phonon-vlc
end module-set

# Strigi provides file analysis tools for extracting information from files
# (e.g. music length, picture size, etc.) It is split into several submodules
# so do not alter the order in the use-modules below.
module-set strigi
    repository kde-projects

    use-modules strigi/libstreams strigi/libstreamanalyzer strigi/strigiutils \\
                strigi/strigidaemon strigi/strigiclient
end module-set

# libdbusmenu is needed to support new-style Plasma system tray icons and
# support in the Unity shell. Installing a recent development package from your
# distribution should be sufficient, but if you want to have the latest then
# make sure you have the "Bazaar" program installed and uncomment the
# following:
#module libdbusmenu-qt
    # The lp: prefix refers to Canonical's Launchpad repository
#    repository bzr://lp:libdbusmenu-qt
#end module

# Base KDE framework libraries and the required runtime programs.
module-set framework
    repository kde-projects

    use-modules kdelibs kactivities kde-runtime
end module-set

EOF
}

# We'll check for pim again later.
if (grep /^pim$/, @chosenModules) {
    print $output <<EOF;
module-set pimlibs
    repository kde-projects

    use-modules akonadi kdepimlibs
end module-set

EOF
}

if (grep /^workspace$/, @chosenModules) {
    print $output <<EOF;
module-set workspace
    repository kde-projects

    use-modules kde-workspace kdeplasma-addons
end module-set

EOF
}

if (grep /^base$/, @chosenModules) {
    print $output <<EOF;
module-set base
    repository kde-projects

    # kde-baseapps must precede kate and konsole, due to
    # on-disk layout.
    use-modules kde-baseapps kate konsole
end module-set

EOF
}

if (grep /^pim$/, @chosenModules) {
    print $output <<EOF;
module-set pim
    repository kde-projects

    use-modules kdepim-runtime kdepim
end module-set

EOF
}

close($output);
$outputFileName =~ s/^$ENV{HOME}/~/;
showInfo("Generated configuration has been written to $outputFileName");

# Say same thing in text mode just in case.
system('clear');
say "Generated configuration has been written to $outputFileName";

if ($outputFileName ne '~/.kdesrc-buildrc') {
    say <<EOF;

Note that your configuration file in $outputFileName will
NOT BE USED unless you either:
1. Overwrite your ~/.kdesrc-buildrc with $outputFileName, or
2. Copy $outputFileName to be called 'kdesrc-buildrc' in some directory
   and ALWAYS run kdesrc-build from the directory, or
3. ALWAYS pass the "--rc-file $outputFileName" option to kdesrc-build when you
   run it.
EOF
}

exit 0;