~ubuntu-branches/ubuntu/precise/gtk-qt-engine/precise

« back to all changes in this revision

Viewing changes to admin/am_edit

  • Committer: Bazaar Package Importer
  • Author(s): Christoffer Sawicki
  • Date: 2005-01-02 22:24:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050102222409-2wsno0q9ywn0ac2e
Tags: upstream-0.60
ImportĀ upstreamĀ versionĀ 0.60

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
 
 
3
# Expands the specialised KDE tags in Makefile.in to (hopefully) valid
 
4
# make syntax.
 
5
# When called without file parameters, we work recursively on all Makefile.in
 
6
# in and below the current subdirectory. When called with file parameters,
 
7
# only those Makefile.in are changed.
 
8
# The currently supported tags are
 
9
#
 
10
# {program}_METASOURCES
 
11
# where you have a choice of two styles
 
12
#   {program}_METASOURCES = name1.moc name2.moc ... [\]
 
13
#   {program}_METASOURCES = AUTO
 
14
#       The second style requires other tags as well.
 
15
#
 
16
# To install icons :
 
17
#    KDE_ICON = iconname iconname2 ...
 
18
#    KDE_ICON = AUTO
 
19
#
 
20
# For documentation :
 
21
#    http://developer.kde.org/documentation/other/developer-faq.html
 
22
#
 
23
# and more new tags TBD!
 
24
#
 
25
# The concept (and base code) for this program came from automoc,
 
26
# supplied by the following
 
27
#
 
28
# Matthias Ettrich <ettrich@kde.org>      (The originator)
 
29
# Kalle Dalheimer <kalle@kde.org>      (The original implementator)
 
30
# Harri Porten  <porten@tu-harburg.de>
 
31
# Alex Zepeda  <jazepeda@pacbell.net>
 
32
# David Faure <faure@kde.org>
 
33
# Stephan Kulow <coolo@kde.org>
 
34
# Dirk Mueller <mueller@kde.org>
 
35
 
 
36
use Cwd;
 
37
use File::Find;
 
38
use File::Basename;
 
39
 
 
40
# Prototype the functions
 
41
sub initialise ();
 
42
sub processMakefile ($);
 
43
sub updateMakefile ();
 
44
sub restoreMakefile ();
 
45
 
 
46
sub removeLine ($$);
 
47
sub appendLines ($);
 
48
sub substituteLine ($$);
 
49
 
 
50
sub findMocCandidates ();
 
51
sub pruneMocCandidates ($);
 
52
sub checkMocCandidates ();
 
53
sub addMocRules ();
 
54
sub findKcfgFile($);
 
55
 
 
56
sub tag_AUTOMAKE ();
 
57
sub tag_META_INCLUDES ();
 
58
sub tag_METASOURCES ();
 
59
sub tag_POFILES ();
 
60
sub tag_DOCFILES ();
 
61
sub tag_LOCALINSTALL();
 
62
sub tag_IDLFILES();
 
63
sub tag_UIFILES();
 
64
sub tag_KCFGFILES();
 
65
sub tag_SUBDIRS();
 
66
sub tag_ICON();
 
67
sub tag_CLOSURE();
 
68
sub tag_NO_UNDEFINED();
 
69
sub tag_NMCHECK();
 
70
sub tag_DIST();
 
71
sub tag_KDEINIT();
 
72
 
 
73
# Some global globals...
 
74
$verbose    = 0;        # a debug flag
 
75
$thisProg   = "$0";     # This programs name
 
76
$topdir     = cwd();    # The current directory
 
77
@makefiles  = ();       # Contains all the files we'll process
 
78
@foreignfiles = ();
 
79
$start      = (times)[0]; # some stats for testing - comment out for release
 
80
$version    = "v0.2";
 
81
$errorflag  = 0;
 
82
$cppExt     = "(cpp|cc|cxx|C|c\\+\\+)";
 
83
$hExt       = "(h|H|hh|hxx|hpp|h\\+\\+)";
 
84
$progId     = "KDE tags expanded automatically by " . basename($thisProg);
 
85
$automkCall = "\n";
 
86
$printname  = "";  # used to display the directory the Makefile is in
 
87
$use_final  = 1;        # create code for --enable-final
 
88
$cleantarget = "clean";
 
89
$dryrun     = 0;
 
90
$pathoption = 0;
 
91
$foreign_libtool = 0;
 
92
 
 
93
while (defined ($ARGV[0]))
 
94
{
 
95
    $_ = shift;
 
96
    if (/^--version$/)
 
97
    {
 
98
        print STDOUT "\n";
 
99
        print STDOUT basename($thisProg), " $version\n",
 
100
                "This is really free software, unencumbered by the GPL.\n",
 
101
                "You can do anything you like with it except sueing me.\n",
 
102
                "Copyright 1998 Kalle Dalheimer <kalle\@kde.org>\n",
 
103
                "Concept, design and unnecessary questions about perl\n",
 
104
                "       by Matthias Ettrich <ettrich\@kde.org>\n\n",
 
105
                "Making it useful by Stephan Kulow <coolo\@kde.org> and\n",
 
106
                "Harri Porten <porten\@kde.org>\n",
 
107
                "Updated (Feb-1999), John Birch <jb.nz\@writeme.com>\n",
 
108
                "Fixes and Improvements by Dirk Mueller <mueller\@kde.org>\n",
 
109
                "Current Maintainer Stephan Kulow\n\n";
 
110
        exit 0;
 
111
    }
 
112
    elsif (/^--verbose$|^-v$/)
 
113
    {
 
114
        $verbose = 1;       # Oh is there a problem...?
 
115
    }
 
116
    elsif (/^(?:-p|--path=)(.+)$/)
 
117
    {
 
118
        my $p = $1;
 
119
        $thisProg = $p . "/". basename($thisProg);
 
120
        warn ("$thisProg doesn't exist\n")      if (!(-f $thisProg));
 
121
        $thisProg .= " -p".$p;
 
122
        $pathoption=1;
 
123
    }
 
124
    elsif (/^--help$|^-h$/)
 
125
    {
 
126
        print STDOUT "Usage $thisProg [OPTION] ... [dir/Makefile.in]...\n",
 
127
                "\n",
 
128
                "Patches dir/Makefile.in generated by automake\n",
 
129
                "(where dir can be an absolute or relative directory name)\n",
 
130
                "\n",
 
131
                "  -v, --verbose      verbosely list files processed\n",
 
132
                "  -h, --help         print this help, then exit\n",
 
133
                "  --version          print version number, then exit\n",
 
134
                "  -p, --path=        use the path to am_edit if the path\n",
 
135
                "                     called from is not the one to be used\n",
 
136
                "  --no-final         don't patch for --enable-final\n";
 
137
        
 
138
        exit 0;
 
139
    }
 
140
    elsif (/^--no-final$/)
 
141
    {
 
142
        $use_final = 0;
 
143
        $thisProg .= " --no-final";
 
144
    }
 
145
    elsif (/^--foreign-libtool$/)
 
146
    {
 
147
        $foreign_libtool = 1;
 
148
        $thisProg .= " --foreign-libtool";
 
149
    }
 
150
    elsif (/^-n$/)
 
151
    {
 
152
        $dryrun = 1;
 
153
    }
 
154
    else
 
155
    {
 
156
        # user selects what input files to check
 
157
        # add full path if relative path is given
 
158
        $_ = cwd()."/".$_   if (! /^\//);
 
159
        print "User wants $_\n" if ($verbose);
 
160
        push (@makefiles, $_);
 
161
    }
 
162
}
 
163
 
 
164
if ($thisProg =~ /^\// && !$pathoption )
 
165
{
 
166
  print STDERR "Illegal full pathname call performed...\n",
 
167
      "The call to \"$thisProg\"\nwould be inserted in some Makefile.in.\n",
 
168
      "Please use option --path.\n";
 
169
  exit 1;
 
170
}
 
171
 
 
172
# Only scan for files when the user hasn't entered data
 
173
if (!@makefiles)
 
174
{
 
175
    print STDOUT "Scanning for Makefile.in\n"       if ($verbose);
 
176
    find (\&add_makefile, cwd());
 
177
    #chdir('$topdir');
 
178
} else {
 
179
    print STDOUT "Using input files specified by user\n"   if ($verbose);
 
180
}
 
181
 
 
182
foreach $makefile (sort(@makefiles))
 
183
{
 
184
    processMakefile ($makefile);
 
185
    last            if ($errorflag);
 
186
}
 
187
 
 
188
# Just some debug statistics - comment out for release as it uses printf.
 
189
printf STDOUT "Time %.2f CPU sec\n", (times)[0] - $start     if ($verbose);
 
190
 
 
191
exit $errorflag;        # causes make to fail if erroflag is set
 
192
 
 
193
#-----------------------------------------------------------------------------
 
194
 
 
195
# In conjunction with the "find" call, this builds the list of input files
 
196
sub add_makefile ()
 
197
{
 
198
  push (@makefiles, $File::Find::name) if (/Makefile.in$/);
 
199
}
 
200
 
 
201
#-----------------------------------------------------------------------------
 
202
 
 
203
# Processes a single make file
 
204
# The parameter contains the full path name of the Makefile.in to use
 
205
sub processMakefile ($)
 
206
{
 
207
    # some useful globals for the subroutines called here
 
208
    local ($makefile)       = @_;
 
209
    local @headerdirs       = ('.');
 
210
    local $haveAutomocTag   = 0;
 
211
    local $MakefileData     = "";
 
212
 
 
213
    local $cxxsuffix  = "KKK";
 
214
 
 
215
    local @programs = ();  # lists the names of programs and libraries
 
216
    local $program = "";
 
217
 
 
218
    local @kdeinits = (); # lists the kdeinit targets
 
219
 
 
220
    local %realObjs = ();  # lists the objects compiled into $program
 
221
    local %sources = ();   # lists the sources used for $program
 
222
    local %finalObjs = (); # lists the objects compiled when final
 
223
    local %realname = ();  # the binary name of program variable
 
224
    local %idlfiles = ();  # lists the idl files used for $program
 
225
    local %globalmocs = ();# list of all mocfiles (in %mocFiles format)
 
226
    local %important = (); # list of files to be generated asap
 
227
    local %uiFiles = ();
 
228
    local %kcfgFiles = ();
 
229
 
 
230
    local $allidls = "";
 
231
    local $idl_output = "";# lists all idl generated files for cleantarget
 
232
    local $ui_output = "";# lists all uic generated files for cleantarget
 
233
    local $kcfg_output = "";# lists all kcfg generated files for cleantarget
 
234
 
 
235
    local %dependmocs = ();
 
236
    
 
237
    local $metasourceTags = 0;
 
238
    local $dep_files      = "";
 
239
    local $dep_finals     = "";
 
240
    local %target_adds    = (); # the targets to add
 
241
    local %rule_adds      = ();
 
242
    local $kdelang        = "";
 
243
    local @cleanfiles     = ();
 
244
    local $cleanMoc       = "";
 
245
    local $closure_output = "";
 
246
 
 
247
    local %varcontent     = ();
 
248
 
 
249
    $makefileDir = dirname($makefile);
 
250
    chdir ($makefileDir);
 
251
    $printname = $makefile;
 
252
    $printname =~ s/^\Q$topdir\E\///;
 
253
    $makefile = basename($makefile);
 
254
 
 
255
    print STDOUT "Processing makefile $printname\n"   if ($verbose);
 
256
 
 
257
    # Setup and see if we need to do this.
 
258
    return      if (!initialise());
 
259
 
 
260
    tag_AUTOMAKE ();            # Allows a "make" to redo the Makefile.in
 
261
    tag_META_INCLUDES ();       # Supplies directories for src locations
 
262
 
 
263
    foreach $program (@programs) {
 
264
        $sources_changed{$program} = 0;
 
265
        $dependmocs{$program} = "";
 
266
        $important{$program} = "";
 
267
        tag_IDLFILES();             # Sorts out idl rules
 
268
        tag_NO_UNDEFINED();
 
269
        tag_CLOSURE();
 
270
        tag_NMCHECK();
 
271
        tag_UIFILES();              # Sorts out ui rules
 
272
        tag_KCFGFILES();            # Sorts out kcfg rules
 
273
        tag_METASOURCES ();         # Sorts out the moc rules
 
274
        if ($sources_changed{$program}) {
 
275
            my $lookup = $program . '_SOURCES\s*=[ \t]*(.*)';
 
276
 
 
277
            if($program =~ /libkdeinit_(.*)/) {
 
278
                my $prog = $1;
 
279
                substituteLine($prog . '_SOURCES\s*=[ \t]*(.*)', 
 
280
                    "${prog}_SOURCES = ${prog}_dummy.$cxxsuffix\n" .
 
281
                    "libkdeinit_${prog}_SOURCES = " . $sources{$program});
 
282
                $sources{$prog} = "${prog}_dummy.$cxxsuffix";
 
283
            }
 
284
            else {
 
285
                substituteLine($lookup, "$program\_SOURCES=" . $sources{$program});
 
286
            }
 
287
        }
 
288
        if ($important{$program}) {
 
289
            local %source_dict = ();
 
290
            for $source (split(/[\034\s]+/, $sources{$program})) {
 
291
                $source_dict{$source} = 1;
 
292
            }
 
293
            for $source (@cleanfiles) {
 
294
                $source_dict{$source} = 0;
 
295
            }
 
296
            for $source (keys %source_dict) {
 
297
                next if (!$source);
 
298
                if ($source_dict{$source}) {
 
299
                    # sanity check
 
300
                    if (! -f $source) {
 
301
                        print STDERR "Error: $source is listed in a _SOURCE line in $printname, but doesn't exist yet. Put it in DISTCLEANFILES!\n";
 
302
                    } else {
 
303
                        $target_adds{"\$(srcdir)/$source"} .= $important{$program};
 
304
                    }
 
305
                }
 
306
            }
 
307
        }
 
308
    }
 
309
    if ($cleanMoc) {
 
310
        # Always add dist clean tag
 
311
        # Add extra *.moc.cpp files created for USE_AUTOMOC because they
 
312
        # aren't included in the normal *.moc clean rules.
 
313
        appendLines ("$cleantarget-metasources:\n\t-rm -f $cleanMoc\n");
 
314
        $target_adds{"$cleantarget-am"} .= "$cleantarget-metasources ";
 
315
    }
 
316
    
 
317
    tag_DIST() unless ($kdeopts{"noautodist"});
 
318
 
 
319
    if ($idl_output) {
 
320
        appendLines ("$cleantarget-idl:\n\t-rm -f $idl_output\n");
 
321
        $target_adds{"$cleantarget-am"} .= "$cleantarget-idl ";
 
322
    }
 
323
 
 
324
    if ($ui_output) {
 
325
        appendLines ("$cleantarget-ui:\n\t-rm -f $ui_output\n");
 
326
        $target_adds{"$cleantarget-am"} .= "$cleantarget-ui ";
 
327
    }
 
328
 
 
329
    if ($kcfg_output) {
 
330
        appendLines ("$cleantarget-kcfg:\n\t-rm -f $kcfg_output\n");
 
331
        $target_adds{"$cleantarget-am"} .= "$cleantarget-kcfg ";
 
332
    }
 
333
 
 
334
    if ($closure_output) {
 
335
        appendLines ("$cleantarget-closures:\n\t-rm -f $closure_output\n");
 
336
        $target_adds{"$cleantarget-am"} .= "$cleantarget-closures ";
 
337
    }
 
338
 
 
339
    if ($MakefileData =~ /\nKDE_LANG\s*=\s*(\S*)\s*\n/) {
 
340
        $kdelang = '$(KDE_LANG)'
 
341
    } else {
 
342
        $kdelang = '';
 
343
    }
 
344
 
 
345
    tag_POFILES ();             # language rules for po directory
 
346
    tag_DOCFILES ();            # language rules for doc directories
 
347
    tag_LOCALINSTALL();         # add $(DESTDIR) before all kde_ dirs
 
348
    tag_ICON();
 
349
    tag_SUBDIRS();
 
350
 
 
351
    my $tmp = "force-reedit:\n";
 
352
    $tmp   .= "\t$automkCall\n\tcd \$(top_srcdir) && perl $thisProg $printname\n\n";
 
353
    appendLines($tmp);
 
354
    
 
355
    make_bcheck_target();
 
356
    make_meta_classes();
 
357
    tag_COMPILE_FIRST();
 
358
    tag_FINAL() if (!$kdeopts{"nofinal"});
 
359
 
 
360
    my $final_lines = "final:\n\t\$(MAKE) ";
 
361
    my $final_install_lines = "final-install:\n\t\$(MAKE) ";
 
362
    my $nofinal_lines = "no-final:\n\t\$(MAKE) ";
 
363
    my $nofinal_install_lines = "no-final-install:\n\t\$(MAKE) ";
 
364
 
 
365
    foreach $program (@programs) {
 
366
        my $lookup = $program . '_OBJECTS\s*=[ \t]*.*';
 
367
        my $new = "";
 
368
        my @list = split(/[\034\s]+/, $realObjs{$program});
 
369
        if (!$kdeopts{"nofinal"} && @list > 1 && $finalObjs{$program}) {
 
370
            $new .= "$program\_final\_OBJECTS = " . $finalObjs{$program};
 
371
            $new .= "\n$program\_nofinal\_OBJECTS = " . $realObjs{$program};
 
372
            $new .= "\n\@KDE_USE_FINAL_FALSE\@$program\_OBJECTS = \$($program\_nofinal\_OBJECTS)";
 
373
            $new .= "\n\@KDE_USE_FINAL_TRUE\@$program\_OBJECTS = \$($program\_final\_OBJECTS)";
 
374
 
 
375
            $final_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" ";
 
376
            $final_install_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" ";
 
377
            $nofinal_lines .= "$program\_OBJECTS=\"\$($program\_nofinal\_OBJECTS)\" ";
 
378
            $nofinal_install_lines .= "$program\_OBJECTS=\"\$($program\_nofinal_OBJECTS)\" ";
 
379
        } else {
 
380
            $new = "$program\_OBJECTS = " . $realObjs{$program};
 
381
        }
 
382
        if($MakefileData =~ m/\n$lookup/) {
 
383
            substituteLine ($lookup, $new);
 
384
        }
 
385
        else {
 
386
            appendLines("$new\n");
 
387
        }
 
388
    }
 
389
    appendLines($final_lines . "all-am\n");
 
390
    appendLines($final_install_lines . "install-am\n");
 
391
    appendLines($nofinal_lines . "all-am\n");
 
392
    appendLines($nofinal_install_lines . "install-am\n");
 
393
 
 
394
    my $lookup = '(\@\S+\@)?DEP_FILES\s*=[ \t]*(.*)';
 
395
    if ($MakefileData =~ /\n$lookup/) {
 
396
        my $condition = $1;
 
397
        my $depfiles = $2;
 
398
        my $workfiles;
 
399
 
 
400
        if ($dep_finals) {
 
401
            # Add the conditions on every line, since
 
402
            # there may be line continuations in the list.
 
403
            $workfiles = "$dep_files $dep_finals $depfiles";
 
404
            $workfiles =~ s/\034/\034$condition\@KDE_USE_FINAL_TRUE\@\t/g;
 
405
            $lines  = "$condition\@KDE_USE_FINAL_TRUE\@DEP_FILES = $workfiles\n";
 
406
            $workfiles = "$dep_files $depfiles";
 
407
            $workfiles =~ s/\034/\034$condition\@KDE_USE_FINAL_FALSE\@\t/g;
 
408
            $lines .= "$condition\@KDE_USE_FINAL_FALSE\@DEP_FILES = $workfiles";
 
409
        } else {
 
410
            $workfiles = "$dep_files $depfiles";
 
411
            $workfiles =~ s/\034/\034$condition\t/g;
 
412
            $lines = $condition . "DEP_FILES = $workfiles";
 
413
        }
 
414
        substituteLine($lookup, $lines);
 
415
    }
 
416
 
 
417
    # new recursive targets
 
418
    $target_adds{ "nmcheck" } .= ""; # always create nmcheck target
 
419
    $target_adds{ "nmcheck-am" } .= "nmcheck";
 
420
    $lookup = 'RECURSIVE_TARGETS\s*=[ \t]*(.*)';
 
421
    if ($MakefileData =~ /\n$lookup/) {
 
422
      substituteLine($lookup, "RECURSIVE_TARGETS = $1 nmcheck-recursive bcheck-recursive");
 
423
    }
 
424
 
 
425
    my $cvs_lines = "cvs-clean:\n";
 
426
    $cvs_lines .= "\t\$(MAKE) admindir=\$(top_srcdir)/admin -f \$(top_srcdir)/admin/Makefile.common cvs-clean\n";
 
427
    appendLines($cvs_lines);
 
428
 
 
429
    $cvs_lines  = "kde-rpo-clean:\n";
 
430
    $cvs_lines .= "\t-rm -f *.rpo\n";
 
431
    appendLines($cvs_lines);
 
432
    $target_adds{"clean"} .= "kde-rpo-clean ";
 
433
 
 
434
    my %target_dels = ("install-data-am" => "");
 
435
 
 
436
    # some strange people like to do a install-exec, and expect that also
 
437
    # all modules are installed.  automake doesn't know this, so we need to move
 
438
    # this here from install-data to install-exec.
 
439
    if ($MakefileData =~ m/\nkde_module_LTLIBRARIES\s*=/) {
 
440
#      $target_adds{"install-exec-am"} .= "install-kde_moduleLTLIBRARIES ";
 
441
#      don't use $target_adds here because we need to append the dependency, not
 
442
#      prepend it. Fixes #44342 , when a module depends on a lib in the same dir
 
443
#      and libtool needs it during relinking upon install (Simon)
 
444
      my $lookup = "install-exec-am:([^\n]*)";
 
445
      if($MakefileData =~ /\n$lookup\n/) {
 
446
        substituteLine("$lookup", "install-exec-am: $1 install-kde_moduleLTLIBRARIES");
 
447
      }
 
448
      $target_dels{"install-data-am"} .= "install-kde_moduleLTLIBRARIES ";
 
449
      $target_adds{"install-data-am"} .= " ";
 
450
    }
 
451
 
 
452
    my $lines = "";
 
453
 
 
454
    foreach $add (keys %target_adds) {
 
455
        my $lookup = quotemeta($add) . ':([^\n]*)';
 
456
        if ($MakefileData =~ /\n$lookup\n/) {
 
457
          my $newlines = $1;
 
458
          my $oldlines = $lookup;
 
459
          if (defined $target_dels{$add}) {
 
460
            foreach $del (split(' ', $target_dels{$add})) {
 
461
              $newlines =~ s/\s*$del\s*/ /g;
 
462
            }
 
463
          }
 
464
          substituteLine($oldlines, "$add: " . $target_adds{$add} . $newlines);
 
465
        } else {
 
466
          $lines .= "$add: " . $target_adds{$add} . "\n";
 
467
        }
 
468
    }
 
469
 
 
470
    appendLines($lines) if ($lines);
 
471
 
 
472
    $lines = join("\n", values %rule_adds);
 
473
    appendLines($lines) if ($lines);
 
474
 
 
475
    my $found = 1;
 
476
 
 
477
    while ($found) {
 
478
        if ($MakefileData =~ m/\n(.*)\$\(CXXFLAGS\)(.*)\n/) {
 
479
            my $stuff_before = $1;
 
480
            my $stuff_after = $2;
 
481
            my $lookup = quotemeta("$1\$(CXXFLAGS)$2");
 
482
            my $replacement = "$1\$(KCXXFLAGS)$2";
 
483
            $MakefileData =~ s/$lookup/$replacement/;
 
484
            $lookup =~ s/\\\$\\\(CXXFLAGS\\\)/\\\$\\\(KCXXFLAGS\\\)/;
 
485
            $replacement = "$stuff_before\$(KCXXFLAGS) \$(KDE_CXXFLAGS)$stuff_after";
 
486
            substituteLine($lookup, $replacement);
 
487
        } else {
 
488
            $found = 0;
 
489
        }
 
490
    }
 
491
 
 
492
    if($foreign_libtool == 0) {
 
493
        $lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=link) (\$\(CXXLD\).*\$\(KCXXFLAGS\))';
 
494
 
 
495
        if ($MakefileData =~ m/$lookup/ ) {
 
496
            $MakefileData =~ s/$lookup/$1 --tag=CXX $2/;
 
497
        }
 
498
 
 
499
        $lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=compile)\s+(\$\(CXX\)\s+)';
 
500
        if ($MakefileData =~ m/$lookup/ ) {
 
501
            $MakefileData =~ s/$lookup/$1 --tag=CXX $2/;
 
502
        }
 
503
    }
 
504
 
 
505
    $MakefileData =~ s/\$\(KCXXFLAGS\)/\$\(CXXFLAGS\)/g;
 
506
 
 
507
    $lookup = '(.*)cp -pr \$\$/\$\$file \$\(distdir\)/\$\$file(.*)';
 
508
    if ($MakefileData =~ m/\n$lookup\n/) {
 
509
        substituteLine($lookup, "$1cp -pr \$\$d/\$\$file \$(distdir)/\$\$file$2");
 
510
    }
 
511
 
 
512
    # Always update the Makefile.in
 
513
    updateMakefile ();
 
514
    return;
 
515
}
 
