kdesvn-build 130 KB
Newer Older
1
#!/usr/bin/perl -w
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

#Pod documentation:

=head1 NAME

=over

=item B<kdesvn-build> - automate the kde svn build process

=back

=head1 SYNOPSIS

=over

=item B<kdesvn-build> I<[options]...> I<[modules]...>

=back

=head1 DESCRIPTION

The B<kdesvn-build> script is used to automate the download, build,
and install process for KDE (using Subversion).

26
It is recommended that you first setup a F<.kdesvn-buildrc> file
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
in your home directory. Please refer to B<kdesvn-build> help file
in KDE help for information on how to write F<.kdesvn-buildrc>,
or consult the sample file which should have been included
with this program.  If you don't setup a F<.kdesvn-buildrc>, a
default set of options will be used, and a few modules will be
built by default.

After setting up F<.kdesvn-buildrc>, you can run this program from
either the command-line or from cron. It will automatically
download the modules from Subversion, create the build
system, and configure and make the modules you tell it to.
You can use this program to install KDE as well,
if you are building KDE for a single user. Note that B<kdesvn-build>
will try to install the modules by default.

If you DO specify a package name, then your settings will still be
read, but the script will try to build / install the package
regardless of F<.kdesvn-buildrc>

46
47
48
49
50
51
52
53
54
55
56
57
kdesvn-build reads options in the following order:

=over

=item 1. From the command line.

=item 2. From the file F<kdesvn-buildrc> in the current directory.  Note that
         the file is not a hidden file.

=item 3. From the file F<~/.kdesvn-buildrc>.

=item 4. From a set of internal options.
58
59
60

=back

61
62
This utility is part of the KDE Software Development Kit.

63
64
=head1 OPTIONS

65
66
=over

67
68
69
70
71
72
73
74
75
76
77
78
79
80
=item B<--quiet>,  B<-q>

With this switch kdesvn-build will only output a general overview of the build
process.  Progress output is still displayed if available.

=item B<--really-quiet>

With this switch only warnings and errors will be output.

=item B<--verbose>,  B<-v>

Be very detailed in what is going on, and what actions kdesvn-build is taking.
Only B<--debug> is more detailed.

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
=item B<--no-svn>

Skip contacting the Subversion server.

=item B<--no-build>

Skip the build process.

=item B<--no-install>

Don't automatically install after build.

=item B<--svn-only>

Update from Subversion only (Identical to B<--no-build> at this point).

=item B<--build-only>

Build only, do not perform updates or install.

=item B<--rc-file=E<lt>filenameE<gt>>

Read configuration from filename instead of default.

=item B<--debug>

Activates debug mode.

=item B<--pretend>,  B<-p>

Do not contact the Subversion server, run make, or create / delete files
and directories. Instead, output what the script would have done.

=item B<--nice=E<lt>valueE<gt>>

Allow you to run the script with a lower priority. The default value is
10 (lower priority by 10 steps).

=item B<--prefix=/kde/path>

This option is a shortcut to change the setting for kdedir from the
command line. It implies B<--reconfigure>.

=item B<--color>

126
Add color to the output.
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

=item B<--no-color>

Remove color from the output.

=item B<--resume>

Tries to resume the make process from the last time the script was run,
without performing the Subversion update.

=item B<--resume-from=E<lt>pkgE<gt>>

Starts building from the given package, without performing the Subversion
update.

=item B<--revision=E<lt>revE<gt>>, B<-r=E<lt>revE<gt>>

Forces update to revision <rev> from Subversion.

=item B<--refresh-build>

148
149
150
151
Start the build from scratch.  This means that the build directory for the
module B<will be deleted> before make -f Makefile.cvs is run again.  You can
use B<--recreate-configure> to do the same thing without deleting the module
build directory.
152
153
154
155
156
157
158
159

=item B<--reconfigure>

Run configure again, but don't clean the build directory or re-run
make -f Makefile.cvs.

=item B<--recreate-configure>

160
161
Run make -f Makefile.cvs again to redo the configure script.  The build
directory is not deleted.
162
163
164

=item B<--no-rebuild-on-fail>

165
166
167
Do not try to rebuild a module from scratch if it failed building.  Normally
kdesvn-build will try progressively harder to build the module before giving
up.
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183

=item B<--build-system-only>

Create the build infrastructure, but don't actually perform the build.

=item B<--install>

Try to install the packages passed on the command line, or all packages in
F<~/.kdesvn-buildrc> that don't have manual-build set. Building and
Subversion updates are not performed.

=item B<--E<lt>optionE<gt>=>

Any unrecognized options are added to the global configuration, overriding
any value that may exist.

184
185
186
For example, B<--svn-server=http://path.to.svn.server/> would change the
setting of the global B<svn-server> option for this instance of kdesvn-build.

187
188
189
190
191
=item B<--E<lt>moduleE<gt>,E<lt>optionE<gt>=>

Likewise, allow you to override any module specific option from the
command line.

192
193
194
Example: B<--kdelibs,use-unsermake=false> would disable unsermake for the
kdelibs module.

195
196
197
198
199
200
201
202
203
204
205
206
=item B<--help>

Display the help and exit.

=item B<--author>

Output the author(s)'s name.

=item B<--version>

Output the program version.

207
208
=back

209
210
=head1 EXAMPLES

211
212
=over

213
214
215
216
217
218
=item B<kdesvn-build>

=item B<kdesvn-build> I<--no-svn kdelibs>

=item B<kdesvn-bulid> I<--refresh-build> I<kdebase>

219
220
=back

221
222
=head1 BUGS

223
224
225
226
Since kdesvn-build doesn't generally save information related to the build and
prior settings, you may need to manually re-run kdesvn-build with a flag like
B<--recreate-configure> if you change some options, including B<use-unsermake>.

227
228
229
230
231
232
Please use KDE bugzilla at http://bugs.kde.org for information and
reporting bugs.

=head1 SEE ALSO

You can find additional information at B<kdesvn-build> home page,
233
F<http://kdesvn-build.kde.org/>, or using kdesvn-build
234
235
236
237
238
239
docbook documentation, using the help kioslave, F<help:/kdesvn-build>.

=head1 AUTHOR

Michael Pyne <michael.pyne@kdemail.net>