516
 
 
517
#-----------------------------------------------------------------------------
 
518
 
 
519
# Beware: This procedure is not complete.  E.g. it also parses lines
 
520
# containing a '=' in rules (for instance setting shell vars).  For our
 
521
# usage this us enough, though.
 
522
sub read_variables ()
 
523
{
 
524
    while ($MakefileData =~ /\n\s*(\S+)\s*=([^\n]*)/g) {
 
525
        $varcontent{$1} = $2;
 
526
    }
 
527
}
 
528
 
 
529
# Check to see whether we should process this make file.
 
530
# This is where we look for tags that we need to process.
 
531
# A small amount of initialising on the tags is also done here.
 
532
# And of course we open and/or create the needed make files.
 
533
sub initialise ()
 
534
{
 
535
    if (! -r "Makefile.am") {
 
536
        print STDOUT "found Makefile.in without Makefile.am\n" if ($verbose);
 
537
        return 0;
 
538
    }
 
539
 
 
540
    # Checking for files to process...
 
541
 
 
542
    open (FILEIN, $makefile) || die "Can't open $makefileDir/$makefile: $!\n";
 
543
    # perl bug in 5.8.0: in utf8 mode it badly screws up
 
544
    binmode(FILEIN, ":bytes") if ($] >= 5.008);
 
545
    # Read the file
 
546
    # stat(FILEIN)[7] might look more elegant, but is slower as it 
 
547
    # requires stat'ing the file
 
548
    seek(FILEIN, 0, 2);
 
549
    my $fsize = tell(FILEIN);
 
550
    seek(FILEIN, 0, 0);
 
551
    read FILEIN, $MakefileData, $fsize;
 
552
    close FILEIN;
 
553
    print "DOS CRLF within $makefileDir/$makefile!\n" if($MakefileData =~ y/\r//d);
 
554
 
 
555
    # Remove the line continuations, but keep them marked
 
556
    # Note: we lose the trailing spaces but that's ok.
 
557
    # Don't mangle line-leading spaces (usually tabs)
 
558
    # since they're important.
 
559
    $MakefileData =~ s/\\\s*\n/\034/g;
 
560
 
 
561
    # If we've processed the file before...
 
562
    restoreMakefile ()      if ($MakefileData =~ /$progId/);
 
563
 
 
564
    foreach $dir (@foreignfiles) {
 
565
      if (substr($makefileDir,0,length($dir)) eq $dir) {
 
566
        return 0;
 
567
      }
 
568
    }
 
569
 
 
570
    %kdeopts = ();
 
571
    $kdeopts{"foreign"} = 0;
 
572
    $kdeopts{"qtonly"} = 0;
 
573
    $kdeopts{"noautodist"} = 0;
 
574
    $kdeopts{"foreign-libtool"} = $foreign_libtool;
 
575
    $kdeopts{"nofinal"} = !$use_final; # default
 
576
 
 
577
    read_variables();
 
578
 
 
579
    if ($MakefileData =~ /\nKDE_OPTIONS\s*=[ \t]*([^\n]*)\n/) {
 
580
        my $kde_options_str = $1;
 
581
        local @kde_options = split(/[\034\s]+/, $kde_options_str);
 
582
        if (grep(/^foreign$/, @kde_options)) {
 
583
            push(@foreignfiles, $makefileDir . "/");
 
584
            return 0; # don't touch me
 
585
        }
 
586
        for $opt (@kde_options) {
 
587
            if (!defined $kdeopts{$opt}) {
 
588
                print STDERR "Warning: unknown option $opt in $printname\n";
 
589
            } else {
 
590
                $kdeopts{$opt} = 1;
 
591
            }
 
592
        }
 
593
    }
 
594
 
 
595
    # Look for the tags that mean we should process this file.
 
596
    $metasourceTags = 0;
 
597
    $metasourceTags++    while ($MakefileData =~ /\n[^=\#]*METASOURCES\s*=/g);
 
598
 
 
599
    my $pofileTag = 0;
 
600
    $pofileTag++    while ($MakefileData =~ /\nPOFILES\s*=/g);
 
601
    if ($pofileTag > 1)
 
602
      {
 
603
          print STDERR "Error: Only one POFILES tag allowed\n";
 
604
          $errorflag = 1;
 
605
      }
 
606
 
 
607
    while ($MakefileData =~ /\n\.SUFFIXES:([^\n]+)\n/g) {
 
608
        my $suffixes_str = $1;
 
609
        my @list=split(' ', $suffixes_str);
 
610
        foreach $ext (@list) {
 
611
            if ($ext =~ /^\.$cppExt$/) {
 
612
                $cxxsuffix = $ext;
 
613
                $cxxsuffix =~ s/\.//g;
 
614
                print STDOUT "will use suffix $cxxsuffix\n" if ($verbose);
 
615
                last;
 
616
            }
 
617
        }
 
618
    }
 
619
 
 
620
    tag_KDEINIT();
 
621
 
 
622
    while ($MakefileData =~ /\n(\S*)_OBJECTS\s*=[\034 \t]*([^\n]*)\n/g) {
 
623
 
 
624
        my $program = $1;
 
625
        my $objs = $2; # safe them
 
626
 
 
627
        my $ocv = 0;
 
628
 
 
629
        my @objlist = split(/[\034\s]+/, $objs);
 
630
        foreach $obj (@objlist) {
 
631
            if ($obj =~ /(\S*)\$\((\S+)\)/ ) {
 
632
                my $pre = $1;
 
633
                my $variable = $2;
 
634
                if ($pre eq '' && exists($varcontent{$variable})) {
 
635
                    my @addlist = split(/[\034\s]+/, $varcontent{$variable});
 
636
                    push(@objlist, @addlist);
 
637
                } elsif ($variable !~ 'OBJEXT') {
 
638
                    $ocv = 1;
 
639
                }
 
640
            }
 
641
        }
 
642
 
 
643
        next if ($ocv);
 
644
        next if ($program =~ /^am_libkdeinit_/);
 
645
 
 
646
        $program =~ s/^am_// if ($program =~ /^am_/);
 
647
 
 
648
        my $sourceprogram = $program;
 
649
        $sourceprogram =~ s/\@am_/\@/ if($sourceprogram =~ /^.*\@am_.+/);
 
650
 
 
651
        print STDOUT "found program $program\n" if ($verbose);
 
652
        push(@programs, $program);
 
653
 
 
654
        $realObjs{$program} = $objs;
 
655
 
 
656
        if ($MakefileData =~ /\n$sourceprogram\_SOURCES\s*=[ \t]*(.*)\n/) {
 
657
            $sources{$program} = $1;
 
658
        } 
 
659
        else {
 
660
            $sources{$program} = "";
 
661
            print STDERR "found program with no _SOURCES: $program\n";
 
662
        }
 
663
        
 
664
        my $realprogram = $program;
 
665
        $realprogram =~ s/_/./g; # unmask to regexp
 
666
        if ($MakefileData =~ /\n($realprogram)(\$\(EXEEXT\)?)?:.*\$\($program\_OBJECTS\)/) {
 
667
            $realname{$program} = $1;
 
668
        } else {
 
669
            # not standard Makefile - nothing to worry about
 
670
            $realname{$program} = "";
 
671
        }
 
672
    }
 
673
 
 
674
    my $lookup = 'DEPDIR\s*=.*';
 
675
    if ($MakefileData !~ /\n$lookup/) {
 
676
        $lookup = 'bindir\s*=[ \t]*.*';
 
677
        substituteLine($lookup, "DEPDIR = .deps\n$1") if ($MakefileData =~ /\n($lookup)/);
 
678
    }
 
679
 
 
680
    my @marks = ('MAINTAINERCLEANFILES', 'CLEANFILES', 'DISTCLEANFILES');
 
681
    foreach $mark (@marks) {
 
682
        while ($MakefileData =~ /\n($mark)\s*=[ \t]*([^\n]*)/g) {
 
683
            my $clean_str = $2; 
 
684
            foreach $file (split('[\034\s]+', $clean_str)) {
 
685
                $file =~ s/\.\///;
 
686
                push(@cleanfiles, $file);
 
687
            }
 
688
        }
 
689
    }
 
690
 
 
691
    my $localTag = 0;
 
692
    $localTag++ if ($MakefileData =~ /\ninstall-\S+-local:/);
 
693
    
 
694
    return (!$errorflag);
 
695
}
 
696
 
 
697
#-----------------------------------------------------------------------------
 
698
 
 
699
# Gets the list of user defined directories - relative to $srcdir - where
 
700
# header files could be located.
 
701
sub tag_META_INCLUDES ()
 
702
{
 
703
    my $lookup = '[^=\n]*META_INCLUDES\s*=[ \t]*(.*)';
 
704
    return 1    if ($MakefileData !~ /($lookup)\n/);
 
705
    print STDOUT "META_INCLUDE processing <$1>\n"       if ($verbose);
 
706
 
 
707
    my $headerStr = $2;
 
708
    removeLine ($lookup, $1);
 
709
 
 
710
    my @headerlist = split(/[\034\s]+/, $headerStr);
 
711
 
 
712
    foreach $dir (@headerlist)
 
713
    {
 
714
        $dir =~ s#\$\(srcdir\)#.#;
 
715
        if (! -d $dir)
 
716
        {
 
717
            print STDERR "Warning: $dir can't be found. ",
 
718
                            "Must be a relative path to \$(srcdir)\n";
 
719
        }
 
720
        else
 
721
        {
 
722
            push (@headerdirs, $dir);
 
723
        }
 
724
    }
 
725
 
 
726
    return 0;
 
727
}
 
728
 
 
729
#-----------------------------------------------------------------------------
 
730
 
 
731
sub tag_FINAL()
 
732
{
 
733
    my @final_names = ();
 
734
    
 
735
    foreach $program (@programs) {
 
736
        
 
737
        if ($sources{$program} =~ /\(/) {
 
738
            print STDOUT "found ( in $program\_SOURCES. skipping\n" if ($verbose);
 
739
            next;
 
740
        }
 
741
 
 
742
        my $mocs = "";       # Moc files (in this program)
 
743
        my $moc_cpp_added = 0;  # If we added some .moc.cpp files, due to
 
744
                                # no other .cpp file including the .moc one.
 
745
        
 
746
        my @progsources = split(/[\034\s]+/, $sources{$program});
 
747
        my %shash = ();
 
748
        @shash{@progsources} = 1;  # we are only interested in the existence
 
749
        my %sourcelist = ();
 
750
        my %extradeps = ();
 
751
        
 
752
        foreach $source (@progsources) {
 
753
            my $suffix = $source;
 
754
            $suffix =~ s/^.*\.([^\.]+)$/$1/;
 
755
            
 
756
            $sourcelist{$suffix} .= "$source ";
 
757
        }
 
758
        foreach my $mocFile (keys (%globalmocs))
 
759
        {
 
760
            my ($dir, $hFile, $cppFile) = split ("\035", $globalmocs{$mocFile}, 3);
 
761
            if (defined ($cppFile)) {
 
762
                $mocs .= " $mocFile.moc" if exists $shash{$cppFile};
 
763
            } else {
 
764
                $sourcelist{$cxxsuffix} .= "$mocFile.moc.$cxxsuffix ";
 
765
                $moc_cpp_added = 1;
 
766
            }
 
767
        }
 
768
 
 
769
        # scan for extra given dependencies and add them to our target
 
770
        while ($MakefileData =~ /\n\s*(\S+)\.(?:lo|o)\s*:([^\n]*)/g) {
 
771
            $extradeps{$1} = $2;
 
772
        }
 
773
 
 
774
        foreach $suffix (keys %sourcelist) {
 
775
            # See if this file contains c++ code. (i.e., just check the file's suffix against c++ extensions)
 
776
            my $suffix_is_cxx = 0;
 
777
            if($suffix =~ /($cppExt)$/) {
 
778
              $cxxsuffix = $1;
 
779
              $suffix_is_cxx = 1;
 
780
            }
 
781
            
 
782
            my $mocfiles_in = ($suffix eq $cxxsuffix) && $moc_cpp_added;
 
783
            
 
784
            my @sourcelist = split(/[\034\s]+/, $sourcelist{$suffix});
 
785
            
 
786
            if ((@sourcelist == 1 && !$mocfiles_in) || $suffix_is_cxx != 1 ) {
 
787
                
 
788
                # we support IDL on our own
 
789
                if ($suffix eq "skel" || $suffix =~ /^stub/
 
790
                    || $suffix =~ /^signals/ # obsolete, remove in KDE-4
 
791
                    || $suffix eq "h" || $suffix eq "ui" 
 
792
                    || $suffix eq "kcfgc" ) {
 
793
                    next;
 
794
                }
 
795
                
 
796
                foreach $file (@sourcelist) {
 
797
                    $file =~ s/\Q$suffix\E$//;
 
798
                    
 
799
                    $finalObjs{$program} .= $file;
 
800
                    if ($program =~ /_la$/) {
 
801
                        $finalObjs{$program} .= "lo ";
 
802
                    } else {
 
803
                        $finalObjs{$program} .= "o ";
 
804
                    }
 
805
                }
 
806
                next; # suffix
 
807
            }
 
808
            
 
809
            my $source_deps = "";
 
810
            foreach $source (@sourcelist) {
 
811
                if (-f $source) {
 
812
                    $source_deps .= " \$(srcdir)/$source";
 
813
                } else {
 
814
                    $source_deps .= " $source";
 
815
                }
 
816
                my $plainsource = $source;
 
817
                $plainsource =~ s/\.$cppExt$//;
 
818
                $source_deps .= " " . $extradeps{$plainsource} if (exists($extradeps{$plainsource}));
 
819
            }
 
820
 
 
821
            $handling = "$program.all_$suffix.$suffix: \$(srcdir)/Makefile.in" . $source_deps . " " . join(' ', $mocs)  . "\n";
 
822
            $handling .= "\t\@echo 'creating $program.all_$suffix.$suffix ...'; \\\n";
 
823
            $handling .= "\trm -f $program.all_$suffix.files $program.all_$suffix.final; \\\n";
 
824
            $handling .= "\techo \"#define KDE_USE_FINAL 1\" >> $program.all_$suffix.final; \\\n";
 
825
            $handling .= "\tfor file in " . $sourcelist{$suffix} . "; do \\\n";
 
826
            $handling .= "\t  echo \"#include \\\"\$\$file\\\"\" >> $program.all_$suffix.files; \\\n";
 
827
            $handling .= "\t  test ! -f \$\(srcdir\)/\$\$file || egrep '^#pragma +implementation' \$\(srcdir\)/\$\$file >> $program.all_$suffix.final; \\\n";
 
828
            $handling .= "\tdone; \\\n";
 
829
            $handling .= "\tcat $program.all_$suffix.final $program.all_$suffix.files > $program.all_$suffix.$suffix; \\\n";
 
830
            $handling .= "\trm -f $program.all_$suffix.final $program.all_$suffix.files\n";
 
831
 
 
832
            appendLines($handling);
 
833
 
 
834
            push(@final_names, "$program.all_$suffix.$suffix");
 
835
            my $finalObj = "$program.all_$suffix.";
 
836
            if ($program =~ /_la$/) {
 
837
                $finalObj .= "lo";
 
838
            } else {
 
839
                $finalObj .= "o";
 
840
            }
 
841
            $finalObjs{$program} .= $finalObj . " ";
 
842
        }
 
843
    }
 
844
    
 
845
    if (!$kdeopts{"nofinal"} && @final_names >= 1) {
 
846
        # add clean-final target
 
847
        my $lines = "$cleantarget-final:\n";
 
848
        $lines .= "\t-rm -f " . join(' ', @final_names) . "\n" if (@final_names);
 
849
        appendLines($lines);
 
850
        $target_adds{"$cleantarget-am"} .= "$cleantarget-final ";
 
851
        
 
852
        foreach $finalfile (@final_names) {
 
853
            $finalfile =~ s/\.[^.]*$/.P/;
 
854
            $dep_finals .= " \$(DEPDIR)/$finalfile";
 
855
        }
 
856
    }
 
857
}
 
858
 
 
859
sub tag_KDEINIT()
 
860
{
 
861
    my @progs = ();
 
862
    my $ltlibs = "";
 
863
    my $lookup = 'kdeinit_LTLIBRARIES\s*=[ \t]*(.*)';
 
864
 
 
865
    if ($MakefileData =~ m/\n$lookup/) {
 
866
        @kdeinits = split(/[\034\s]+/, $1);
 
867
        my $lines = "";
 
868
        foreach my $kdeinit (@kdeinits) {
 
869
            if ($kdeinit =~ m/\.la$/) {
 
870
                $kdeinit =~ s/\.la$//;
 
871
                push(@progs, $kdeinit);
 
872
 
 
873
                $lines .= "\n${kdeinit}.la.$cxxsuffix:\n";
 
874
                $lines .= "\techo 'extern \"C\" int kdemain(int argc, char* argv[]);' > ${kdeinit}.la.$cxxsuffix; \\\n";
 
875
                $lines .= "\techo 'int main(int argc, char* argv[]) { return kdemain(argc,argv); }' >> ${kdeinit}.la.$cxxsuffix\n";
 
876
 
 
877
                $lines .= "\n${kdeinit}_dummy.$cxxsuffix:\n";
 
878
                $lines .= "\techo 'extern \"C\" int kdemain(int argc, char* argv[]);' > ${kdeinit}_dummy.$cxxsuffix; \\\n";
 
879
                $lines .= "\techo 'extern \"C\" int kdeinitmain(int argc, char* argv[]) { return kdemain(argc,argv); }' >> ${kdeinit}_dummy.$cxxsuffix\n";
 
880
 
 
881
                push(@cleanfiles, "${kdeinit}.la.$cxxsuffix");
 
882
                push(@cleanfiles, "${kdeinit}_dummy.$cxxsuffix");
 
883
 
 
884
                # add dependency
 
885
                $dep_files .= " \$(DEPDIR)/${kdeinit}.la.Po" if($dep_files !~/${kdeinit}.la.Po/ );
 
886
                $dep_files .= " \$(DEPDIR)/${kdeinit}_dummy.Plo" if($dep_files !~/${kdeinit}_dummy.Plo/ );
 
887
 
 
888
                # make library
 
889
                $lookup = $kdeinit . '_la_LIBADD\s*=[ \t]*(.*)';
 
890
                if($MakefileData =~ m/\n$lookup/) {
 
891
                    my $libadd = $1;
 
892
                    substituteLine($lookup, "${kdeinit}_la_LIBADD = libkdeinit_${kdeinit}.la");
 
893
                    appendLines("libkdeinit_${kdeinit}_la_LIBADD = $libadd\n");
 
894
                }
 
895
                appendLines("libkdeinit_${kdeinit}_la_LDFLAGS = -no-undefined -avoid-version \$(all_libraries)\n");
 
896
 
 
897
                # add library dependencies
 
898
                $lookup = $kdeinit . '_la_DEPENDENCIES\s*=[ \t]*(.*)';
 
899
                if($MakefileData =~ m/\n$lookup/) {
 
900
                    my $libdeps = $1;
 
901
                    substituteLine($lookup, "${kdeinit}_la_DEPENDENCIES = libkdeinit_${kdeinit}.la");
 
902
                    appendLines("libkdeinit_${kdeinit}_la_DEPENDENCIES = $libdeps\n");
 
903
                }
 
904
 
 
905
                # make library objects
 
906
                $lookup = "am_${kdeinit}_la_OBJECTS" . '\s*=[ \t]*(.*)';
 
907
                if($MakefileData =~ m/\n$lookup/) {
 
908
                    my $libobjects = $1;
 
909
                    substituteLine($lookup, "am_${kdeinit}_la_OBJECTS = ${kdeinit}_dummy.lo");
 
910
                    appendLines("am_libkdeinit_${kdeinit}_la_OBJECTS = $libobjects\n");
 
911
                    my $prog = "libkdeinit_${kdeinit}_la";
 
912
                    push(@programs, $prog);
 
913
                    $realObjs{$prog} = $libobjects;
 
914
                    $realname{$prog} = "libkdeinit_${kdeinit}.la";
 
915
                }
 
916
                $target_adds{"libkdeinit_${kdeinit}.la"} = "\$(libkdeinit_${kdeinit}_la_OBJECTS) \$(libkdeinit_${kdeinit}_la_DEPENDENCIES)\n" .
 
917
                        "\t\$(CXXLINK) -rpath \$(libdir) \$(libkdeinit_${kdeinit}_la_LDFLAGS) ".
 
918
                           "\$(libkdeinit_${kdeinit}_la_OBJECTS) " .
 
919
                           "\$(libkdeinit_${kdeinit}_la_LIBADD) " .
 
920
                           "\$(LIBS)\n";
 
921
 
 
922
                # make libkdeinit sources
 
923
                $lookup = $kdeinit . '_la_SOURCES\s*=[ \t]*(.*)';
 
924
                if($MakefileData =~ m/\n$lookup/) {
 
925
                    my $srces = $1;
 
926
                    $sources_changed{"libkdeinit_${kdeinit}_la"} = 1;
 
927
                    $sources{"libkdeinit_${kdeinit}_la"} = $srces;
 
928
                }
 
929
 
 
930
                # make libkdeinit metasources
 
931
                $lookup = $kdeinit . '_la_METASOURCES\s*=[ \t]*(.*)';
 
932
                substituteLine($lookup, "libkdeinit_${kdeinit}_la_METASOURCES = $1")
 
933
                    if($MakefileData =~ m/\n$lookup/);
 
934
 
 
935
=cut
 
936
                # make binary sources
 
937
                $lookup = $kdeinit. '_SOURCES\s*=[ \t]*(.*)';
 
938
                if($MakefileData =~ m/\n$lookup/) {
 
939
                    substituteLine($lookup, "${kdeinit}_SOURCES = ${kdeinit}.la.$cxxsuffix");
 
940
                    $lookup = 'SOURCES\s*=[ \t]*(.*)';
 
941
                    if($MakefileData =~ m/\n$lookup/) {
 
942
                        my $srces = $1;
 
943
                        $srces =~ s/\b$kdeinit\.c\b/\$(${kdeinit}_SOURCES)/;
 
944
                        $srces =~ s/\$\(${kdeinit}_la_SOURCES\)/\$(libkdeinit_${kdeinit}_la_SOURCES)/;
 
945
                        substituteLine($lookup, "SOURCES = $srces");
 
946
                    }
 
947
                    $lookup = 'DIST_SOURCES\s*=[ \t](.*)';
 
948
                    if($MakefileData =~ m/\n$lookup/) {
 
949
                        my $srces = $1;
 
950
                        $srces =~ s/\b$kdeinit\.c\b/\$(${kdeinit}_SOURCES)/;
 
951
                        $srces =~ s/\$\(${kdeinit}_la_SOURCES\)/\$(libkdeinit_${kdeinit}_la_SOURCES)/;
 
952
                        substituteLine($lookup, "DIST_SOURCES = $srces");
 
953
                    }
 
954
                }
 
955
 
 
956
                # make binary objects / libs
 
957
                $lookup = $kdeinit . '_OBJECTS\s*=[ \t]*.*';
 
958
                if($MakefileData =~ m/\n$lookup/) {
 
959
                    $realObjs{$kdeinit} = "${kdeinit}.la.\$(OBJEXT)";
 
960
                    substituteLine("${kdeinit}_LDFLAGS\\s*=.*", "${kdeinit}_LDFLAGS = \$(all_libraries)");
 
961
                    substituteLine("${kdeinit}_LDADD\\s*=.*", "${kdeinit}_LDADD = libkdeinit_${kdeinit}.la");
 
962
                    substituteLine("${kdeinit}_DEPENDENCIES\\s*=.*", "${kdeinit}_DEPENDENCIES = libkdeinit_${kdeinit}.la");
 
963
                }
 
964
=cut
 
965
                # add binary
 
966
                push(@programs, $kdeinit);
 
967
                $realObjs{$kdeinit} = "${kdeinit}.la.\$(OBJEXT)";
 
968
                $realname{$kdeinit} = $kdeinit;
 
969
                $sources{$kdeinit} = "${kdeinit}.la.$cxxsuffix";
 
970
 
 
971
                $lines .= "${kdeinit}_LDFLAGS = \$(KDE_RPATH) -no-undefined \$(all_libraries)\n";
 
972
                $lines .= "${kdeinit}_LDADD = libkdeinit_${kdeinit}.la\n";
 
973
                $lines .= "${kdeinit}_DEPENDENCIES = libkdeinit_${kdeinit}.la\n";
 
974
 
 
975
                $target_adds{"${kdeinit}\$(EXEEXT)"} =
 
976
                          "\$(${kdeinit}_OBJECTS) \$(${kdeinit}_DEPENDENCIES)\n" .
 
977
                          "\t\@rm -f ${kdeinit}\$(EXEEXT)\n" .
 
978
                          "\t\$(CXXLINK) \$(${kdeinit}_LDFLAGS) \$(${kdeinit}_OBJECTS) \$(${kdeinit}_LDADD) \$(LIBS)\n";
 
979
 
 
980
                $ltlibs .= " libkdeinit_${kdeinit}.la";
 
981
            }
 
982
        }
 
983
        appendLines($lines);
 
984
 
 
985
        # add libkdeinit target
 
986
        $lookup = 'lib_LTLIBRARIES\s*=[ \t]*(.*)';
 
987
        if($MakefileData =~ m/\n$lookup/) {
 
988
            substituteLine($lookup, "lib_LTLIBRARIES = $1 $ltlibs");
 
989
        }
 
990
        else {
 
991
            print STDERR
 
992
                "Error: lib_LTLIBRARIES missing in $printname (required for kdeinit_LTLIBRARIES).\n";
 
993
            $errorflag = 1;
 
994
        }
 
995
    }
 
996
 
 
997
    if($#progs >= 0) {
 
998
        if($MakefileData !~ m/\nbin_PROGRAMS\s*=/) {
 
999
            print STDERR "Error: bin_PROGRAMS missing in $printname (required for kdeinit_LTLIBRARIES).\n";
 
1000
            $errorflag = 1;
 
1001
        }
 
1002
        else {
 
1003
            # add our new progs to SOURCES, DIST_SOURCES and bin_PROGRAMS
 
1004
            my $progsources = "";
 
1005
            my $progexes = "";
 
1006
            foreach my $p (@progs) {
 
1007
                $progsources .= "\$(${p}_SOURCES) ";
 
1008
                $progexes .= "${p}\$(EXEEXT) ";
 
1009
            }
 
1010
            $lookup = 'SOURCES\s*=[ \t]*(.*)';
 
1011
            if($MakefileData =~ /\n$lookup/) {
 
1012
                substituteLine($lookup, "SOURCES = $1 $progsources");
 
1013
            }
 
1014
            $lookup = 'DIST_SOURCES\s*=[ \t]*(.*)';
 
1015
            if($MakefileData =~ /\n$lookup/) {
 
1016
                substituteLine($lookup, "DIST_SOURCES = $1 $progsources");
 
1017
            }
 
1018
            # bin_PROGRAMS is complicated, as it exists twice, so we do a little
 
1019
            # magic trick here
 
1020
            $lookup = 'PROGRAMS\s*=[ \t]*(.*)';
 
1021
            if ($MakefileData =~ /\n$lookup/) {
 
1022
                substituteLine($lookup, "bin_PROGRAMS += $progexes\nPROGRAMS = $1");
 
1023
            }
 
1024
        }
 
1025
    }
 
1026
}
 
1027
 
 
1028
#-----------------------------------------------------------------------------
 
1029
 
 
1030
sub tag_COMPILE_FIRST()
 
1031
{
 
1032
  foreach $program (@programs) {
 
1033
    my $lookup = "$program" . '_COMPILE_FIRST\s*=[ \t]*(.*)';
 
1034
    if ($MakefileData =~ m/\n$lookup\n/) {
 
1035
      my $compilefirst_str = $1;
 
1036
      my @compilefirst = split(/[\034\s]+/, $compilefirst_str);
 
1037
      my @progsources = split(/[\034\s]+/, $sources{$program});
 
1038
      my %donesources = ();
 
1039
      foreach $source (@progsources) {
 
1040
        my @deps  = ();
 
1041
        my $sdeps = "";
 
1042
        if (-f $source) {
 
1043
          $sdeps = "\$(srcdir)/$source";
 
1044
        } else {
 
1045
          $sdeps = "$source";
 
1046
        }
 
1047
        foreach $depend (@compilefirst) {
 
1048
          next if ($source eq $depend);
 
1049
          # avoid cyclic dependencies
 
1050
          next if defined($donesources{$depend});
 
1051
          push @deps, $depend;
 
1052
        }
 
1053
        $target_adds{$sdeps} .= join(' ', @deps) . ' ' if (@deps);
 
1054
        $donesources{$source} = 1;
 
1055
      }
 
1056
    }
 
1057
  }
 
1058
}
 
1059
 
 
1060
#-----------------------------------------------------------------------------
 
1061
 
 
1062
 
 
1063
# Organises the list of headers that we'll use to produce moc files
 
1064
# from.
 
1065
sub tag_METASOURCES ()
 
1066
{
 
1067
    local @newObs           = ();  # here we add to create object files
 
1068
    local @depend           = ();  # here we add to create moc files
 
1069
    local $mocExt           = ".moc";
 
1070
    local %mocFiles         = ();
 
1071
 
 
1072
    my $line = "";
 
1073
    my $postEqual = "";
 
1074
 
 
1075
    my $lookup;
 
1076
    my $found = "";
 
1077
    if ($metasourceTags > 1) {
 
1078
        $lookup = $program . '_METASOURCES\s*=\s*(.*)';
 
1079
        return 1    if ($MakefileData !~ /\n($lookup)\n/);
 
1080
        $found = $1;
 
1081
    } else {
 
1082
        $lookup = $program . '_METASOURCES\s*=\s*(.*)';
 
1083
        if ($MakefileData !~ /\n($lookup)\n/) {
 
1084
            $lookup = 'METASOURCES\s*=\s*(.*)';
 
1085
            return 1    if ($MakefileData !~ /\n($lookup)\n/);
 
1086
            $found = $1;
 
1087
            $metasourceTags = 0; # we can use the general target only once
 
1088
        } else {
 
1089
            $found = $1;
 
1090
        }
 
1091
    }
 
1092
    print STDOUT "METASOURCE processing <$found>)\n"      if ($verbose);
 
1093
    
 
1094
    $postEqual = $found;
 
1095
    $postEqual =~ s/[^=]*=//;
 
1096
    
 
1097
    removeLine ($lookup, $found);
 
1098
    
 
1099
    # Always find the header files that could be used to "moc"
 
1100
    return 1    if (findMocCandidates ());
 
1101
    
 
1102
    if ($postEqual =~ /AUTO\s*(\S*)|USE_AUTOMOC\s*(\S*)/)
 
1103
    {
 
1104
        print STDERR "$printname: the argument for AUTO|USE_AUTOMOC is obsolete" if ($+);
 
1105
        $mocExt = ".moc.$cxxsuffix";
 
1106
        $haveAutomocTag = 1;
 
1107
    }
 
1108
    else
 
1109
    {
 
1110
        # Not automoc so read the list of files supplied which
 
1111
        # should be .moc files.
 
1112
 
 
1113
        $postEqual =~ tr/\034/ /;
 
1114
 
 
1115
        # prune out extra headers - This also checks to make sure that
 
1116
        # the list is valid.
 
1117
        pruneMocCandidates ($postEqual);
 
1118
    }
 
1119
 
 
1120
    checkMocCandidates ();
 
1121
    
 
1122
    if (@newObs) {
 
1123
        my $ext =  ($program =~ /_la$/) ? ".moc.lo " : ".moc.o ";
 
1124
        $realObjs{$program} .= "\034" . join ($ext, @newObs) . $ext;
 
1125
        $dependmocs{$program} = join (".moc.$cxxsuffix " , @newObs) . ".moc.$cxxsuffix";
 
1126
        foreach $file (@newObs) {
 
1127
            $dep_files .= " \$(DEPDIR)/$file.moc.P" if($dep_files !~/$file.moc.P/);
 
1128
        }
 
1129
    }
 
1130
    if (@depend) {
 
1131
        $dependmocs{$program} .= " ";
 
1132
        $dependmocs{$program} .= join('.moc ', @depend) . ".moc";
 
1133
        $dependmocs{$program} .= " ";
 
1134
    }
 
1135
    addMocRules ();
 
1136
    @globalmocs{keys %mocFiles}=values %mocFiles;
 
1137
}
 
1138
 
 
1139
#-----------------------------------------------------------------------------
 
1140
 
 
1141
# Returns 0 if the line was processed - 1 otherwise.
 
1142
# Errors are logged in the global $errorflags
 
1143
sub tag_AUTOMAKE ()
 
1144
{
 
1145
    my $lookup = '.*cd \$\(top_srcdir\)\s+&&[\034\s]+\$\(AUTOMAKE\)(.*)';
 
1146
    return 1    if ($MakefileData !~ /\n($lookup)\n/);
 
1147
    print STDOUT "AUTOMAKE processing <$1>\n"        if ($verbose);
 
1148
 
 
1149
    my $newLine = $1."\n\tcd \$(top_srcdir) && perl $thisProg $printname";
 
1150
 
 
1151
    # automake 1.8.x adds another automake call. *sigh*
 
1152
    $newLine =~ s/;([\034\s]+cd\s+\$\(srcdir\)\s+&&[\034\s]+\$\(AUTOMAKE\).*)[\034\s]+\&\&[\034\s]+exit[\034\s]+0;([\034\s]+exit\s+1)/; \034 ( $1 ) || exit 1; echo \' cd \$(top_srcdir) && perl $thisProg \'; cd \$(top_srcdir) && perl $thisProg && exit 0; $2/;
 
1153
    substituteLine ($lookup, $newLine);
 
1154
    $automkCall = $1;
 
1155
 
 
1156
    $lookup = '.*cd \$\(srcdir\)\s+&&[\034\s]+\$\(AUTOCONF\)(.*)';
 
1157
    if ($MakefileData =~ /\n($lookup)\n/) {
 
1158
      $newLine  = "\tcd \$(srcdir) && rm -f configure\n";
 
1159
      $newLine .= "\tcd \$(top_srcdir) && \$(MAKE) -f admin/Makefile.common configure";
 
1160
      substituteLine ($lookup, $newLine);
 
1161
    }
 
1162
 
 
1163
    return 0;
 
1164
}
 
1165
 
 
1166
#-----------------------------------------------------------------------------
 
1167
 
 
1168
sub handle_TOPLEVEL()
 
1169
{
 
1170
    my $pofiles = "";
 
1171
    my @restfiles = ();
 
1172
    opendir (THISDIR, ".");
 
1173
    foreach $entry (readdir(THISDIR)) {
 
1174
        next if (-d $entry);
 
1175
        
 
1176
        next if ($entry eq "CVS" || $entry =~ /^\./  || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/ || $entry =~ /.gmo$/);
 
1177
                 
 
1178
        if ($entry =~ /\.po$/) {
 
1179
             next;
 
1180
        }
 
1181
        push(@restfiles, $entry);
 
1182
    }
 
1183
    closedir (THISDIR);
 
1184
            
 
1185
    if (@restfiles) {
 
1186
        $target_adds{"install-data-am"} .= "install-nls-files ";
 
1187
        $lines = "install-nls-files:\n";
 
1188
        $lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$kdelang\n";
 
1189
        for $file (@restfiles) {
 
1190
            $lines .= "\t\$(INSTALL_DATA) \$\(srcdir\)/$file \$(DESTDIR)\$(kde_locale)/$kdelang/$file\n";
 
1191
        }
 
1192
        $target_adds{"uninstall"} .= "uninstall-nls-files ";
 
1193
        $lines .= "uninstall-nls-files:\n";
 
1194
        for $file (@restfiles) {
 
1195
            $lines .= "\t-rm -f \$(DESTDIR)\$(kde_locale)/$kdelang/$file\n";
 
1196
        }
 
1197
        appendLines($lines);
 
1198
    }
 
1199
    
 
1200
    return 0;
 
1201
}
 
1202
 
 
1203
#-----------------------------------------------------------------------------
 
1204
 
 
1205
sub tag_SUBDIRS ()
 
1206
{
 
1207
  if ($MakefileData !~ /\nSUBDIRS\s*=\s*\$\(AUTODIRS\)\s*\n/) {
 
1208
    return 1;
 
1209
  }
 
1210
 
 
1211
  my $subdirs = ".";
 
1212
 
 
1213
  opendir (THISDIR, ".");
 
1214
  foreach $entry (readdir(THISDIR)) {
 
1215
    next if ($entry eq "CVS" || $entry =~ /^\./);
 
1216
    if (-d $entry && -f $entry . "/Makefile.am") {
 
1217
      $subdirs .= " $entry";
 
1218
      next;
 
1219
    }
 
1220
  }
 
1221
  closedir (THISDIR);
 
1222
 
 
1223
  substituteLine('SUBDIRS\s*=.*', "SUBDIRS =$subdirs");
 
1224
  return 0;
 
1225
}
 
1226
 
 
1227
sub tag_IDLFILES ()
 
1228
{
 
1229
    my @psources = split(/[\034\s]+/, $sources{$program});
 
1230
    my $dep_lines = "";
 
1231
    my @cppFiles = ();
 
1232
    
 
1233
    foreach $source (@psources) {
 
1234
        my $skel = ($source =~ m/\.skel$/);
 
1235
        my $stub = ($source =~ m/\.stub$/);
 
1236
        my $signals = ($source =~ m/\.signals$/); # obsolete, remove in KDE-4
 
1237
        
 
1238
        if ($stub || $skel || $signals) {
 
1239
 
 
1240
            my $qs = quotemeta($source);
 
1241
            $sources{$program} =~ s/$qs//;
 
1242
            $sources_changed{$program} = 1;
 
1243
 
 
1244
            $source =~ s/\.(stub|skel|signals)$//;
 
1245
            my $sourcename;
 
1246
 
 
1247
            if ($skel) {
 
1248
                $sourcename = "$source\_skel";
 
1249
            } elsif ($stub) {
 
1250
                $sourcename = "$source\_stub";
 
1251
            } else {
 
1252
                $sourcename = "$source\_signals";
 
1253
            }
 
1254
            
 
1255
            my $sourcedir = '';
 
1256
            if (-f "$makefileDir/$source.h") {
 
1257
                $sourcedir = '$(srcdir)/';
 
1258
            } else {
 
1259
                if ($MakefileData =~ /\n$source\_DIR\s*=\s*(\S+)\n/) {
 
1260
                    $sourcedir = $1;
 
1261
                    $sourcedir .= "/" if ($sourcedir !~ /\/$/);
 
1262
                }
 
1263
            }
 
1264
            
 
1265
            if ($allidls !~ /$source\_kidl/) {
 
1266
                
 
1267
                $use_ng = ($MakefileData =~ /\n$source\_DCOPIDLNG\s*=\s*(\S+)\n/);
 
1268
                $dcopidl =  $use_ng ? "KDECONFIG=\"\$(KDECONFIG)\" \$(DCOPIDLNG)" : "\$(DCOPIDL)";
 
1269
 
 
1270
                $dep_lines .= "$source.kidl: $sourcedir$source.h \$(DCOP_DEPENDENCIES)\n";
 
1271
                $dep_lines .= "\t$dcopidl $sourcedir$source.h > $source.kidl || ( rm -f $source.kidl ; false )\n";
 
1272
                
 
1273
                $allidls .= $source . "_kidl ";
 
1274
            }
 
1275
            
 
1276
            if ($allidls !~ /$sourcename/) {
 
1277
                
 
1278
                $dep_lines_tmp = "";
 
1279
 
 
1280
                if ($skel) {
 
1281
                    $dep_lines .= "$sourcename.$cxxsuffix: $source.kidl\n";
 
1282
                    $dep_lines .= "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-signals --no-stub $source.kidl\n";
 
1283
                } elsif ($stub) {
 
1284
                    $dep_lines_tmp = "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-signals --no-skel $source.kidl\n";
 
1285
                } else { # signals - obsolete, remove in KDE 4
 
1286
                    $dep_lines_tmp = "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-stub --no-skel $source.kidl\n";
 
1287
                }
 
1288
 
 
1289
                if ($stub || $signals) {
 
1290
                    $target_adds{"$sourcename.$cxxsuffix"} .= "$sourcename.h ";
 
1291
                    $dep_lines .= "$sourcename.h: $source.kidl\n";
 
1292
                    $dep_lines .= $dep_lines_tmp;
 
1293
                }
 
1294
                
 
1295
                $allidls .= $sourcename . " ";
 
1296
            }
 
1297
            
 
1298
            $idlfiles{$program} .= $sourcename . " ";
 
1299
            
 
1300
            if ($program =~ /_la$/) {
 
1301
                $realObjs{$program} .= " $sourcename.lo";
 
1302
            } else {
 
1303
                $realObjs{$program} .= " $sourcename.\$(OBJEXT)";
 
1304
            }
 
1305
            $sources{$program} .= " $sourcename.$cxxsuffix";
 
1306
            $sources_changed{$program} = 1;
 
1307
            $important{$program} .= "$sourcename.h " if (!$skel);
 
1308
            $idl_output .= "\\\n\t$sourcename.$cxxsuffix $sourcename.h $source.kidl ";
 
1309
            push(@cleanfiles, "$sourcename.$cxxsuffix");
 
1310
            push(@cleanfiles, "$sourcename.h");
 
1311
            push(@cleanfiles, "$sourcename.kidl");
 
1312
            $dep_files .= " \$(DEPDIR)/$sourcename.P" if ($dep_files !~/$sourcename.P/);
 
1313
        }
 
1314
    }
 
1315
    if ($dep_lines) {
 
1316
        appendLines($dep_lines);
 
1317
    }
 
1318
    
 
1319
    if (0) {
 
1320
        my $lookup = "($program)";
 
1321
        $lookup .= '(|\$\(EXEEXT\))';
 
1322
        $lookup =~ s/\_/./g;
 
1323
        $lookup .= ":(.*..$program\_OBJECTS..*)";
 
1324
        #    $lookup = quotemeta($lookup);
 
1325
        if ($MakefileData =~ /\n$lookup\n/) {
 
1326
            
 
1327
            my $line = "$1$2: ";
 
1328
            foreach $file (split(' ', $idlfiles{$program})) {
 
1329
                $line .= "$file.$cxxsuffix ";
 
1330
            }
 
1331
            $line .= $3;
 
1332
            substituteLine($lookup, $line);
 
1333
        } else {
 
1334
            print STDERR "no built dependency found $lookup\n";
 
1335
        }
 
1336
    }
 
1337
}
 
1338
 
 
1339
sub tag_UIFILES ()
 
1340
{
 
1341
    my @psources = split(/[\034\s]+/, $sources{$program});
 
1342
    my @depFiles = ();
 
1343
    
 
1344
    foreach $source (@psources) {
 
1345
 
 
1346
        if ($source =~ m/\.ui$/) {
 
1347
 
 
1348
            print STDERR "adding UI file $source\n" if ($verbose);
 
1349
 
 
1350
            my $qs = quotemeta($source);
 
1351
            $sources{$program} =~ s/$qs//;
 
1352
            $sources_changed{$program} = 1;
 
1353
      
 
1354
            $source =~ s/\.ui$//;
 
1355
 
 
1356
            my $sourcedir = '';
 
1357
            if (-f "$makefileDir/$source.ui") {
 
1358
                $sourcedir = '$(srcdir)/';
 
1359
            }
 
1360
 
 
1361
            if (!$uiFiles{$source}) {
 
1362
 
 
1363
                my $dep_lines = "$source.$cxxsuffix: $sourcedir$source.ui $source.h $source.moc\n";
 
1364
                $dep_lines .= "\trm -f $source.$cxxsuffix\n";
 
1365
                if (!$kdeopts{"qtonly"}) {
 
1366
                    $dep_lines .= "\techo '#include <kdialog.h>' > $source.$cxxsuffix\n";
 
1367
                    $dep_lines .= "\techo '#include <klocale.h>' >> $source.$cxxsuffix\n";
 
1368
                    my ($mangled_source) = $source;
 
1369
                    $mangled_source =~ s/[^A-Za-z0-9]/_/g;  # get rid of garbage
 
1370
                    $dep_lines .= "\t\$(UIC) -tr \${UIC_TR} -i $source.h $sourcedir$source.ui > $source.$cxxsuffix.temp ; ret=\$\$?; \\\n";
 
1371
                    $dep_lines .= "\t\$(PERL) -pe \"s,\${UIC_TR}( \\\"\\\" ),QString::null,g\" $source.$cxxsuffix.temp | \$(PERL) -pe \"s,\${UIC_TR}( \\\"\\\"\\, \\\"\\\" ),QString::null,g\" | \$(PERL) -pe \"s,image([0-9][0-9]*)_data,img\\\$\$1_" . $mangled_source . ",g\" >> $source.$cxxsuffix ;\\\n";
 
1372
                    $dep_lines .= "\trm -f $source.$cxxsuffix.temp ;\\\n";
 
1373
                } else {
 
1374
                    $dep_lines .= "\t\$(UIC) -i $source.h $sourcedir$source.ui > $source.$cxxsuffix; ret=\$\$?; \\\n";
 
1375
                }
 
1376
                $dep_lines .= "\tif test \"\$\$ret\" = 0; then echo '#include \"$source.moc\"' >> $source.$cxxsuffix; else rm -f $source.$cxxsuffix ; exit \$\$ret ; fi\n\n";
 
1377
                $dep_lines .= "$source.h: $sourcedir$source.ui\n";
 
1378
                $dep_lines .= "\t\$(UIC) -o $source.h $sourcedir$source.ui\n\n";
 
1379
                $dep_lines .= "$source.moc: $source.h\n";
 
1380
                $dep_lines .= "\t\$(MOC) $source.h -o $source.moc\n";
 
1381
 
 
1382
                $rule_adds{"$source.$cxxsuffix"} = $dep_lines;
 
1383
 
 
1384
                $uiFiles{$source} = 1;
 
1385
                $dependmocs{$program} .= " $source.moc";
 
1386
                $globalmocs{$source} = "\035$source.h\035$source.cpp";
 
1387
            }
 
1388
            
 
1389
            if ($program =~ /_la$/) {
 
1390
                $realObjs{$program} .= " $source.lo";
 
1391
            } else {
 
1392
                $realObjs{$program} .= " $source.\$(OBJEXT)";
 
1393
            }
 
1394
            $sources{$program} .= " $source.$cxxsuffix";
 
1395
            $sources_changed{$program} = 1;
 
1396
            $important{$program} .= "$source.h ";
 
1397
            $ui_output .= "\\\n\t$source.$cxxsuffix $source.h $source.moc ";
 
1398
            push(@cleanfiles, "$source.$cxxsuffix");
 
1399
            push(@cleanfiles, "$source.h");
 
1400
            push(@cleanfiles, "$source.moc");
 
1401
            $dep_files .= " \$(DEPDIR)/$source.P" if($dep_files !~/$source.P/ );
 
1402
        }
 
1403
    }
 
1404
}
 
1405
 
 
1406
sub tag_KCFGFILES ()
 
1407
{
 
1408
    my @psources = split(/[\034\s]+/, $sources{$program});
 
1409
    my @depFiles = ();
 
1410
    
 
1411
    foreach $source (@psources) {
 
1412
 
 
1413
        if ($source =~ m/\.kcfgc$/) {
 
1414
 
 
1415
            print STDERR "adding KCFG file $source\n" if ($verbose);
 
1416
 
 
1417
            my $qs = quotemeta($source);
 
1418
            $sources{$program} =~ s/$qs//;
 
1419
            $sources_changed{$program} = 1;
 
1420
      
 
1421
            $source =~ s/\.kcfgc$//;
 
1422
 
 
1423
            my $sourcedir = '';
 
1424
            if (-f "$makefileDir/$source.kcfgc") {
 
1425
                $sourcedir = '$(srcdir)/';
 
1426
            }
 
1427
 
 
1428
            if (!$kcfgFiles{$source}) {
 
1429
                $kcfg = "$program.kcfg";
 
1430
                findKcfgFile("$source.kcfgc");
 
1431
 
 
1432
                my $fixsuffix = "";
 
1433
                $fixsuffix = "else mv $source.cpp $source.$cxxsuffix ; " 
 
1434
                    unless "cpp" eq $cxxsuffix;
 
1435
 
 
1436
                my $dep_lines = "$source.$cxxsuffix: $source.h\n";
 
1437
                $dep_lines .= "$source.h: $sourcedir$kcfg $sourcedir$source.kcfgc \$(KCFG_DEPENDENCIES)\n";
 
1438
                $dep_lines .= "\t\$(KCONFIG_COMPILER) $sourcedir$kcfg $sourcedir$source.kcfgc; ret=\$\$?; \\\n";
 
1439
                $dep_lines .= "\tif test \"\$\$ret\" != 0; then rm -f $source.h ; exit \$\$ret ; $fixsuffix fi\n\n";
 
1440
 
 
1441
                $rule_adds{"$source.$cxxsuffix"} = $dep_lines;
 
1442
 
 
1443
                $kcfgFiles{$source} = 1;
 
1444
            }
 
1445
            
 
1446
            if ($program =~ /_la$/) {
 
1447
                $realObjs{$program} .= " $source.lo";
 
1448
            } else {
 
1449
                $realObjs{$program} .= " $source.\$(OBJEXT)";
 
1450
            }
 
1451
            $sources{$program} .= " $source.$cxxsuffix";
 
1452
            $sources_changed{$program} = 1;
 
1453
            $important{$program} .= "$source.h ";
 
1454
            $kcfg_output .= "\\\n\t$source.$cxxsuffix $source.h ";
 
1455
            push(@cleanfiles, "$source.$cxxsuffix");
 
1456
            push(@cleanfiles, "$source.h");
 
1457
            $dep_files .= " \$(DEPDIR)/$source.P" if($dep_files !~/$source.P/ );
 
1458
        }
 
1459
    }
 
1460
}
 
1461
 
 
1462
sub tag_ICON()
 
1463
{
 
1464
    my $lookup = '([^\s]*)_ICON\s*=[ \t]*(.*)';
 
1465
    my $install = "";
 
1466
    my $uninstall = "";
 
1467
 
 
1468
    while ($MakefileData =~ /\n$lookup/g) {
 
1469
        my $destdir;
 
1470
        if ($1 eq "KDE") {
 
1471
            $destdir = "kde_icondir";
 
1472
        } else {
 
1473
            $destdir = $1 . "dir";
 
1474
        }
 
1475
        my $iconauto = ($2 =~ /AUTO\s*$/);
 
1476
        my @appnames = ();
 
1477
        if ( ! $iconauto ) {
 
1478
            my $appicon_str = $2;
 
1479
            my @_appnames = split(" ", $appicon_str);
 
1480
            print STDOUT "KDE_ICON processing <@_appnames>\n"   if ($verbose);
 
1481
            foreach $appname (@_appnames) {
 
1482
                push(@appnames, quotemeta($appname));
 
1483
            }
 
1484
        } else {
 
1485
            print STDOUT "KDE_ICON processing <AUTO>\n"   if ($verbose);
 
1486
        }
 
1487
 
 
1488
        my @files = ();
 
1489
        opendir (THISDIR, ".");
 
1490
        foreach $entry (readdir(THISDIR)) {
 
1491
            next if ($entry eq "CVS" || $entry =~ /^\./  || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
 
1492
            next if (! -f $entry);
 
1493
            if ( $iconauto )
 
1494
              {
 
1495
                  push(@files, $entry)
 
1496
                    if ($entry =~ /\.xpm/ || $entry =~ /\.png/ || $entry =~ /\.mng/ || $entry =~ /\.svg/);
 
1497
              } else {
 
1498
                  foreach $appname (@appnames) {
 
1499
                      push(@files, $entry)
 
1500
                        if ($entry =~ /-$appname\.xpm/ || $entry =~ /-$appname\.png/ || $entry =~ /-$appname\.mng/ || $entry =~ /-$appname\.svg/);
 
1501
                  }
 
1502
              }
 
1503
        }
 
1504
        closedir (THISDIR);
 
1505
        
 
1506
        my %directories = ();
 
1507
        
 
1508
        foreach $file (@files) {
 
1509
            my $newfile = $file;
 
1510
            my $prefix = $file;
 
1511
            $prefix =~ s/\.(png|xpm|mng|svg|svgz)$//;
 
1512
            my $appname = $prefix;
 
1513
            $appname =~ s/^[^-]+-// if ($appname =~ /-/) ;
 
1514
            $appname =~ s/^[^-]+-// if ($appname =~ /-/) ;
 
1515
            $appname = quotemeta($appname);
 
1516
            $prefix =~ s/$appname$//;
 
1517
            $prefix =~ s/-$//;
 
1518
            
 
1519
            $prefix = 'lo16-app' if ($prefix eq 'mini');
 
1520
            $prefix = 'lo32-app' if ($prefix eq 'lo');
 
1521
            $prefix = 'hi48-app' if ($prefix eq 'large');
 
1522
            $prefix .= '-app' if ($prefix =~ m/^...$/);
 
1523
            
 
1524
            my $type = $prefix;
 
1525
            $type =~ s/^.*-([^-]+)$/$1/;
 
1526
            $prefix =~ s/^(.*)-[^-]+$/$1/;
 
1527
            
 
1528
            my %type_hash =
 
1529
              (
 
1530
               'action' => 'actions',
 
1531
               'app' => 'apps',
 
1532
               'device' => 'devices',
 
1533
               'filesys' => 'filesystems',
 
1534
               'mime' => 'mimetypes'
 
1535
              );
 
1536
 
 
1537
            if (! defined $type_hash{$type} ) {
 
1538
                print STDERR "unknown icon type $type in $printname ($file)\n";
 
1539
                next;
 
1540
            }
 
1541
 
 
1542
            my %dir_hash =
 
1543
              (
 
1544
               'los' => 'locolor/16x16',
 
1545
               'lom' => 'locolor/32x32',
 
1546
               'him' => 'hicolor/32x32',
 
1547
               'hil' => 'hicolor/48x48',
 
1548
               'lo16' => 'locolor/16x16',
 
1549
               'lo22' => 'locolor/22x22',
 
1550
               'lo32' => 'locolor/32x32',
 
1551
               'hi16' => 'hicolor/16x16',
 
1552
               'hi22' => 'hicolor/22x22',
 
1553
               'hi32' => 'hicolor/32x32',
 
1554
               'hi48' => 'hicolor/48x48',
 
1555
               'hi64' => 'hicolor/64x64',
 
1556
               'hi128' => 'hicolor/128x128',
 
1557
               'hisc' => 'hicolor/scalable',
 
1558
               'cr16' => 'crystalsvg/16x16',
 
1559
               'cr22' => 'crystalsvg/22x22',
 
1560
               'cr32' => 'crystalsvg/32x32',
 
1561
               'cr48' => 'crystalsvg/48x48',
 
1562
               'cr64' => 'crystalsvg/64x64',
 
1563
               'cr128' => 'crystalsvg/128x128',
 
1564
               'crsc' => 'crystalsvg/scalable'
 
1565
              );
 
1566
            
 
1567
            $newfile =~ s@.*-($appname\.(png|xpm|mng|svgz|svg?))@$1@;
 
1568
            
 
1569
            if (! defined $dir_hash{$prefix}) {
 
1570
                print STDERR "unknown icon prefix $prefix in $printname\n";
 
1571
                next;
 
1572
            }
 
1573
            
 
1574
            my $dir = $dir_hash{$prefix} . "/" . $type_hash{$type};
 
1575
            if ($newfile =~ /-[^\.]/) {
 
1576
                my $tmp = $newfile;
 
1577
                $tmp =~ s/^([^-]+)-.*$/$1/;
 
1578
                $dir = $dir . "/" . $tmp;
 
1579
                $newfile =~ s/^[^-]+-//;
 
1580
            }
 
1581
            
 
1582
            if (!defined $directories{$dir}) {
 
1583
                $install .= "\t\$(mkinstalldirs) \$(DESTDIR)\$($destdir)/$dir\n";
 
1584
                $directories{$dir} = 1;
 
1585
            }
 
1586
            
 
1587
            $install .= "\t\$(INSTALL_DATA) \$(srcdir)/$file \$(DESTDIR)\$($destdir)/$dir/$newfile\n";
 
1588
            $uninstall .= "\t-rm -f \$(DESTDIR)\$($destdir)/$dir/$newfile\n";
 
1589
            
 
1590
        }
 
1591
    }
 
1592
 
 
1593
    if (length($install)) {
 
1594
        $target_adds{"install-data-am"} .= "install-kde-icons ";
 
1595
        $target_adds{"uninstall-am"} .= "uninstall-kde-icons ";
 
1596
        appendLines("install-kde-icons:\n" . $install . "\nuninstall-kde-icons:\n" . $uninstall);
 
1597
    }
 
1598
}
 
1599
 
 
1600
sub handle_POFILES($$)
 
1601
{
 
1602
  my @pofiles = split(" ", $_[0]);
 
1603
  my $lang = $_[1];
 
1604
 
 
1605
  # Build rules for creating the gmo files
 
1606
  my $tmp = "";
 
1607
  my $allgmofiles     = "";
 
1608
  my $pofileLine   = "POFILES =";
 
1609
  foreach $pofile (@pofiles)
 
1610
    {
 
1611
        $pofile =~ /(.*)\.[^\.]*$/;          # Find name minus extension
 
1612
        $tmp .= "$1.gmo: $pofile\n";
 
1613
        $tmp .= "\trm -f $1.gmo; \$(GMSGFMT) -o $1.gmo \$(srcdir)/$pofile\n";
 
1614
        $tmp .= "\ttest ! -f $1.gmo || touch $1.gmo\n";
 
1615
        $allgmofiles .= " $1.gmo";
 
1616
        $pofileLine  .= " $1.po";
 
1617
    }
 
1618
  appendLines ($tmp);
 
1619
  my $lookup = 'POFILES\s*=([^\n]*)';
 
1620
  if ($MakefileData !~ /\n$lookup/) {
 
1621
    appendLines("$pofileLine\nGMOFILES =$allgmofiles");
 
1622
  } else {
 
1623
    substituteLine ($lookup, "$pofileLine\nGMOFILES =$allgmofiles");
 
1624
  }
 
1625
 
 
1626
    if ($allgmofiles) {
 
1627
 
 
1628
        # Add the "clean" rule so that the maintainer-clean does something
 
1629
        appendLines ("clean-nls:\n\t-rm -f $allgmofiles\n");
 
1630
 
 
1631
        $target_adds{"maintainer-clean"} .= "clean-nls ";
 
1632
 
 
1633
        $lookup = 'DISTFILES\s*=[ \t]*(.*)';
 
1634
        if ($MakefileData =~ /\n$lookup/) {
 
1635
          $tmp = "DISTFILES = \$(GMOFILES) \$(POFILES) $1";
 
1636
          substituteLine ($lookup, $tmp);
 
1637
        }
 
1638
    }
 
1639
 
 
1640
  $target_adds{"install-data-am"} .= "install-nls ";
 
1641
 
 
1642
  $tmp = "install-nls:\n";
 
1643
  if ($lang) {
 
1644
    $tmp  .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES\n";
 
1645
  }
 
1646
  $tmp .= "\t\@for base in ";
 
1647
  foreach $pofile (@pofiles)
 
1648
    {
 
1649
      $pofile =~ /(.*)\.[^\.]*$/;          # Find name minus extension
 
1650
      $tmp .= "$1 ";
 
1651
    }
 
1652
 
 
1653
  $tmp .= "; do \\\n";
 
1654
  if ($lang) {
 
1655
    $tmp .= "\t  echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n";
 
1656
    $tmp .= "\t  if test -f \$\$base.gmo; then \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n";
 
1657
    $tmp .= "\t  elif test -f \$(srcdir)/\$\$base.gmo; then \$(INSTALL_DATA) \$(srcdir)/\$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n";
 
1658
    $tmp .= "\t  fi ;\\\n";
 
1659
  } else {
 
1660
    $tmp .= "\t  echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
 
1661
    $tmp .= "\t  \$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES ; \\\n";
 
1662
    $tmp .= "\t  if test -f \$\$base.gmo; then \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
 
1663
    $tmp .= "\t  elif test -f \$(srcdir)/\$\$base.gmo; then \$(INSTALL_DATA) \$(srcdir)/\$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
 
1664
    $tmp .= "\t  fi ;\\\n";
 
1665
  }
 
1666
  $tmp .= "\tdone\n\n";
 
1667
  appendLines ($tmp);
 
1668
 
 
1669
  $target_adds{"uninstall"} .= "uninstall-nls ";
 
1670
 
 
1671
  $tmp = "uninstall-nls:\n";
 
1672
  foreach $pofile (@pofiles)
 
1673
    {
 
1674
      $pofile =~ /(.*)\.[^\.]*$/;          # Find name minus extension
 
1675
      if ($lang) {
 
1676
        $tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/$1.mo\n";
 
1677
      } else {
 
1678
        $tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$1/LC_MESSAGES/\$(PACKAGE).mo\n";
 
1679
      }
 
1680
    }
 
1681
  appendLines($tmp);
 
1682
 
 
1683
  $target_adds{"all"} .= "all-nls ";
 
1684
 
 
1685
  $tmp = "all-nls: \$(GMOFILES)\n";
 
1686
 
 
1687
  appendLines($tmp);
 
1688
 
 
1689
  $target_adds{"distdir"} .= "distdir-nls ";
 
1690
 
 
1691
  $tmp = "distdir-nls:\$(GMOFILES)\n";
 
1692
  $tmp .= "\tfor file in \$(POFILES); do \\\n";
 
1693
  $tmp .= "\t  cp \$(srcdir)/\$\$file \$(distdir); \\\n";
 
1694
  $tmp .= "\tdone\n";
 
1695
  $tmp .= "\tfor file in \$(GMOFILES); do \\\n";
 
1696
  $tmp .= "\t  cp \$(srcdir)/\$\$file \$(distdir); \\\n";
 
1697
  $tmp .= "\tdone\n";
 
1698
 
 
1699
  appendLines ($tmp);
 
1700
 
 
1701
  if (!$lang) {
 
1702
    appendLines("merge:\n\t\$(MAKE) -f \$(top_srcdir)/admin/Makefile.common package-merge POFILES=\"\${POFILES}\" PACKAGE=\${PACKAGE}\n\n");
 
1703
  }
 
1704
 
 
1705
}
 
1706
 
 
1707
#-----------------------------------------------------------------------------
 
1708
 
 
1709
# Returns 0 if the line was processed - 1 otherwise.
 
1710
# Errors are logged in the global $errorflags
 
1711
sub tag_POFILES ()
 
1712
{
 
1713
    my $lookup = 'POFILES\s*=([^\n]*)';
 
1714
    return 1    if ($MakefileData !~ /\n$lookup/);
 
1715
    print STDOUT "POFILES processing <$1>\n"   if ($verbose);
 
1716
 
 
1717
    my $tmp = $1;
 
1718
 
 
1719
    # make sure these are all gone.
 
1720
    if ($MakefileData =~ /\n\.po\.gmo:\n/)
 
1721
    {
 
1722
        print STDERR "Warning: Found old .po.gmo rules in $printname. New po rules not added\n";
 
1723
        return 1;
 
1724
    }
 
1725
 
 
1726
    # Either find the pofiles in the directory (AUTO) or use
 
1727
    # only the specified po files.
 
1728
    my $pofiles = "";
 
1729
    if ($tmp =~ /^\s*AUTO\s*$/)
 
1730
    {
 
1731
        opendir (THISDIR, ".");
 
1732
        $pofiles =  join(" ", grep(/\.po$/, readdir(THISDIR)));
 
1733
        closedir (THISDIR);
 
1734
        print STDOUT "pofiles found = $pofiles\n"   if ($verbose);
 
1735
        if (-f "charset" && -f "kdelibs/kdelibs.po") {
 
1736
            handle_TOPLEVEL();
 
1737
        }
 
1738
    }
 
1739
    else
 
1740
    {
 
1741
        $tmp =~ s/\034/ /g;
 
1742
        $pofiles = $tmp;
 
1743
    }
 
1744
    return 1    if (!$pofiles);        # Nothing to do
 
1745
 
 
1746
    handle_POFILES($pofiles, $kdelang);
 
1747
 
 
1748
    return 0;
 
1749
}
 
1750
 
 
1751
sub helper_LOCALINSTALL($)
 
1752
{
 
1753
  my $lookup = "\035" . $_[0] . " *:[^\035]*\035\t";
 
1754
  my $copy = $MakefileData;
 
1755
  $copy =~ s/\n/\035/g;
 
1756
  if ($copy =~ /($lookup.*)$/) {
 
1757
 
 
1758
    $install = $1;
 
1759
    $install =~ s/\035$_[0] *:[^\035]*\035//;
 
1760
    my $emptyline = 0;
 
1761
    while (! $emptyline ) {
 
1762
      if ($install =~ /([^\035]*)\035(.*)/) {
 
1763
        local $line = $1;
 
1764
        $install = $2;
 
1765
        if ($line !~ /^\s*$/ && $line !~ /^(\@.*\@)*\t/) {
 
1766
          $emptyline = 1;
 
1767
        } else {
 
1768
          replaceDestDir($line);
 
1769
        }
 
1770
      } else {
 
1771
        $emptyline = 1;
 
1772
      }
 
1773
    }
 
1774
  }
 
1775
 
 
1776
}
 
1777
 
 
1778
sub tag_LOCALINSTALL ()
 
1779
{
 
1780
  helper_LOCALINSTALL('install-exec-local');
 
1781
  helper_LOCALINSTALL('install-data-local');
 
1782
  helper_LOCALINSTALL('uninstall-local');
 
1783
 
 
1784
  return 0;
 
1785
}
 
1786
 
 
1787
sub replaceDestDir($) {
 
1788
  local $line = $_[0];
 
1789
 
 
1790
  if (   $line =~ /^\s*(\@.*\@)*\s*\$\(mkinstalldirs\)/
 
1791
      || $line =~ /^\s*(\@.*\@)*\s*\$\(INSTALL\S*\)/
 
1792
      || $line =~ /^\s*(\@.*\@)*\s*(-?rm.*) \S*$/)
 
1793
  {
 
1794
    $line =~ s/^(.*) ([^\s]+)\s*$/$1 \$(DESTDIR)$2/ if ($line !~ /\$\(DESTDIR\)/);
 
1795
  }
 
1796
 
 
1797
  if ($line ne $_[0]) {
 
1798
    $_[0] = quotemeta $_[0];
 
1799
    substituteLine($_[0], $line);
 
1800
  }
 
1801
}
 
1802
 
 
1803
#---------------------------------------------------------------------------
 
1804
# libtool is very hard to persuade it could use -Wl,--no-undefined for making
 
1805
# -no-undefined actually work
 
1806
# append $(KDE_NO_UNFINED) after every -no-undefined in LDFLAGS
 
1807
# this may go away if libtool ever does this on its own
 
1808
sub tag_NO_UNDEFINED () {
 
1809
    return if ($program !~ /_la$/);
 
1810
 
 
1811
    my $lookup = quotemeta($realname{$program}) . ":.*?\n\t.*?\\((.*?)\\) .*\n";
 
1812
    $MakefileData =~ m/$lookup/;
 
1813
    return if (!defined($1));
 
1814
    return if ($1 !~ /CXXLINK/);
 
1815
 
 
1816
    if ($MakefileData !~ /\n$program\_LDFLAGS\s*=.*-no-undefined/ ) {
 
1817
        return;
 
1818
    }
 
1819
 
 
1820
    $lookup = $program . '\_LDFLAGS(\s*)=(.*)-no-undefined(.*)';
 
1821
    if ($MakefileData =~ /\n$lookup\n/) {
 
1822
        my $replace = $program . "\_LDFLAGS$1=$2-no-undefined \$(KDE_NO_UNDEFINED)$3";
 
1823
        substituteLine($lookup, $replace);
 
1824
    }
 
1825
}
 
1826
 
 
1827
sub tag_CLOSURE () {
 
1828
    return if ($program !~ /_la$/);
 
1829
 
 
1830
    my $lookup = quotemeta($realname{$program}) . ":.*?\n\t.*?\\((.*?)\\) .*\n";
 
1831
    $MakefileData =~ m/$lookup/;
 
1832
    return if (!defined($1));
 
1833
    return if ($1 !~ /CXXLINK/);
 
1834
 
 
1835
    if ($MakefileData !~ /\n$program\_LDFLAGS\s*=.*-no-undefined/ &&
 
1836
        $MakefileData !~ /\n$program\_LDFLAGS\s*=.*KDE_PLUGIN/ ) {
 
1837
        print STDERR "Report: $program contains undefined in $printname\n" if ($program =~ /^lib/ && $dryrun);
 
1838
        return;
 
1839
    }
 
1840
 
 
1841
    my $closure = $realname{$program} . ".closure";
 
1842
    my $lines = "$closure: \$($program\_OBJECTS) \$($program\_DEPENDENCIES)\n";
 
1843
    $lines .= "\t\@echo \"int main() {return 0;}\" > $program\_closure.$cxxsuffix\n";
 
1844
    $lines .= "\t\@\$\(LTCXXCOMPILE\) -c $program\_closure.$cxxsuffix\n";
 
1845
    $lines .= "\t\$\(CXXLINK\) $program\_closure.lo \$($program\_LDFLAGS) \$($program\_OBJECTS) \$($program\_LIBADD) \$(LIBS)\n";
 
1846
    $lines .= "\t\@rm -f $program\_closure.* $closure\n";
 
1847
    $lines .= "\t\@echo \"timestamp\" > $closure\n";
 
1848
    $lines .= "\n";
 
1849
    appendLines($lines);
 
1850
    $lookup = $realname{$program} . ": (.*)";
 
1851
    if ($MakefileData =~ /\n$lookup\n/) {
 
1852
        $lines  = "\@KDE_USE_CLOSURE_TRUE@". $realname{$program} . ": $closure $1";
 
1853
        $lines .= "\n\@KDE_USE_CLOSURE_FALSE@" . $realname{$program} . ": $1";
 
1854
        substituteLine($lookup, $lines);
 
1855
    }
 
1856
    $closure_output .= " $closure";
 
1857
}
 
1858
 
 
1859
sub tag_NMCHECK () {
 
1860
    return if ($program !~ /_la$/);
 
1861
    my $lookup = quotemeta($realname{$program}) . ":.*?\n\t.*?\\((.*?)\\) .*\n";
 
1862
    $MakefileData =~ m/$lookup/;
 
1863
    my $linkcmd = $1;
 
1864
    return if (!defined($1));
 
1865
    return if ($linkcmd !~ /CXXLINK/ && $linkcmd !~ /LINK/);
 
1866
 
 
1867
    $lookup = $program . '_NMCHECK\s*=([^\n]*)';
 
1868
    if( $MakefileData !~ m/\n$lookup\n/ ) {
 
1869
        return;
 
1870
    }
 
1871
    my $allowed = $1;
 
1872
    $allowed =~ s/^ *//;
 
1873
    $lookup = $program . '_NMCHECKWEAK\s*=([^\n]*)';
 
1874
    my $weak = "";
 
1875
    my $is_weak = 0;
 
1876
    if( $MakefileData =~ m/\n$lookup\n/ ) {
 
1877
        $weak = $1;
 
1878
        $is_weak = 1;
 
1879
    }
 
1880
    $weak =~ s/^ *//;
 
1881
 
 
1882
    if( $is_weak )
 
1883
    {
 
1884
        $weak = '--allowweak=\'' . $weak . '\' ';
 
1885
    }
 
1886
    my $nmline = "\@KDE_USE_NMCHECK_TRUE@\t\@\$(MAKE) \$(AM_MAKEFLAGS) nmcheck_$realname{$program} || ( rm -f $realname{$program}; exit 1 )";
 
1887
    $lookup = '(\t\$\(CXXLINK\)[^\n]*' . $program . '_OBJECTS[^\n]*)';
 
1888
    if( $MakefileData =~ /\n$lookup\n/ ) {
 
1889
        my $oldstuff = $1;
 
1890
        substituteLine( $lookup, $oldstuff . "\n" . $nmline );
 
1891
    }
 
1892
    $lookup = '(\t\$\(LINK\)[^\n]*' . $program . '_OBJECTS[^\n]*)';
 
1893
    if( $MakefileData =~ /\n$lookup\n/ ) {
 
1894
        my $oldstuff = $1;
 
1895
        substituteLine( $lookup, $oldstuff . "\n" . $nmline );
 
1896
    }
 
1897
    $nmline = "\@\$(top_srcdir)/admin/nmcheck $realname{$program} \'$allowed\' $weak";
 
1898
    appendLines( "\nnmcheck_$realname{$program}: $realname{$program} \n\t$nmline\n" );
 
1899
    $target_adds{ "nmcheck" } .= "nmcheck_$realname{$program} ";
 
1900
}
 
1901
 
 
1902
sub tag_DIST () {
 
1903
    my %foundfiles = ();
 
1904
    opendir (THISDIR, ".");
 
1905
    foreach $entry (readdir(THISDIR)) {
 
1906
        next if ($entry eq "CVS" || $entry =~ /^\./  || $entry eq "Makefile" || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
 
1907
        next if (! -f $entry);
 
1908
        next if ($entry =~ /\.moc/ || $entry =~ /\.moc.$cppExt$/ || $entry =~ /\.lo$/ || $entry =~ /\.la$/ || $entry =~ /\.o/);
 
1909
        next if ($entry =~ /\.all_$cppExt\.$cppExt$/);
 
1910
        $foundfiles{$entry} = 1;
 
1911
    }
 
1912
    closedir (THISDIR);
 
1913
 
 
1914
    # doing this for MAINTAINERCLEANFILES would be wrong
 
1915
    my @marks = ("EXTRA_DIST", "DIST_COMMON", '\S*_SOURCES', '\S*_HEADERS', 'CLEANFILES', 'DISTCLEANFILES', '\S*_OBJECTS');
 
1916
    foreach $mark (@marks) {
 
1917
        while ($MakefileData =~ /\n($mark)\s*=[ \t]*([^\n]*)/g) {
 
1918
            my $cleanfiles_str = $2;
 
1919
            foreach $file (split('[\034\s]+', $cleanfiles_str)) {
 
1920
                $file =~ s/\.\///;
 
1921
                $foundfiles{$file} = 0 if (defined $foundfiles{$file});
 
1922
            }
 
1923
        }
 
1924
    }
 
1925
    my @files = ("Makefile", "config.cache", "config.log", "stamp-h",
 
1926
                 "stamp-h1", "stamp-h1", "config.h", "Makefile", 
 
1927
                 "config.status", "config.h", "libtool", "core" );
 
1928
    foreach $file (@files) {
 
1929
        $foundfiles{$file} = 0 if (defined $foundfiles{$file});
 
1930
    }
 
1931
 
 
1932
    my $KDE_DIST = "";
 
1933
    foreach $file (keys %foundfiles) {
 
1934
        if ($foundfiles{$file} == 1) {
 
1935
            $KDE_DIST .= "$file ";
 
1936
        }
 
1937
    }
 
1938
    if ($KDE_DIST) {
 
1939
        print "KDE_DIST $printname $KDE_DIST\n" if ($verbose);
 
1940
 
 
1941
        my $lookup = 'DISTFILES\s*=[ \t]*(.*)';
 
1942
        if ($MakefileData =~ /\n$lookup/) {
 
1943
            substituteLine($lookup, "DISTFILES = $1 \$(KDE_DIST)");
 
1944
            appendLines("KDE_DIST=$KDE_DIST\n");
 
1945
        }
 
1946
    }
 
1947
}
 
1948
 
 
1949
#-----------------------------------------------------------------------------
 
1950
# Returns 0 if the line was processed - 1 otherwise.
 
1951
# Errors are logged in the global $errorflags
 
1952
sub tag_DOCFILES ()
 
1953
{
 
1954
    $target_adds{"all"} .= "docs-am ";
 
1955
 
 
1956
    my $lookup = 'KDE_DOCS\s*=[ \t]*([^\n]*)';
 
1957
    goto nodocs    if ($MakefileData !~ /\n$lookup/);
 
1958
    print STDOUT "KDE_DOCS processing <$1>\n"   if ($verbose);
 
1959
 
 
1960
    my $tmp = $1;
 
1961
 
 
1962
    # Either find the files in the directory (AUTO) or use
 
1963
    # only the specified po files.
 
1964
    my $files = "";
 
1965
    my $appname = $tmp;
 
1966
    $appname =~ s/^(\S*)\s*.*$/$1/;
 
1967
    if ($appname =~ /AUTO/) {
 
1968
      $appname = basename($makefileDir);
 
1969
      if ("$appname" eq "en") {
 
1970
          print STDERR "Error: KDE_DOCS = AUTO relies on the directory name. Yours is 'en' - you most likely want something else, e.g. KDE_DOCS = myapp\n";
 
1971
          exit(1);
 
1972
      }
 
1973
    }
 
1974
 
 
1975
    if ($tmp !~ / - /)
 
1976
    {
 
1977
        opendir (THISDIR, ".");
 
1978
        foreach $entry (readdir(THISDIR)) {
 
1979
          next if ($entry eq "CVS" || $entry =~ /^\./  || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/ || $entry eq "core" || $entry eq "index.cache.bz2");
 
1980
          next if (! -f $entry);
 
1981
          $files .= "$entry ";
 
1982
        }
 
1983
        closedir (THISDIR);
 
1984
        print STDOUT "docfiles found = $files\n"   if ($verbose);
 
1985
    }
 
1986
    else
 
1987
    {
 
1988
        $tmp =~ s/\034/ /g;
 
1989
        $tmp =~ s/^\S*\s*-\s*//;
 
1990
        $files = $tmp;
 
1991
    }
 
1992
    goto nodocs if (!$files);        # Nothing to do
 
1993
 
 
1994
    if ($files =~ /(^| )index\.docbook($| )/) {
 
1995
 
 
1996
      my $lines = "";
 
1997
      my $lookup = 'MEINPROC\s*=';
 
1998
      if ($MakefileData !~ /\n($lookup)/) {
 
1999
        $lines = "MEINPROC=/\$(kde_bindir)/meinproc\n";
 
2000
      }
 
2001
      $lookup = 'KDE_XSL_STYLESHEET\s*=';
 
2002
      if ($MakefileData !~ /\n($lookup)/) {
 
2003
        $lines .= "KDE_XSL_STYLESHEET=/\$(kde_datadir)/ksgmltools2/customization/kde-chunk.xsl\n";
 
2004
      }
 
2005
      $lookup = '\nindex.cache.bz2:';
 
2006
      if ($MakefileData !~ /\n($lookup)/) {
 
2007
         $lines .= "index.cache.bz2: \$(srcdir)/index.docbook \$(KDE_XSL_STYLESHEET) $files\n";
 
2008
         $lines .= "\t\@if test -n \"\$(MEINPROC)\"; then echo \$(MEINPROC) --check --cache index.cache.bz2 \$(srcdir)/index.docbook; \$(MEINPROC) --check --cache index.cache.bz2 \$(srcdir)/index.docbook; fi\n";
 
2009
         $lines .= "\n";
 
2010
      }
 
2011
 
 
2012
      $lines .= "docs-am: index.cache.bz2\n";
 
2013
      $lines .= "\n";
 
2014
      $lines .= "install-docs: docs-am install-nls\n";
 
2015
      $lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n";
 
2016
      $lines .= "\t\@if test -f index.cache.bz2; then \\\n";
 
2017
      $lines .= "\techo \$(INSTALL_DATA) index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n";
 
2018
      $lines .= "\t\$(INSTALL_DATA) index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n";
 
2019
      $lines .= "\telif test -f  \$(srcdir)/index.cache.bz2; then \\\n";
 
2020
      $lines .= "\techo \$(INSTALL_DATA) \$(srcdir)/index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n";
 
2021
      $lines .= "\t\$(INSTALL_DATA) \$(srcdir)/index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n";
 
2022
      $lines .= "\tfi\n";
 
2023
      $lines .= "\t-rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n";
 
2024
      $lines .= "\t\$(LN_S) \$(kde_libs_htmldir)/$kdelang/common \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n";
 
2025
 
 
2026
      $lines .= "\n";
 
2027
      $lines .= "uninstall-docs:\n";
 
2028
      $lines .= "\t-rm -rf \$(kde_htmldir)/$kdelang/$appname\n";
 
2029
      $lines .= "\n";
 
2030
      $lines .= "clean-docs:\n";
 
2031
      $lines .= "\t-rm -f index.cache.bz2\n";
 
2032
      $lines .= "\n";
 
2033
      $target_adds{"install-data-am"} .= "install-docs ";
 
2034
      $target_adds{"uninstall"} .= "uninstall-docs ";
 
2035
      $target_adds{"clean-am"} .= "clean-docs ";
 
2036
      appendLines ($lines);
 
2037
    } else {
 
2038
      appendLines("docs-am: $files\n");
 
2039
    }
 
2040
 
 
2041
    $target_adds{"install-data-am"} .= "install-nls ";
 
2042
    $target_adds{"uninstall"} .= "uninstall-nls ";
 
2043
 
 
2044
    $tmp = "install-nls:\n";
 
2045
    $tmp .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n";
 
2046
    $tmp .= "\t\@for base in $files; do \\\n";
 
2047
    $tmp .= "\t  echo \$(INSTALL_DATA) \$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
 
2048
    $tmp .= "\t  \$(INSTALL_DATA) \$(srcdir)/\$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
 
2049
    $tmp .= "\tdone\n";
 
2050
    if ($appname eq 'common') {
 
2051
      $tmp .= "\t\@echo \"merging common and language specific dir\" ;\\\n";
 
2052
      $tmp .= "\tif test ! -f \$(kde_htmldir)/en/common/kde-common.css; then echo 'no english docs found in \$(kde_htmldir)/en/common/'; exit 1; fi \n";
 
2053
      $tmp .= "\t\@com_files=`cd \$(kde_htmldir)/en/common && echo *` ;\\\n";
 
2054
      $tmp .= "\tcd \$(DESTDIR)\$(kde_htmldir)/$kdelang/common ;\\\n";
 
2055
      $tmp .= "\tif test -n \"\$\$com_files\"; then for p in \$\$com_files ; do \\\n";
 
2056
      $tmp .= "\t  case \" $files \" in \\\n";
 
2057
      $tmp .= "\t    *\" \$\$p \"*) ;; \\\n";
 
2058
      $tmp .= "\t    *) test ! -f \$\$p && echo \$(LN_S) ../../en/common/\$\$p \$(DESTDIR)\$(kde_htmldir)/$kdelang/common/\$\$p && \$(LN_S) ../../en/common/\$\$p \$\$p ;; \\\n";
 
2059
      $tmp .= "\t  esac ; \\\n";
 
2060
      $tmp .= "\tdone ; fi ; true\n";
 
2061
    }
 
2062
    $tmp .= "\n";
 
2063
    $tmp .= "uninstall-nls:\n";
 
2064
    $tmp .= "\tfor base in $files; do \\\n";
 
2065
    $tmp .= "\t  rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
 
2066
    $tmp .= "\tdone\n\n";
 
2067
    appendLines ($tmp);
 
2068
 
 
2069
    $target_adds{"distdir"} .= "distdir-nls ";
 
2070
 
 
2071
    $tmp = "distdir-nls:\n";
 
2072
    $tmp .= "\tfor file in $files; do \\\n";
 
2073
    $tmp .= "\t  cp \$(srcdir)/\$\$file \$(distdir); \\\n";
 
2074
    $tmp .= "\tdone\n";
 
2075
 
 
2076
    appendLines ($tmp);
 
2077
 
 
2078
    return 0;
 
2079
 
 
2080
  nodocs:
 
2081
    appendLines("docs-am:\n");
 
2082
    return 1;
 
2083
}
 
2084
 
 
2085
#-----------------------------------------------------------------------------
 
2086
# Find headers in any of the source directories specified previously, that
 
2087
# are candidates for "moc-ing".
 
2088
sub findMocCandidates ()
 
2089
{
 
2090
    foreach $dir (@headerdirs)
 
2091
    {
 
2092
        my @list = ();
 
2093
        opendir (SRCDIR, "$dir");
 
2094
        @hFiles = grep { /.+\.$hExt$/o && !/^\./ } readdir(SRCDIR);
 
2095
        closedir SRCDIR;
 
2096
        foreach $hf (@hFiles)
 
2097
        {
 
2098
            next if ($hf =~ /^\.\#/);
 
2099
            $hf =~ /(.*)\.[^\.]*$/;          # Find name minus extension
 
2100
            next if ($uiFiles{$1});
 
2101
            open (HFIN, "$dir/$hf") || die "Could not open $dir/$hf: $!\n";
 
2102
            my $hfsize = 0;
 
2103
            seek(HFIN, 0, 2);
 
2104
            $hfsize = tell(HFIN);
 
2105
            seek(HFIN, 0, 0);
 
2106
            read HFIN, $hfData, $hfsize;
 
2107
            close HFIN;
 
2108
            # push (@list, $hf) if(index($hfData, "Q_OBJECT") >= 0); ### fast but doesn't handle //Q_OBJECT
 
2109
            # handle " { friend class blah; Q_OBJECT ", but don't match antlarr_Q_OBJECT (\b).
 
2110
            if ( $hfData =~ /{([^}]*)\bQ_OBJECT/s ) {
 
2111
                push (@list, $hf) unless $1 =~ m://[^\n]*Q_OBJECT[^\n]*$:s;  ## reject "// Q_OBJECT"
 
2112
            }
 
2113
        }
 
2114
        # The assoc array of root of headerfile and header filename
 
2115
        foreach $hFile (@list)
 
2116
        {
 
2117
            $hFile =~ /(.*)\.[^\.]*$/;          # Find name minus extension
 
2118
            if ($mocFiles{$1})
 
2119
            {
 
2120
              print STDERR "Warning: Multiple header files found for $1\n";
 
2121
              next;                           # Use the first one
 
2122
            }
 
2123
            $mocFiles{$1} = "$dir\035$hFile";   # Add relative dir
 
2124
        }
 
2125
    }
 
2126
 
 
2127
    return 0;
 
2128
}
 
2129
 
 
2130
#-----------------------------------------------------------------------------
 
2131
 
 
2132
# The programmer has specified a moc list. Prune out the moc candidates
 
2133
# list that we found based on looking at the header files. This generates
 
2134
# a warning if the programmer gets the list wrong, but this doesn't have
 
2135
# to be fatal here.
 
2136
sub pruneMocCandidates ($)
 
2137
{
 
2138
    my %prunedMoc = ();
 
2139
    local @mocList = split(' ', $_[0]);
 
2140
 
 
2141
    foreach $mocname (@mocList)
 
2142
    {
 
2143
        $mocname =~ s/\.moc$//;
 
2144
        if ($mocFiles{$mocname})
 
2145
        {
 
2146
            $prunedMoc{$mocname} = $mocFiles{$mocname};
 
2147
        }
 
2148
        else
 
2149
        {
 
2150
            my $print = $makefileDir;
 
2151
            $print =~ s/^\Q$topdir\E\\//;
 
2152
            # They specified a moc file but we can't find a header that
 
2153
            # will generate this moc file. That's possible fatal!
 
2154
            print STDERR "Warning: No moc-able header file for $print/$mocname\n";
 
2155
        }
 
2156
    }
 
2157
 
 
2158
    undef %mocFiles;
 
2159
    %mocFiles = %prunedMoc;
 
2160
}
 
2161
 
 
2162
#-----------------------------------------------------------------------------
 
2163
 
 
2164
# Finds the cpp files (If they exist).
 
2165
# The cpp files get appended to the header file separated by \035
 
2166
sub checkMocCandidates ()
 
2167
{
 
2168
    my @cppFiles;
 
2169
    my $cpp2moc;  # which c++ file includes which .moc files
 
2170
    my $moc2cpp;  # which moc file is included by which c++ files
 
2171
 
 
2172
    return unless (keys %mocFiles);
 
2173
    opendir(THISDIR, ".") || return;
 
2174
    @cppFiles = grep { /.+\.$cppExt$/o  && !/.+\.moc\.$cppExt$/o
 
2175
                         && !/.+\.all_$cppExt\.$cppExt$/o
 
2176
                         && !/^\./  } readdir(THISDIR);
 
2177
    closedir THISDIR;
 
2178
    return unless (@cppFiles);
 
2179
    my $files = join (" ", @cppFiles);
 
2180
    $cpp2moc = {};
 
2181
    $moc2cpp = {};
 
2182
    foreach $cxxf (@cppFiles)
 
2183
    {
 
2184
      open (CXXFIN, $cxxf) || die "Could not open $cxxf: $!\n";
 
2185
      seek(CXXFIN, 0, 2);
 
2186
      my $cxxfsize = tell(CXXFIN);
 
2187
      seek(CXXFIN, 0, 0);
 
2188
      read CXXFIN, $cxxfData, $cxxfsize;
 
2189
      close CXXFIN;
 
2190
      while(($cxxfData =~ m/^[ \t]*\#include\s*[<\"](.*\.moc)[>\"]/gm)) {
 
2191
        $cpp2moc->{$cxxf}->{$1} = 1;
 
2192
        $moc2cpp->{$1}->{$cxxf} = 1;
 
2193
      }
 
2194
    }
 
2195
    foreach my $mocFile (keys (%mocFiles))
 
2196
    {
 
2197
        @cppFiles = keys %{$moc2cpp->{"$mocFile.moc"}};
 
2198
        if (@cppFiles == 1) {
 
2199
            $mocFiles{$mocFile} .= "\035" . $cppFiles[0];
 
2200
            push(@depend, $mocFile);
 
2201
        } elsif (@cppFiles == 0) {
 
2202
            push (@newObs, $mocFile);           # Produce new object file
 
2203
            next    if ($haveAutomocTag);       # This is expected...
 
2204
            # But this is an error we can deal with - let them know
 
2205
            print STDERR
 
2206
                "Warning: No c++ file that includes $mocFile.moc\n";
 
2207
        } else {
 
2208
            # We can't decide which file to use, so it's fatal. Although as a
 
2209
            # guess we could use the mocFile.cpp file if it's in the list???
 
2210
            print STDERR
 
2211
                "Error: Multiple c++ files that include $mocFile.moc\n";
 
2212
            print STDERR "\t",join ("\t", @cppFiles),"\n";
 
2213
            $errorflag = 1;
 
2214
            delete $mocFiles{$mocFile};
 
2215
            # Let's continue and see what happens - They have been told!
 
2216
        }
 
2217
    }
 
2218
}
 
2219
 
 
2220
#-----------------------------------------------------------------------------
 
2221
 
 
2222
# Add the rules for generating moc source from header files
 
2223
# For Automoc output *.moc.cpp but normally we'll output *.moc
 
2224
# (We must compile *.moc.cpp separately. *.moc files are included
 
2225
# in the appropriate *.cpp file by the programmer)
 
2226
sub addMocRules ()
 
2227
{
 
2228
    my $cppFile;
 
2229
    my $hFile;
 
2230
 
 
2231
    foreach $mocFile (keys (%mocFiles))
 
2232
    {
 
2233
        undef $cppFile;
 
2234
        ($dir, $hFile, $cppFile) =  split ("\035", $mocFiles{$mocFile}, 3);
 
2235
        $dir =~ s#^\.#\$(srcdir)#;
 
2236
        if (defined ($cppFile))
 
2237
        {
 
2238
          $cppFile =~ s,\.[^.]*$,,;
 
2239
          $target_adds{"$cppFile.o"} .= "$mocFile.moc ";
 
2240
          $target_adds{"$cppFile.lo"} .= "$mocFile.moc ";
 
2241
          appendLines ("$mocFile.moc: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile.moc\n");
 
2242
          $cleanMoc .= " $mocFile.moc";
 
2243
          appendLines ("mocs: $mocFile.moc\n");
 
2244
        }
 
2245
        else
 
2246
        {
 
2247
            appendLines ("$mocFile$mocExt: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile$mocExt\n");
 
2248
            $cleanMoc .= " $mocFile$mocExt";
 
2249
            appendLines ("mocs: $mocFile$mocExt\n");
 
2250
        }
 
2251
    }
 
2252
}
 
2253
 
 
2254
sub make_bcheck_target()
 
2255
{
 
2256
    my $lookup = 'RECURSIVE_TARGETS\s*=[ \t]*(.*)';
 
2257
    my $bcheckdep = "bcheck-am";
 
2258
    $bcheckdep = "bcheck-recursive" if ($MakefileData =~ /\n$lookup/);
 
2259
 
 
2260
    my $headers= "";
 
2261
    $headers = $1 if($MakefileData =~ /\nHEADERS\s*=[ \t]*(.+)/);
 
2262
    $headers =~ s/\$\((?:noinst|EXTRA)_HEADERS\)//g;
 
2263
 
 
2264
    $target_adds{"clean-am"} .= "clean-bcheck ";
 
2265
 
 
2266
    my $t = "clean-bcheck: \n" .
 
2267
            "\trm -f *.bchecktest.cc *.bchecktest.cc.class a.out\n\n" .
 
2268
            "bcheck: $bcheckdep\n\n" .
 
2269
            "bcheck-am:\n" .
 
2270
           "\t\@for i in $headers; do \\\n" .
 
2271
           "\t    if test \$(srcdir)/\$\$i -nt \$\$i.bchecktest.cc; then \\\n" . 
 
2272
           "\t        echo \"int main() {return 0;}\" > \$\$i.bchecktest.cc ; \\\n" .
 
2273
           "\t        echo \"#include \\\"\$\$i\\\"\" >> \$\$i.bchecktest.cc ; \\\n" .
 
2274
           "\t        echo \"\$\$i\"; \\\n" . 
 
2275
           "\t        if ! ";
 
2276
    $t .=  $cxxsuffix eq "KKK" ?
 
2277
           "\$(CXX) \$(DEFS) -I. -I\$(srcdir) -I\$(top_builddir) \$(INCLUDES) \$(AM_CPPFLAGS) \$(CPPFLAGS) \$(KDE_CXXFLAGS) " :
 
2278
           "\$(CXXCOMPILE) ";
 
2279
    $t .=  " --dump-class-hierarchy -c \$\$i.bchecktest.cc; then \\\n" .
 
2280
           "\t            rm -f \$\$i.bchecktest.cc; exit 1; \\\n" .
 
2281
           "\t        fi ; \\\n" .
 
2282
           "\t        echo \"\" >> \$\$i.bchecktest.cc.class; \\\n" .
 
2283
           "\t        perl \$(top_srcdir)/admin/bcheck.pl \$\$i.bchecktest.cc.class || { rm -f \$\$i.bchecktest.cc; exit 1; }; \\\n" .
 
2284
           "\t        rm -f a.out; \\\n" .
 
2285
           "\t    fi ; \\\n" .
 
2286
           "\tdone\n";
 
2287
    appendLines("$t\n");
 
2288
}
 
2289
 
 
2290
sub make_meta_classes ()
 
2291
{
 
2292
    return if ($kdeopts{"qtonly"});
 
2293
 
 
2294
    my $cppFile;
 
2295
    my $hFile;
 
2296
    my $moc_class_headers = "";
 
2297
    foreach $program (@programs) {
 
2298
        my $mocs = "";
 
2299
        my @progsources = split(/[\034\s]+/, $sources{$program});
 
2300
        my @depmocs = split(' ', $dependmocs{$program});
 
2301
        my %shash = (), %mhash = ();
 
2302
        @shash{@progsources} = 1;  # we are only interested in the existence
 
2303
        @mhash{@depmocs} = 1;
 
2304
 
 
2305
        print STDOUT "program=$program\n" if ($verbose);
 
2306
        print STDOUT "psources=[".join(' ', keys %shash)."]\n" if ($verbose);
 
2307
        print STDOUT "depmocs=[".join(' ', keys %mhash)."]\n" if ($verbose);
 
2308
        print STDOUT "globalmocs=[".join(' ', keys(%globalmocs))."]\n" if ($verbose);
 
2309
        foreach my $mocFile (keys (%globalmocs))
 
2310
        {
 
2311
            my ($dir, $hFile, $cppFile) = split ("\035", $globalmocs{$mocFile}, 3);
 
2312
            if (defined ($cppFile))
 
2313
            {
 
2314
                $mocs .= " $mocFile.moc" if exists $shash{$cppFile};
 
2315
            }
 
2316
            else
 
2317
            {
 
2318
                # Bah. This is the case, if no C++ file includes the .moc
 
2319
                # file. We make a .moc.cpp file for that. Unfortunately this
 
2320
                # is not included in the %sources hash, but rather is mentioned
 
2321
                # in %dependmocs. If the user wants to use AUTO he can't just
 
2322
                # use an unspecific METAINCLUDES. Instead he must use
 
2323
                # program_METAINCLUDES. Anyway, it's not working real nicely.
 
2324
                # E.g. Its not clear what happens if user specifies two
 
2325
                # METAINCLUDES=AUTO in the same Makefile.am.
 
2326
                $mocs .= " $mocFile.moc.$cxxsuffix"
 
2327
                    if exists $mhash{$mocFile.".moc.$cxxsuffix"};
 
2328
            }
 
2329
        }
 
2330
        if ($mocs) {
 
2331
            print STDOUT "==> mocs=[".$mocs."]\n" if ($verbose);
 
2332
        }
 
2333
        print STDOUT "\n" if $verbose;
 
2334
    }
 
2335
    if ($moc_class_headers) {
 
2336
        appendLines ("$cleantarget-moc-classes:\n\t-rm -f $moc_class_headers\n");
 
2337
        $target_adds{"$cleantarget-am"} .= "$cleantarget-moc-classes ";
 
2338
    }
 
2339
}
 
2340
 
 
2341
#-----------------------------------------------------------------------------
 
2342
 
 
2343
sub updateMakefile ()
 
2344
{
 
2345
    return if ($dryrun);
 
2346
 
 
2347
    open (FILEOUT, "> $makefile")
 
2348
                        || die "Could not create $makefile: $!\n";
 
2349
 
 
2350
    $MakefileData =~ s/\034/\\\n/g;    # Restore continuation lines
 
2351
    # Append our $progId line, _below_ the "generated by automake" line
 
2352
    # because automake-1.6 relies on the first line to be his own.
 
2353
    my $progIdLine = "\# $progId - " . '$Revision: 1.5 $ '."\n";
 
2354
    if ( !( $MakefileData =~ s/^(.*generated .*by automake.*\n)/$1$progIdLine/ ) ) {
 
2355
        warn "automake line not found in $makefile\n";
 
2356
        # Fallback: first line
 
2357
        print FILEOUT $progIdLine;
 
2358
    };
 
2359
    print FILEOUT $MakefileData;
 
2360
    close FILEOUT;
 
2361
}
 
2362
 
 
2363
#-----------------------------------------------------------------------------
 
2364
 
 
2365
# The given line needs to be removed from the makefile
 
2366
# Do this by adding the special "removed line" comment at the line start.
 
2367
sub removeLine ($$)
 
2368
{
 
2369
    my ($lookup, $old) = @_;
 
2370
 
 
2371
    $old =~ s/\034/\\\n#>- /g;          # Fix continuation lines
 
2372
    $MakefileData =~ s/\n$lookup/\n#>\- $old/;
 
2373
}
 
2374
 
 
2375
#-----------------------------------------------------------------------------
 
2376
 
 
2377
# Replaces the old line with the new line
 
2378
# old line(s) are retained but tagged as removed. The new line(s) have the
 
2379
# "added" tag placed before it.
 
2380
sub substituteLine ($$)
 
2381
{
 
2382
    my ($lookup, $new) = @_;
 
2383
 
 
2384
    if ($MakefileData =~ /\n($lookup)/) {
 
2385
      $old = $1;
 
2386
      $old =~ s/\034/\\\n#>\- /g;         # Fix continuation lines
 
2387
      my $newCount = ($new =~ tr/\034//) + ($new =~ tr/\n//) + 1;
 
2388
      $new =~ s/\\\n/\034/g;
 
2389
      $MakefileData =~ s/\n$lookup/\n#>- $old\n#>\+ $newCount\n$new/;
 
2390
    } else {
 
2391
        warn "Warning: substitution of \"$lookup\" in $printname failed\n";
 
2392
    }
 
2393
}
 
2394
 
 
2395
#-----------------------------------------------------------------------------
 
2396
 
 
2397
# Slap new lines on the back of the file.
 
2398
sub appendLines ($)
 
2399
{
 
2400
  my ($new) = @_;
 
2401
  my $copynew = $new;
 
2402
  my $newCount = ($new =~ tr/\034//) + ($new =~ tr/\n//) + 1;
 
2403
  $new =~ s/\\\n/\034/g;        # Fix continuation lines
 
2404
  $MakefileData .= "\n#>\+ $newCount\n$new";
 
2405
}
 
2406
 
 
2407
#-----------------------------------------------------------------------------
 
2408
 
 
2409
# Restore the Makefile.in to the state it was before we fiddled with it
 
2410
sub restoreMakefile ()
 
2411
{
 
2412
    $MakefileData =~ s/# $progId[^\n\034]*[\n\034]*//g;
 
2413
    # Restore removed lines
 
2414
    $MakefileData =~ s/([\n\034])#>\- /$1/g;
 
2415
    # Remove added lines
 
2416
    while ($MakefileData =~ /[\n\034]#>\+ ([^\n\034]*)/)
 
2417
    {
 
2418
        my $newCount = $1;
 
2419
        my $removeLines = "";
 
2420
        while ($newCount--) {
 
2421
            $removeLines .= "[^\n\034]*([\n\034]|)";
 
2422
        }
 
2423
        $MakefileData =~ s/[\n\034]#>\+.*[\n\034]$removeLines/\n/;
 
2424
    }
 
2425
}
 
2426
 
 
2427
#-----------------------------------------------------------------------------
 
2428
 
 
2429
# find the .kcfg file listed in the .kcfgc file
 
2430
sub findKcfgFile($)
 
2431
{
 
2432
  my ($kcfgf) = @_;
 
2433
  open (KCFGFIN, $kcfgf) || die "Could not open $kcfgf: $!\n";
 
2434
  seek(KCFGFIN, 0, 2);
 
2435
  my $kcfgfsize = tell(KCFGFIN);
 
2436
  seek(KCFGFIN, 0, 0);
 
2437
  read KCFGFIN, $kcfgfData, $kcfgfsize;
 
2438
  close KCFGFIN;
 
2439
  if(($kcfgfData =~ m/^File=(.*\.kcfg)/gm)) {
 
2440
    $kcfg = $1;
 
2441
  }
 
2442
}