240
241
242
Man page written by:
Carlos Leonhard Woelz <carlos.woelz@kdemail.net>

243
244
=cut

245
246
247
248
249
250
251
# Script to handle building KDE from Subversion.  All of the configuration is
# stored in the file ~/.kdesvn-buildrc.
#
# Please also see the documentation that should be included with this program,
# in doc.html
#
# Copyright (c) 2003, 2004, 2005 Michael Pyne. <michael.pyne@kdemail.net>
252
# Home page: http://kdesvn-build.kde.org/
253
254
255
256
257
258
259
260
261
262
#
# You may use, alter, and redistribute this software under the terms
# of the GNU General Public License, v2 (or any later version).
#
# TODO: It would be better to have lockfiles in each directory as it's
#       being updated, instead of having one big lock for the script.

use strict;
use warnings;
use Fcntl;    # For sysopen constants
263
use POSIX 'strftime';
264
use File::Find; # For our lndir reimplementation.
265
use Errno qw(:POSIX);
266

267
268
269
270
271
272
273
274
275
276
# Debugging level constants.
use constant {
    DEBUG   => 0,
    WHISPER => 1,
    INFO    => 2,
    NOTE    => 3,
    WARNING => 4,
    ERROR   => 5,
};

277
278
279
280
281
# Some global variables
# Remember kids, global variables are evil!  I only get to do this
# because I'm an adult and you're not! :-P
# Options that start with a # will replace values with the same name,
# if the option is actually set.
282
283
my %package_opts = (
  'global' => {
284
    "apidox"              => "",
285
    "apply-qt-patches"    => "",
286
    "binpath"             => "/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin",
287
    "branch"              => "",
288
289
290
    "build-dir"           => "build",
    "build-system-only"   => "",
    "checkout-only"       => "",
291
    "configure-flags"     => "--enable-debug=full",
292
    "colorful-output"     => 1, # Use color by default.
293
    "cxxflags"            => "-g -pipe",
294
    "debug"               => "",
295
    "debug-level"         => INFO,
296
    "dest-dir"            => '${MODULE}', # single quotes used on purpose!
Michael Pyne's avatar
Michael Pyne committed
297
    "disable-agent-check" => 0,   # If true we don't check on ssh-agent
298
    "do-not-compile"      => "",
299
300
    "email-address"       => "",
    "email-on-compile-error" => "",
301
302
303
304
305
    "install-after-build" => "1", # Default to true
    "inst-apps"           => "",
    "kdedir"              => "$ENV{HOME}/kde",
    "libpath"             => "",
    "log-dir"             => "log",
306
307
    "make-install-prefix" => "",  # Some people need sudo
    "make-options"        => "-j2",
308
309
    "manual-build"        => "",
    "manual-update"       => "",
310
    "module-base-path"    => "",  # Used for tags and branches
311
    "niceness"            => "10",
312
313
    "no-svn"              => "",
    "no-rebuild-on-fail"  => "",
314
    "override-url"        => "",
315
    "prefix"              => "", # Override installation prefix.
316
317
    "pretend"             => "",
    "qtdir"               => "$ENV{HOME}/kdesvn/build/qt-copy",
318
319
320
    "reconfigure"         => "",
    "recreate-configure"  => "",
    "refresh-build"       => "",
321
    "remove-after-install"=> "none", # { none, builddir, all }
322
    "revision"            => 0,
323
324
    "set-env"             => { }, # Hash of environment vars to set
    "source-dir"          => "$ENV{HOME}/kdesvn",
325
    "stop-on-failure"     => "",
326
    "svn-server"          => "svn://anonsvn.kde.org/home/kde",
327
    "tag"                 => "",
328
    "unsermake-options"   => "--compile-jobs=2 -p",
329
    "unsermake-path"      => "unsermake",
330
    "use-unsermake"       => "1", # Default to true now, we may need a blacklist
331
  }
332
333
);

334
# This is a hash since Perl doesn't have a "in" keyword.
335
my %ignore_list;  # List of packages to refuse to include in the build list.
336
337
338
339

# update and build are lists since they support an ordering, which can't be
# guaranteed using a hash unless I want a custom sort function (which isn't
# necessarily a horrible way to go, I just chose to do it this way.
340
341
my @update_list;  # List of modules to update/checkout.
my @build_list;   # List of modules to build.
342

343
344
345
346
347
# Dictionary of lists of failed modules, keyed by the name of the operation
# that caused the failure (e.g. build).  Note that output_failed_module_lists
# uses the key name to display text to the user so it should describe the
# actual category of failure.  You should also add the key name to
# output_failed_module_lists since it uses its own sorted list.
348
my @fail_display_order = qw/build update install/;
349
350
351
352
353
354
my %fail_lists = (
    'build'   => [ ],
    'install' => [ ],
    'update'  => [ ],
);

355
356
357
my $install_flag; # True if we're in install mode.
my $BUILD_ID;     # Used by logging subsystem to create a unique log dir.
my $LOG_DATE;     # Used by logging subsystem to create logs in same dir.
Michael Pyne's avatar
Michael Pyne committed
358
my @rcfiles = ("./kdesvn-buildrc", "$ENV{HOME}/.kdesvn-buildrc");
359

360
361
362
# Colors
my ($RED, $GREEN, $YELLOW, $NORMAL, $BOLD) = ("") x 5;

363
364
# Subroutine definitions

365
366
# I swear Perl must be the only language where the docs tell you to use a
# constant that you'll never find exported without some module from CPAN.
367
use constant PRIO_PROCESS => 0;
368

369
370
371
# I'm lazy and would rather write in shorthand for the colors.  This sub
# allows me to do so. Put it right up top to stifle Perl warnings.
sub clr($)
372
{
373
374
375
376
377
378
379
380
381
    my $str = shift;

    $str =~ s/g\[/$GREEN/g;
    $str =~ s/]/$NORMAL/g;
    $str =~ s/y\[/$YELLOW/g;
    $str =~ s/r\[/$RED/g;
    $str =~ s/b\[/$BOLD/g;

    return $str;
382
383
384
385
386
387
388
389
390
391
392
393
394
}

# Subroutine which returns true if pretend mode is on.  Uses the prototype
# feature so you don't need the parentheses to use it.
sub pretending()
{
    return get_option('global', 'pretend');
}

# Subroutine which returns true if debug mode is on.  Uses the prototype
# feature so you don't need the parentheses to use it.
sub debugging()
{
395
    return get_option('global', 'debug-level') <= DEBUG;
396
397
}

398
399
400
401
402
403
404
405
406
407
408
409
410
411
# The next few subroutines are used to print output at different importance
# levels to allow for e.g. quiet switches, or verbose switches.  The levels are,
# from least to most important:
# debug, whisper, info (default), note (quiet), warning (very-quiet), and error.
# 
# You can also use the pretend output subroutine, which is emitted if, and only
# if pretend mode is enabled.
#
# clr is automatically run on the input for all of those functions.
# Also, the terminal color is automatically reset to normal as well so you don't
# need to manually add the ] to reset.

# Subroutine used to actually display the data, calls clr on each entry first.
sub print_clr(@)
Michael Pyne's avatar
Michael Pyne committed
412
{
413
414
415
    print clr $_ foreach (@_);
    print clr "]\n";
}
Michael Pyne's avatar
Michael Pyne committed
416

417
418
419
420
sub debug(@)
{
    print_clr @_ if debugging;
}
Michael Pyne's avatar
Michael Pyne committed
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
sub whisper(@)
{
    print_clr @_ if get_option('global', 'debug-level') <= WHISPER;
}

sub info(@)
{
    print_clr @_ if get_option('global', 'debug-level') <= INFO;
}

sub note(@)
{
    print_clr @_ if get_option('global', 'debug-level') <= NOTE;
}

sub warning(@)
{
    print_clr @_ if get_option('global', 'debug-level') <= WARNING;
}

# This sub has the additional side effect of printing the errno value if it
# is set.
sub error(@)
{
    print STDERR (clr $_) foreach (@_);
    print "  $!\n" if $!;
}

sub pretend(@)
{
    print_clr @_ if pretending;
}

# Subroutine to handle removing the lock file upon receiving a signal
sub quit_handler
{
    note "Signal received, terminating.";
    finish(5);
Michael Pyne's avatar
Michael Pyne committed
460
461
}

462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
# Subroutine that returns the path of a file used to output the results of the
# build process.  It accepts one parameter, which changes the kind of file
# returned.  If the parameter is set to 'existing', then the file returned is
# the latest file that exists, or undef if no log has been created yet.  This
# is useful for the --resume mode.  All other values will return the name if a
# file that does not yet exist.
#
# All files will be stored in the log directory.
sub get_output_file
{
    my $logdir;
    my $mode;
    $mode = shift or $mode = '';
    my $fname;

477
    debug "get_output_file in mode $mode";
478
479
480
481
482
483
484
485
486
487
488

    if ($mode eq 'existing')
    {
        # There's two ways of finding the old file.  Searching backwards with
        # valid combinations of the date and build id, or just reading in the
        # name from a known file or location.  Since the latter option is much
        # easier, that's what I'm going with.  Note that this depends on the
        # latest symlink being in place.
        $logdir = get_subdir_path ('global', 'log-dir');
        $fname = "$logdir/latest/build-status";

489
490
491
492
        debug "Old build status file is $fname";

        # The _ at the end returns the cached file stats to avoid multiple
        # stat() calls.
493
494
495
496
497
498
499
500
        return "" if not -e $fname or not -r _;

        return $fname;
    }

    # This call must follow the test above, because it changes the 'latest'
    # symlink leading to failures later.
    $logdir = get_log_dir('global');
501

502
    $fname = "$logdir/build-status";
503
504
    debug "Build status file is $fname";

505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
    return $fname;
}

# Subroutine to retrieve a subdirecty path for the given module.
# First parameter is the name of the module, and the second
# parameter is the option key (e.g. build-dir or log-dir).
sub get_subdir_path
{
    my $module = shift;
    my $option = shift;
    my $dir = get_option($module, $option);

    # If build-dir starts with a slash, it is an absolute path.
    return $dir if $dir =~ /^\//;

    # If it starts with a tilde, expand it out.
    if ($dir =~ /^~/)
    {
        $dir =~ s/^~/$ENV{'HOME'}/;
    }
    else
    {
        # Relative directory, tack it on to the end of $kdesvn.
        my $kdesvndir = get_kdesvn_dir();
        $dir = "$kdesvndir/$dir";
    }

    return $dir;
}

535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
# Subroutine to return the name of the destination directory for the checkout
# and build routines.  Based on the dest-dir option.  The return value will be
# relative to the src/build dir.  The user may use the '$MODULE' or '${MODULE}'
# sequences, which will be replaced by the name of the module in question.
#
# The first parameter should be the module name.
sub get_dest_dir
{
    my $module = shift;
    my $dest_dir = get_option($module, 'dest-dir');

    $dest_dir =~ s/(\${MODULE})|(\$MODULE\b)/$module/g;

    return $dest_dir;
}

551
552
553
554
555
556
# Convienience subroutine to get the source root dir.
sub get_kdesvn_dir
{
    return get_option ('global', 'source-dir');
}

557
558
559
560
561
562
563
564
565
566
# Function to work around a Perl language limitation.
# First parameter is the list to search.
# Second parameter is the value to search for.
# Returns true if the value is in the list
sub list_has(\@$)
{
    my ($list_ref, $value) = @_;
    return scalar grep ($_ eq $value, @{$list_ref});
}

567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
# Subroutine to return the branch prefix. i.e. the part before the branch name
# and module name.
#
# The first parameter is the module in question.
# The second parameter should be 'branches' if we're dealing with a branch or
#     'tags' if we're dealing with a tag.
#
# Ex: 'kdelibs'  => 'branches/KDE'
#     'kdevelop' => 'branches/kdevelop'
sub branch_prefix
{
    my $module = shift;
    my $type = shift;

    # These modules seem to have their own subdir in /tags.
    my @tag_components = qw/arts koffice amarok kst qt taglib/;

    # The map call adds the kde prefix to the module names because I don't feel
    # like typing them all in. kdevelop and konstruct are special cases.
    my @kde_module_list = ((map {'kde' . $_} qw/-i18n -common accessibility
            addons admin artwork base bindings edu games graphics libs
            multimedia network nonbeta pim sdk toys utils webdev/), 'kdevelop',
            'konstruct');

    # KDE proper modules seem to use this pattern.
    return "$type/KDE" if list_has(@kde_module_list, $module);

    # If we doing a tag just return 'tags' because the next part is the actual
    # tag name, which is added by the caller, unless the module has its own
    # subdirectory in /tags.
    return "$type" if $type eq 'tags' and not list_has(@tag_components, $module);

    # Everything else.
    return "$type/$module";
}

# Subroutine to return a module URL for a module using the 'branch' option.
# First parameter is the module in question.
# Second parameter is the type ('tags' or 'branches')
sub handle_branch_tag_option
{
    my ($module, $type) = @_;
    my $svn_server = get_option($module, 'svn-server');
    my $branch = branch_prefix($module, $type);
    my $branchname = get_option($module, 'tag');

    if($type eq 'branches')
    {
        $branchname = get_option($module, 'branch');
    }

    # Remove trailing slashes.
    $svn_server =~ s/\/*$//;

    return "$svn_server/$branch/$branchname/$module";
}

624
625
626
627
628
629
# Subroutine to return the appropriate SVN URL for a given module, based on
# the user settings.  For example, 'kdelibs' -> https://svn.kde.org/home/kde/trunk/KDE/kdelibs
sub svn_module_url
{
    my $module = shift;
    my $svn_server = get_option($module, 'svn-server');
630
    my $branch = get_option($module, 'module-base-path');
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648

    # Allow user to override normal processing of the module in a few ways,
    # to make it easier to still be able to use kdesvn-build even when I
    # can't be there to manually update every little special case.
    if(get_option($module, 'override-url'))
    {
        return get_option($module, 'override-url');
    }

    if(get_option($module, 'tag'))
    {
        return handle_branch_tag_option($module, 'tags');
    }

    if(get_option($module, 'branch'))
    {
        return handle_branch_tag_option($module, 'branches');
    }
649
    
650
651
652
    # The following modules are in /trunk, not /trunk/KDE.  There are others,
    # but there are the important ones.  The hash is associated with the value
    # 1 so that we can do a boolean test by looking up the module name.
653
654
    my @non_trunk_modules = qw(extragear kdenonbeta kdesupport koffice
        playground qt-copy valgrind KDE kdereview www l10n);
655

656
657
658
    my $module_root = $module;
    $module_root =~ s/\/.*//; # Remove everything after the first slash

659
660
661
662
663
    if (not $branch)
    {
        $branch = 'trunk/KDE';
        $branch = 'trunk' if list_has(@non_trunk_modules, $module_root);
    }
664

665
666
667
    $branch =~ s/^\/*//; # Eliminate / at beginning of string.
    $branch =~ s/\/*$//; # Likewise at the end.
    
668
669
670
671
672
673
    # Remove trailing slashes.
    $svn_server =~ s/\/*$//;

    return "$svn_server/$branch/$module";
}

674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
# Convienience subroutine to return the build directory for a module. Use
# this instead of get_subdir_path because this special-cases modules for you,
# such as qt-copy.
# TODO: From what I hear this hack is no longer necessary.  Investigate this.
sub get_build_dir
{
    my $module = shift;

    # It is the responsibility of the caller to append $module!
    return get_kdesvn_dir() if ($module eq 'qt-copy') and not get_option('qt-copy', 'use-qt-builddir-hack');
    return get_subdir_path($module, 'build-dir');
}

# Subroutine to return a list of the different log directories that are used
# by the different modules in the script.
sub get_all_log_directories
{
    my @module_list = keys %package_opts;
    my %log_dict;

694
    # A hash is used to track directories to avoid duplicate entries.
695
696
697
    unshift @module_list, "global";
    $log_dict{get_subdir_path($_, 'log-dir')} = 1 foreach @module_list;

698
    debug "Log directories are ", join (", ", keys %log_dict);
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
    return keys %log_dict;
}

# Subroutine to determine the build id for this invocation of the script.  The
# idea of a build id is that we want to be able to run the script more than
# once in a day and still retain each set of logs.  So if we run the script
# more than once in a day, we need to increment the build id so we have a
# unique value.  This subroutine sets the global variable $BUILD_ID and
# $LOG_DATE for use by the logging subroutines.
sub setup_logging_subsystem
{
    my $min_build_id = "00";
    my $date = strftime "%F", localtime; # ISO 8601 date
    my @log_dirs = get_all_log_directories();

    for (@log_dirs)
    {
        my $id = "01";
        $id++ while -e "$_/$date-$id";

        # We need to use a string comparison operator to keep 
        # the magic in the ++ operator.
        $min_build_id = $id if $id gt $min_build_id;
    }

    $LOG_DATE = $date;
    $BUILD_ID = $min_build_id;
}

# Convienience subroutine to return the log directory for a module.
# It also creates the directory and manages the 'latest' symlink.
#
# Returns undef on an error, or the name of the directory otherwise.
sub get_log_dir
{
    my $module = shift;
    my $logbase = get_subdir_path($module, 'log-dir');
    my $logpath = "$logbase/$LOG_DATE-$BUILD_ID/$module";

    $logpath = "$logbase/$LOG_DATE-$BUILD_ID" if $module eq 'global';
739
740

    debug "Log directory for $module is $logpath";
741

742
    if (not -e $logpath and not pretending and not super_mkdir($logpath))
743
    {
744
        error "Unable to create log directory r[$logpath]";
745
746
747
748
        return undef;
    }

    # Add symlink to the directory.
749
750
    # TODO: This probably can result in a few dozen unnecessary calls to
    # unlink and symlink, fix this.
751
752
753
    if (not pretending)
    {
        unlink("$logbase/latest") if -l "$logbase/latest";
754
        symlink("$logbase/$LOG_DATE-$BUILD_ID", "$logbase/latest");
755
    }
756
757
758
759

    return $logpath;
}

Michael Pyne's avatar
Michael Pyne committed
760
761
762
763
764
765
# This function returns true if the given option doesn't make sense with the
# given module.
# blacklisted($module, $option)
sub blacklisted
{
    my ($module, $option) = @_;
766
767
768

    # Known to not work.
    my @unsermake_ban_list = qw/valgrind kde-common qt-copy kdebindings/;
Michael Pyne's avatar
Michael Pyne committed
769

770
    return list_has(@unsermake_ban_list, $module) if ($option eq 'use-unsermake');
Michael Pyne's avatar
Michael Pyne committed
771
772
773
    return 0;
}

774
775
776
777
778
779
780
781
782
783
784
785
# This subroutine returns an option value for a given module.  Some
# globals can't be overridden by a module's choice.  If so, the
# module's choice will be ignored, and a warning will be issued.
#
# Option names are case-sensitive!
#
# First parameter: Name of module
# Second paramenter: Name of option
sub get_option
{
    my $module = shift;
    my $option = shift;
786
    my $global_opts = $package_opts{'global'};
787
    my $defaultQtCopyArgs = '-qt-gif -plugin-imgfmt-mng -thread -no-exceptions -debug -dlopen-opengl -plugin-sql-sqlite';
788
    my @lockedOpts = qw(source-dir svn-server qtdir libpath binpath kdedir
Michael Pyne's avatar
Michael Pyne committed
789
                        pretend disable-agent-check);
790

Michael Pyne's avatar
Michael Pyne committed
791
    # These options can't override globals
792
    if (list_has(@lockedOpts, $option) or $module eq 'global')
Michael Pyne's avatar
Michael Pyne committed
793
    {
794
795
        return ${$global_opts}{"#$option"} if exists ${$global_opts}{"#$option"};
        return ${$global_opts}{$option};
Michael Pyne's avatar
Michael Pyne committed
796
    }
797

798
    # Don't even try this
Michael Pyne's avatar
Michael Pyne committed
799
800
801
802
803
804
805
806
    return 0 if blacklisted($module, $option);

    my $ref = $package_opts{$module};

    # Check for a sticky option
    return $$ref{"#$option"} if exists $$ref{"#$option"};

    # Next in order of precedence
807
    if (defined ${$global_opts}{"#$option"} and not 
808
809
        ($module eq 'qt-copy' and $option eq 'configure-flags'))
    {
810
        return ${$global_opts}{"#$option"};
811
    }
812

Michael Pyne's avatar
Michael Pyne committed
813
    # No sticky options left.
814
815
816
817
    # Configure flags and CXXFLAGS are appended to the global option
    if (($module ne 'qt-copy' && $option eq 'configure-flags')
        || $option eq 'cxxflags')
    {
818
        my $value = ${$global_opts}{$option};
Michael Pyne's avatar
Michael Pyne committed
819
820

        if(defined $$ref{$option})
821
        {
Michael Pyne's avatar
Michael Pyne committed
822
823
            my $modvalue = $$ref{$option};
            $value .= " $modvalue";
824
825
826
827
828
        }

        return $value;
    }

829
830
831
832
833
834
835
    # As always qt-copy has to be difficult
    if ($module eq 'qt-copy' and $option eq 'configure-flags')
    {
        return $defaultQtCopyArgs if not defined $$ref{$option};
        return $$ref{$option};
    }

836
837
    # Everything else overrides the global, unless of course it's not set.
    # If we're reading for global options, we're pretty much done.
Michael Pyne's avatar
Michael Pyne committed
838
    return $$ref{$option} if defined $$ref{$option};
839
    return ${$global_opts}{$option};
840
841
}

842
843
844
845
846
847
848
849
850
851
852
853
854
855
# Subroutine used to handle the checkout-only option.  It handles
# updating subdirectories of an already-checked-out module.
# First parameter is the module, all remaining parameters are subdirectories
# to check out.
#
# Returns 0 on success, non-zero on failure.
sub update_module_subdirectories
{
    my $module = shift;
    my $result;

    # If we have elements in @path, download them now
    for my $dir (@_)
    {
856
        info "\tUpdating g[$dir]";
857
        $result = run_svn($module, "svn-up-$dir", [ 'svn', 'up', $dir ]);
858
859
860
861
862
863
        return $result if $result;
    }

    return 0;
}

864
865
866
867
868
869
870
871
872
873
# Returns true if a module has a base component to their name (e.g. KDE/,
# extragear/, or playground).  Note that modules that aren't in trunk/KDE
# don't necessary meet this criteria (e.g. kdereview is a module itself).
sub has_base_module
{
    my $module = shift;

    return $module =~ /^(extragear|playground|KDE)(\/[^\/]+)?$/;
}

874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
# Subroutine to return the directory that a module will be stored in.
# NOTE: The return value is a hash. The key 'module' will return the final
# module name, the key 'path' will return the full path to the module. The
# key 'fullpath' will return their concatenation.
# For example, with $module == 'KDE/kdelibs', and no change in the dest-dir
# option, you'd get something like:
# {
#   'path'     => '/home/user/kdesvn/KDE',
#   'module'   => 'kdelibs',
#   'fullpath' => '/home/user/kdesvn/KDE/kdelibs'
# }
# If dest-dir were changed to e.g. extragear-multimedia, you'd get:
# {
#   'path'     => '/home/user/kdesvn',
#   'module'   => 'extragear-multimedia',
#   'fullpath' => '/home/user/kdesvn/extragear-multimedia'
# }
# First parameter is the module.
# Second parameter is either source or build.
sub get_module_path_dir
{
    my $module = shift;
    my $type = shift;
    my $destdir = get_dest_dir($module);
    my $srcbase = get_kdesvn_dir();
    $srcbase = get_build_dir($module) if $type eq 'build';

    my $combined = "$srcbase/$destdir";

    # Remove dup //
    $combined =~ s/\/+/\//;

    my @parts = split(/\//, $combined);
    my %result = ();
    $result{'module'} = pop @parts;
    $result{'path'} = join('/', @parts);
    $result{'fullpath'} = "$result{path}/$result{module}";

    return %result;
}

sub get_fullpath
{
    my ($module, $type) = @_;
    my %pathinfo = get_module_path_dir($module, $type);

    return $pathinfo{'fullpath'};
}

923
924
925
926
927
928
929
930
931
# Checkout a module that has not been checked out before, along with any
# subdirectories the user desires.
# The first parameter is the module to checkout (including extragear and
# playground modules), all remaining parameters are subdirectories of the
# module to checkout.
# Returns 0 on success, non-zero on failure.
sub checkout_module_path
{
    my ($module, @path) = @_;
932
    my %pathinfo = get_module_path_dir($module, 'source');
933
934
935
    my $result;
    my @args;

936
    if (not -e $pathinfo{'path'} and not super_mkdir($pathinfo{'path'}))
937
    {
938
        error "Unable to create path r[$pathinfo{path}]!";
939
        return 1;
940
941
    }

942
    chdir($pathinfo{'path'});
943
944
945
946

    push @args, ('svn', 'co');
    push @args, '-N' if scalar @path;
    push @args, svn_module_url($module);
947
    push @args, $pathinfo{'module'};
948

949
    note "Checking out g[$module]";
950
951
952
    $result = run_svn($module, 'svn-co', \@args);
    return $result if $result;

953
    chdir($pathinfo{'module'}) if scalar @path;
954
955
956
957
958
959
960
961
962
963
964
965
966

    return update_module_subdirectories($module, @path);
}

# Update a module that has already been checked out, along with any
# subdirectories the user desires.
# The first parameter is the module to checkout (including extragear and
# playground modules), all remaining parameters are subdirectories of the
# module to checkout.
# Returns 0 on success, non-zero on failure.
sub update_module_path
{
    my ($module, @path) = @_;
967
    my $fullpath = get_fullpath($module, 'source');
968
969
970
    my $result;
    my @args;

971
    chdir $fullpath;
972
973
974
975

    push @args, ('svn', 'up');
    push @args, '-N' if scalar @path;

976
    note "Updating g[$module]";
977

978
    $result = run_svn($module, 'svn-up', \@args);
979
980
981
982
983
984
985
986
987
988
989
990
991
992

    if($result) # Update failed, try svn cleanup.
    {
        info "\tUpdate failed, trying a cleanup.";
        $result = safe_system('svn', 'cleanup');

        return $result if $result;

        info "\tCleanup complete.";
        # Now try again.

        $result = run_svn($module, 'svn-up-2', \@args);
    }

993
994
995
996
997
    return $result if $result;

    # If the admin dir exists and is a soft link, remove it so that svn can
    # update it if need be.  The link will automatically be re-created later
    # in the process if necessary by the build functions.
998
    unlink ("$fullpath/admin") if -l "$fullpath/admin";
999
1000
1001
1002

    return update_module_subdirectories($module, @path);
}

1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
# Subroutine to run a command with redirected STDOUT and STDERR.  First parameter
# is name of the log file (relative to the log directory), and the
# second parameter is a reference to an array with the command and
# its arguments
sub log_command
{
    my $pid;
    my $module = shift;
    my $filename = shift;
    my @command = @{(shift)};
    my $logdir = get_log_dir($module);

1015
    debug "log_command(): Module $module, Command: ", join(' ', @command);
1016
1017
1018

    if (pretending)
    {
1019
        pretend "\tWould have run g[", join (' ', @command);
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
        return 0;
    }

    if ($pid = fork)
    {
        # Parent
        waitpid $pid, 0;

        # If the module fails building, set an internal flag in the module
        # options with the name of the log file containing the error message.
1030
1031
        my $result = $?;
        set_error_logfile($module, "$filename.log") if $result;
1032

1033
1034
1035
1036
1037
1038
1039
1040
        # If we are using the alias to a kdesvn-build function, it should have
        # already printed the error message, so clear out errno (but still
        # return failure status).
        if ($command[0] eq 'kdesvn-build')
        {
            $! = 0;
        }

1041
        return $result;
1042
1043
1044
1045
1046
1047
1048
    }
    else
    {
        # Child
        if (not defined $logdir or not -e $logdir)
        {
            # Error creating directory for some reason.
1049
            error "\tLogging to std out due to failure creating log dir.";
1050
1051
1052
1053
1054
1055
1056
1057
        }

        # Redirect stdout and stderr to the given file.
        if (not debugging)
        {
# Comment this out because it conflicts with make-install-prefix
#            open (STDIN, "</dev/null");
            open (STDOUT, ">$logdir/$filename.log") or do {
1058
1059
                error "Error opening $logdir/$filename.log for logfile.";
                # Don't abort, hopefully STDOUT still works.
1060
1061
1062
1063
1064
            };
        }
        else
        {
            open (STDOUT, "|tee $logdir/$filename.log") or do {
1065
1066
                error "Error opening pipe to tee command.";
                # Don't abort, hopefully STDOUT still works.
1067
1068
1069
            };
        }

1070
1071
1072
1073
        # Make sure we log everything.  If the command is svn, it is possible
        # that the client will produce output trying to get a password, so
        # don't redirect stderr in that case.
        open (STDERR, ">&STDOUT") unless $command[0] eq 'svn';
1074

1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
        # Call internal function, name given by $command[1]
        if($command[0] eq 'kdesvn-build')
        {
            debug "Calling $command[1]";

            my $cmd = $command[1];
            splice (@command, 0, 2); # Remove first two elements.

            no strict 'refs'; # Disable restriction on symbolic subroutines.
            if (not &{$cmd}(@command)) # Call sub
            {
                exit EINVAL;
            }

            exit 0;
        }

        # External command.
1093
        exec (@command) or do {
1094
1095
1096
1097
            my $cmd_string = join(' ', @command);
            error <<EOF;
r[b[Unable to execute "$cmd_string"]!
	$!
1098

1099
1100
1101
Please check your binpath setting (it controls the PATH used by kdesvn-build).
Currently it is set to g[$ENV{PATH}].
EOF
1102
1103
            # Don't use return, this is the child still!
            exit 1;
1104
1105
1106
1107
        };
    }
}

1108
1109
1110
1111
1112
1113
1114
1115
1116
# Subroutine to mark a file as being the error log for a module.  This also
# creates a symlink in the module log directory for easy viewing.
# First parameter is the module in question.
# Second parameter is the filename in the log directory of the error log.
sub set_error_logfile
{
    my ($module, $logfile) = @_;
    my $logdir = get_log_dir($module);

1117
1118
    return unless $logfile;

1119
1120
1121
1122
1123
1124
1125
1126
1127
    set_option($module, '#error-log-file', "$logdir/$logfile");

    # Setup symlink in the module log directory pointing to the appropriate
    # file.  Make sure to remove it first if it already exists.
    unlink("$logdir/error.log") if -l "$logdir/error.log";

    if(-e "$logdir/error.log")
    {
        # Maybe it was a regular file?
1128
        error "r[b[ * Unable to create symlink to error log file]";
1129
1130
1131
        return 0;
    }

1132
    symlink "$logdir/$logfile", "$logdir/error.log";
1133
1134
}

1135
1136
1137
1138
# Subroutine to run make/unsermake with redirected STDOUT and STDERR,
# and to process the percentage in unsermake (-p). First parameter
# is name of the log file (relative to the log directory), and the
# second parameter is a reference to an array with the command and
1139
# its arguments.
1140
1141
#
# TODO: This is a fork of log_command().  Find a way to re-merge them.
1142
# Returns 0 on success, non-zero on failure.
1143
1144
1145
1146
1147
1148
1149
sub run_make_command
{
    my $pid;
    my $module = shift;
    my $filename = shift;
    my @command = @{(shift)};
    my $logdir = get_log_dir($module);
Michael Pyne's avatar
Michael Pyne committed
1150
    my $isunsermake = $command[0] =~ 'unsermake';
1151

1152
1153
1154
1155
    # Don't print ANSI characters if we're not on a tty.  Also, automake
    # doesn't support printing output status.  Finally, we output the whole
    # log to screen when debugging which makes this useless.
    if (!$isunsermake or not -t STDERR or debugging)
1156
    {
1157
        return log_command($module, $filename, \@command);
1158
1159
    }

1160
1161
1162
1163
1164
1165
1166
1167
    # Make sure -p is in the unsermake flags, it's the whole reason for using
    # this function.
    if (!(grep /^(-p)|(--print-progress)$/, @command))
    {
        # Add in front of element 1, deleting 0 elements.
        splice @command, 1, 0, '-p';
    }

1168
1169
    if (pretending)
    {
1170
        pretend "\tWould have run g[", join (' ', @command);
1171
1172
1173
1174
1175
1176
        return 0;
    }

    $pid = open(CHILD, '-|');
    if ($pid)
    {
1177
        my $last = -1;
1178

1179
1180
1181
        while (<CHILD>)
        {
            chomp;
1182
1183
1184
1185

            # Update terminal (\e[K clears the line) if the percentage
            # changed.
            if (/([0-9]+)% (creating|compiling|linking)/)
1186
1187
1188
1189
1190
            {
                print STDERR "\r$1% \e[K" unless ($1 == $last);
                $last = $1;
            }
        }
1191

1192
        close(CHILD);
Michael Pyne's avatar
Michael Pyne committed
1193
        print STDERR "\r\e[K";
1194
1195
1196

        # If the module fails building, set an internal flag in the module
        # options with the name of the log file containing the error message.
1197
1198
        my $result = $?;
        set_error_logfile($module, "$filename.log") if $result;
1199

1200
        return $result;
1201
1202
1203
1204
1205
1206
1207
    }
    else
    {
        # Child
        if (not defined $logdir or not -e $logdir)
        {
            # Error creating directory for some reason.
1208
            error "\tLogging to standard output due to failure creating log dir.";
1209
1210
        }

1211
        open (STDOUT, "|tee $logdir/$filename.log") or do {
1212
            error "Error opening pipe to tee command."
1213
        };
1214
1215
1216
1217
1218

        # Make sure we log everything.
        open (STDERR, ">&STDOUT");

        exec (@command) or do {
1219
1220
1221
1222
            my $cmd_string = join(' ', @command);
            error <<EOF;
r[b[Unable to execute "$cmd_string"]!
	$!
1223

1224
1225
1226
Please check your binpath setting (it controls the PATH used by kdesvn-build).
Currently it is set to g[$ENV{PATH}].
EOF
1227
1228
            # Don't return, we're still in the child!
            exit 1;
1229
1230
1231
1232
        };
    }
}

1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
# Subroutine to determine if the given subdirectory of a module can actually be
# built or not.  For instance, /admin can never be built, and the /kalyptus subdir
# of kdebindings can't either.
sub is_subdir_buildable
{
    my ($module, $dir) = @_;

    return 0 if $dir eq 'admin';
    return 0 if $dir eq 'kalyptus' and $module eq 'kdebindings';
    return 1;
}

1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
# Subroutine to return the path to the given executable based on the current
# binpath settings.  e.g. if you pass make you could get '/usr/bin/make'.  If
# the executable is not found undef is returned.
#
# This assumes that the module environment has already been updated since
# binpath doesn't exactly correspond to $ENV{'PATH'}.
sub path_to_prog
{
    my $prog = shift;
    my @paths = split(/:/, $ENV{'PATH'});

    # If it starts with a / the path is already absolute.
    return $prog if $prog =~ /^\//;

    for my $path (@paths)
    {
        return "$path/$prog" if (-x "$path/$prog");
    }

    return undef;
}

1267
1268
1269
1270
1271
1272
1273
1274
# Subroutine to run the make command with the arguments given by the passed
# list.  The first argument of the list given must be the module that we're
# making.  The second argument is the "try number", used in creating the log
# file name.
#
# Returns 0 on success, non-zero on failure (shell script style)
sub safe_make (@)
{
1275
    my ($module, $trynumber, $apidox, @args) = @_;
1276
    my $opts;
1277
1278
1279
1280
1281
1282
    my $logdir = get_log_dir($module);
    my $checkout_dirs = get_option($module, "checkout-only");
    my @dirs = split(' ', $checkout_dirs);
    my $installing = $trynumber eq 'install';
    my $make = 'make';

1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
    if (get_option($module, 'use-unsermake'))
    {
        $make = get_option('global', 'unsermake-path');
        $opts = get_option($module, 'unsermake-options');
    }
    else
    {
        $opts = get_option($module, 'make-options');
    }

1293
1294
1295
    # Convert the path to an absolute path since I've encountered a sudo that
    # is apparently unable to guess.  Maybe it's better that it doesn't guess
    # anyways from a security point-of-view.
1296
    $make = path_to_prog($make) unless pretending;
1297
1298
1299
1300
1301

    if(not defined $make)
    {
        # Weird, we can't find make, you'd think configure would have
        # noticed...
1302
        error " r[b[*] Unable to find the g[make] executable!";
1303
1304
1305
1306
1307
1308
1309

        # Make sure we don't bother trying again, this is a more serious
        # error.
        set_option($module, "#was-rebuilt", 1);
        return 1;
    }

1310
1311
1312
    # Add make-options to the given options, as long as we're not installing
    # If we are installing, unsermake seems to assume that the options are a
    # make target, and parallel builds don't help with installing anyways.
1313
1314
1315
    unshift (@args, split(' ', $opts)) unless $installing;

    my $description;
1316
1317

    # Check if we're installing
1318
    if($installing)
1319
    {
1320
        debug "Prepending install options, apidox: $apidox.";
1321
1322
1323
1324
1325

        $description = $apidox ? "API Documentation" : clr "g[$module]";
        unshift @args, $make, $apidox ? 'install-apidox' : 'install';
        unshift @args, split(' ', get_option ($module, 'make-install-prefix'));

1326
        info "\tInstalling $description.";
1327
1328
1329
    }
    else
    {
1330
1331
        $description = "Building API Documentation";
        $description = "Compiling, attempt $trynumber" unless $apidox;
1332

1333
1334
        push @args, 'apidox' if $apidox;
        unshift @args, $make;
1335

1336
        info "\t$description...";
1337
    }
1338

1339
1340
    push (@dirs, "") if scalar @dirs == 0;
    for my $subdir (@dirs)
1341
    {
1342
1343
        # Some subdirectories shouldn't have make run within them.
        next unless is_subdir_buildable($module, $subdir);
1344

1345
1346
1347
1348
1349
1350
        my $logname = "build-$trynumber";
        if ($installing)
        {
            $logname = $apidox ? 'install-apidox' : 'install';
        }

1351
1352
1353
        if ($subdir ne '')
        {
            $logname = $installing ? "install-$subdir" : "build-$subdir-$trynumber";
1354
1355
            next if $apidox; # Don't built apidox in a subdirectory

1356
            info $installing ? "\tInstalling " : "\tBuilding ", "subdirectory g[$subdir]";
1357
1358
        }

1359
1360
1361
1362
1363
        my %pathinfo = get_module_path_dir($module, 'build');
        my $builddir = "$pathinfo{fullpath}/$subdir";
        $builddir =~ s/\/*$//;

        chdir ($builddir);
1364

1365
        my $result = run_make_command ($module, $logname, \@args );
1366
        return $result if $result;
1367
    };
1368
1369
1370
1371
1372
1373
1374
1375
1376

    return 0;
}

# Subroutine to add a variable to the environment, but ONLY if it
# is set. First parameter is the variable to set, the second is the
# value to give it.
sub setenv
{
Michael Pyne's avatar
Michael Pyne committed
1377
    my ($var, $val) = @_;
1378
1379
1380

    return unless $val;

1381
    pretend "\tWould have set g[$var]=y[$val].";
1382
1383

    $ENV{$var} = $val;
1384
1385
}

1386
1387
1388
1389
# Display a message to the user regarding their relative lack of
# ~/.kdesvn-buildrc, and point them to some help.  We will continue using a
# default set of options.
sub no_config_whine
1390
{
1391
    my $searched = join("\n    ", @rcfiles);
1392
    my $homepage = "http://kdesvn-build.kde.org/";
1393

1394
    note <<"HOME";
1395
1396
1397
Unable to open configuration file!
We looked for:
    $searched
1398

1399
1400
1401
kdesvn-build will continue using a default set of options.  These options may
not apply to you, so feel free to visit the kdesvn-build homepage

1402
b[g[$homepage]
1403
1404
1405

and use the configuration file generator to guide you through the process of
creating a config file to customize your kdesvn-build process.
1406
1407

HOME
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
}

# This subroutine assigns the appropriate options to %package_opts and the
# update and build lists to build a default set of modules.
sub setup_default_modules()
{
    @update_list = qw(qt-copy arts kdesupport kdelibs kdebase kdeartwork
                      kdemultimedia kdepim kdeutils kdegraphics kdegames
                      kdetoys kdeedu kdeaddons);
    @build_list = @update_list;

    for my $i (@update_list) {
Michael Pyne's avatar
Michael Pyne committed
1420
1421
1422
1423
1424
        if (not exists $package_opts{$i})
        {
            $package_opts{$i} = { }; # Set up defaults
            $package_opts{$i}{'set-env'} = { };
        }
1425
1426
1427
1428
1429
1430
1431
1432
    }

    # Setup default options for qt-copy
    $package_opts{'qt-copy'} = {
        'conf-flags' => q(-system-zlib -qt-gif -system-libjpeg -system-libpng
                          -plugin-imgfmt-mng -thread -no-exceptions -debug
                          -dlopen-opengl),
        'apply-qt-patches' => 'true',
1433
1434
1435
1436

# See setup_kde35_hack() for why this option is here.
        'module-base-path' => 'branches/qt/3.3',

1437
1438
        'use-qt-builddir-hack' => 'true',
        'use-unsermake' => 0,
1439
        'set-env' => { },
1440
    };
1441
1442
1443

    # That handy q() construct above kept the newlines, I don't want them.
    $package_opts{'qt-copy'}{'conf-flags'} =~ s/\s+/ /gm;
1444
1445
}

1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
# Reads in the options from the config file and adds them to the option store.
# The first parameter is a reference to the file handle to read from.
# The second parameter is 'global' if we're reading the global section, or
# 'module' if we should expect an end module statement.
sub parse_module
{
    my ($fh, $module) = @_;
    $module = 'global' unless $module;

    # Make sure we acknowledge that we read the module name in from the
    # file.
    if (not defined $package_opts{$module})
    {
        $package_opts{$module} = {
            'set-env' => { }
        };
    }

    # Read in each option
    while (<$fh>)
    {
1467
1468
1469
1470
1471
1472
1473
1474
1475
        # Handle line continuation
        chomp;

        if(s/\\\s*$//)  # Replace \ followed by optional space at EOL and try again.
        {
            $_ .= <$fh>;
            redo unless eof($fh);
        }

1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
        s/#.*$//;       # Remove comments
        next if /^\s*$/;   # Skip blank lines

        if($module eq 'global')
        {
            last if /^end\s+global/; # Stop
        }
        else
        {
            last if /^end\s+module/; # Stop
        }

        # The option is the first word, followed by the
        # flags on the rest of the line.  The interpretation
        # of the flags is dependant on the option.
1491