~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to admin/am_edit

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

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
#    ...
 
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
 
 
35
use Cwd;
 
36
use File::Find;
 
37
use File::Basename;
 
38
 
 
39
# Prototype the functions
 
40
sub initialise ();
 
41
sub processMakefile ($);
 
42
sub updateMakefile ();
 
43
sub restoreMakefile ();
 
44
 
 
45
sub removeLine ($$);
 
46
sub appendLines ($);
 
47
sub substituteLine ($$);
 
48
 
 
49
sub findMocCandidates ();
 
50
sub pruneMocCandidates ($);
 
51
sub checkMocCandidates ();
 
52
sub addMocRules ();
 
53
 
 
54
sub tag_AUTOMAKE ();
 
55
sub tag_META_INCLUDES ();
 
56
sub tag_METASOURCES ();
 
57
sub tag_POFILES ();
 
58
sub tag_DOCFILES ();
 
59
sub tag_LOCALINSTALL();
 
60
sub tag_IDLFILES();
 
61
sub tag_UIFILES();
 
62
sub tag_SUBDIRS();
 
63
sub tag_ICON();
 
64
sub tag_CLOSURE();
 
65
sub tag_DIST();
 
66
 
 
67
# Some global globals...
 
68
$verbose    = 0;        # a debug flag
 
69
$thisProg   = "$0";     # This programs name
 
70
$topdir     = cwd();    # The current directory
 
71
@makefiles  = ();       # Contains all the files we'll process
 
72
@foreignfiles = ();
 
73
$start      = (times)[0]; # some stats for testing - comment out for release
 
74
$version    = "v0.2";
 
75
$errorflag  = 0;
 
76
$cppExt     = "(cpp|cc|cxx|C|c\\+\\+)";
 
77
$hExt       = "(h|H|hh|hxx|hpp|h\\+\\+)";
 
78
$progId     = "KDE tags expanded automatically by " . basename($thisProg);
 
79
$automkCall = "\n";
 
80
$printname  = "";  # used to display the directory the Makefile is in
 
81
$use_final  = 1;        # create code for --enable-final
 
82
$cleantarget = "clean";
 
83
$dryrun     = 0;
 
84
$pathoption = 0;
 
85
 
 
86
while (defined ($ARGV[0]))
 
87
{
 
88
    $_ = shift;
 
89
    if (/^--version$/)
 
90
    {
 
91
        print STDOUT "\n";
 
92
        print STDOUT basename($thisProg), " $version\n",
 
93
                "This is really free software, unencumbered by the GPL.\n",
 
94
                "You can do anything you like with it except sueing me.\n",
 
95
                "Copyright 1998 Kalle Dalheimer <kalle\@kde.org>\n",
 
96
                "Concept, design and unnecessary questions about perl\n",
 
97
                "       by Matthias Ettrich <ettrich\@kde.org>\n\n",
 
98
                "Making it useful by Stephan Kulow <coolo\@kde.org> and\n",
 
99
                "Harri Porten <porten\@kde.org>\n",
 
100
                "Updated (Feb-1999), John Birch <jb.nz\@writeme.com>\n",
 
101
                "Current Maintainer Stephan Kulow\n\n";
 
102
        exit 0;
 
103
    }
 
104
    elsif (/^--verbose$|^-v$/)
 
105
    {
 
106
        $verbose = 1;       # Oh is there a problem...?
 
107
    }
 
108
    elsif (/^-p(.+)$|^--path=(.+)$/)
 
109
    {
 
110
        $thisProg = "$1/".basename($thisProg) if($1);
 
111
        $thisProg = "$2/".basename($thisProg) if($2);
 
112
        warn ("$thisProg doesn't exist\n")      if (!(-f $thisProg));
 
113
        $pathoption=1;
 
114
    }
 
115
    elsif (/^--help$|^-h$/)
 
116
    {
 
117
        print STDOUT "Usage $thisProg [OPTION] ... [dir/Makefile.in]...\n",
 
118
                "\n",
 
119
                "Patches dir/Makefile.in generated from automake\n",
 
120
                "(where dir can be a full or relative directory name)",
 
121
                "\n",
 
122
                "  -v, --verbose      verbosely list files processed\n",
 
123
                "  -h, --help         print this help, then exit\n",
 
124
                "  --version          print version number, then exit\n",
 
125
                "  -p, --path=        use the path to am_edit if the path\n",
 
126
                "  --no-final         don't patch for --enable-final\n",
 
127
                "                     called from is not the one to be used\n";
 
128
        
 
129
        exit 0;
 
130
    }
 
131
    elsif (/^--no-final$/)
 
132
    {
 
133
        $use_final = 0;
 
134
        $thisProg .= " --no-final";
 
135
    }
 
136
    elsif (/^-n$/)
 
137
    {
 
138
        $dryrun = 1;
 
139
    }
 
140
    else
 
141
    {
 
142
        # user selects what input files to check
 
143
        # add full path if relative path is given
 
144
        $_ = cwd()."/".$_   if (! /^\//);
 
145
        print "User wants $_\n" if ($verbose);
 
146
        push (@makefiles, $_);
 
147
    }
 
148
}
 
149
 
 
150
if ($thisProg =~ /^\// && !$pathoption )
 
151
{
 
152
  print STDERR "Illegal full pathname call performed...\n",
 
153
      "The call to \"$thisProg\"\nwould be inserted in some Makefile.in.\n",
 
154
      "Please use option --path.\n";
 
155
  exit 1;
 
156
}
 
157
 
 
158
# Only scan for files when the user hasn't entered data
 
159
if (!@makefiles)
 
160
{
 
161
    print STDOUT "Scanning for Makefile.in\n"       if ($verbose);
 
162
    find (\&add_makefile, cwd());
 
163
    #chdir('$topdir');
 
164
} else {
 
165
    print STDOUT "Using user enter input files\n"   if ($verbose);
 
166
}
 
167
 
 
168
foreach $makefile (sort(@makefiles))
 
169
{
 
170
    processMakefile ($makefile);
 
171
    last            if ($errorflag);
 
172
}
 
173
 
 
174
# Just some debug statistics - comment out for release as it uses printf.
 
175
printf STDOUT "Time %.2f CPU sec\n", (times)[0] - $start     if ($verbose);
 
176
 
 
177
exit $errorflag;        # causes make to fail if erroflag is set
 
178
 
 
179
#-----------------------------------------------------------------------------
 
180
 
 
181
# In conjunction with the "find" call, this builds the list of input files
 
182
sub add_makefile ()
 
183
{
 
184
  push (@makefiles, $File::Find::name) if (/Makefile.in$/);
 
185
}
 
186
 
 
187
#-----------------------------------------------------------------------------
 
188
 
 
189
# Processes a single make file
 
190
# The parameter contains the full path name of the Makefile.in to use
 
191
sub processMakefile ($)
 
192
{
 
193
    # some useful globals for the subroutines called here
 
194
    local ($makefile)       = @_;
 
195
    local @headerdirs       = ('.');
 
196
    local $haveAutomocTag   = 0;
 
197
    local $MakefileData     = "";
 
198
 
 
199
    local $cxxsuffix  = "KKK";
 
200
 
 
201
    local @programs = ();  # lists the names of programs and libraries
 
202
    local $program = "";
 
203
 
 
204
    local %realObjs = ();  # lists the objects compiled into $program
 
205
    local %sources = ();   # lists the sources used for $program
 
206
    local %finalObjs = (); # lists the objects compiled when final
 
207
    local %realname = ();  # the binary name of program variable
 
208
    local %idlfiles = ();  # lists the idl files used for $program
 
209
    local %globalmocs = ();# list of all mocfiles (in %mocFiles format)
 
210
    local %important = (); # list of files to be generated asap
 
211
    local %uiFiles = ();
 
212
 
 
213
    local $allidls = "";
 
214
    local $idl_output = "";# lists all idl generated files for cleantarget
 
215
    local $ui_output = "";# lists all uic generated files for cleantarget
 
216
 
 
217
    local %depedmocs = ();
 
218
    
 
219
    local $metasourceTags = 0;
 
220
    local $dep_files      = "";
 
221
    local $dep_finals     = "";
 
222
    local %target_adds    = (); # the targets to add
 
223
    local $kdelang        = "";
 
224
    local @cleanfiles     = ();
 
225
    local $cleanMoc       = "";
 
226
    local $closure_output = "";
 
227
 
 
228
    $makefileDir = dirname($makefile);
 
229
    chdir ($makefileDir);
 
230
    $printname = $makefile;
 
231
    $printname =~ s/^\Q$topdir\E\///;
 
232
    $makefile = basename($makefile);
 
233
 
 
234
    print STDOUT "Processing makefile $printname\n"   if ($verbose);
 
235
    
 
236
    # Setup and see if we need to do this.
 
237
    return      if (!initialise());
 
238
    
 
239
    tag_AUTOMAKE ();            # Allows a "make" to redo the Makefile.in
 
240
    tag_META_INCLUDES ();       # Supplies directories for src locations
 
241
    
 
242
    foreach $program (@programs) {
 
243
        $sources_changed{$program} = 0;
 
244
        $depedmocs{$program} = "";
 
245
        $important{$program} = "";
 
246
        tag_IDLFILES();             # Sorts out idl rules
 
247
        tag_CLOSURE();
 
248
        tag_UIFILES();             # Sorts out ui rules
 
249
        tag_METASOURCES ();         # Sorts out the moc rules
 
250
        if ($sources_changed{$program}) {
 
251
            my $lookup = "$program" . '_SOURCES\s*=\s*(.*)';
 
252
            substituteLine($lookup, "$program\_SOURCES=" . $sources{$program});
 
253
        }
 
254
        if ($important{$program}) {
 
255
            local %source_dict = ();
 
256
            for $source (split(/[\034\s]+/, $sources{$program})) {
 
257
                $source_dict{$source} = 1;
 
258
            }
 
259
            for $source (@cleanfiles) {
 
260
                $source_dict{$source} = 0;
 
261
            }
 
262
            for $source (keys %source_dict) {
 
263
                next if (!$source);
 
264
                if ($source_dict{$source}) {
 
265
                    # sanity check
 
266
                    if (! -f $source) {
 
267
                        print STDERR "Error: $source is listed in a _SOURCE line in $printname, but doesn't exist yet. Put it in DISTCLEANFILES!\n";
 
268
                    } else {
 
269
                        $target_adds{"\$(srcdir)/$source"} .= $important{$program};
 
270
                    }
 
271
                }
 
272
            }
 
273
        }
 
274
    }
 
275
    if ($cleanMoc) {
 
276
        # Always add dist clean tag
 
277
        # Add extra *.moc.cpp files created for USE_AUTOMOC because they
 
278
        # aren't included in the normal *.moc clean rules.
 
279
        appendLines ("$cleantarget-metasources:\n\t-rm -f $cleanMoc\n");
 
280
        $target_adds{"$cleantarget-am"} .= "$cleantarget-metasources ";
 
281
    }
 
282
    tag_DIST();
 
283
 
 
284
    if ($idl_output) {
 
285
        appendLines ("$cleantarget-idl:\n\t-rm -f $idl_output\n");
 
286
        $target_adds{"$cleantarget-am"} .= "$cleantarget-idl ";
 
287
    }
 
288
 
 
289
    if ($ui_output) {
 
290
        appendLines ("$cleantarget-ui:\n\t-rm -f $ui_output\n");
 
291
        $target_adds{"$cleantarget-am"} .= "$cleantarget-ui ";
 
292
    }
 
293
 
 
294
    if ($closure_output) {
 
295
        appendLines ("$cleantarget-closures:\n\t-rm -f $closure_output\n");
 
296
        $target_adds{"$cleantarget-am"} .= "$cleantarget-closures ";
 
297
    }
 
298
 
 
299
    if ($MakefileData =~ /\nKDE_LANG\s*=\s*(\S*)\s*\n/) {
 
300
        $kdelang = '$(KDE_LANG)'
 
301
    } else {
 
302
        $kdelang = '';
 
303
    }
 
304
 
 
305
    tag_POFILES ();             # language rules for po directory
 
306
    tag_DOCFILES ();            # language rules for doc directories
 
307
    tag_LOCALINSTALL();         # add $(DESTDIR) before all kde_ dirs
 
308
    tag_ICON();
 
309
    tag_SUBDIRS();
 
310
 
 
311
    my $tmp = "force-reedit:\n";
 
312
    $tmp   .= "\t$automkCall\n\tcd \$(top_srcdir) && perl $thisProg $printname\n\n";
 
313
    appendLines($tmp);
 
314
    
 
315
    make_meta_classes();
 
316
    tag_FINAL() if (!$kdeopts{"nofinal"});
 
317
 
 
318
    my $final_lines = "final:\n\t\$(MAKE) ";
 
319
    my $final_install_lines = "final-install:\n\t\$(MAKE) ";
 
320
    my $nofinal_lines = "no-final:\n\t\$(MAKE) ";
 
321
    my $nofinal_install_lines = "no-final-install:\n\t\$(MAKE) ";
 
322
 
 
323
    foreach $program (@programs) {
 
324
        
 
325
        my $lookup = "$program\_OBJECTS.*=[^\n]*";
 
326
        
 
327
        my $new = "";
 
328
        
 
329
        my @list = split(/[\034\s]+/, $realObjs{$program});
 
330
        
 
331
        if (!$kdeopts{"nofinal"} && @list > 1 && $finalObjs{$program}) {
 
332
            
 
333
            $new .= "$program\_final\_OBJECTS = " . $finalObjs{$program};
 
334
            $new .= "\n$program\_nofinal\_OBJECTS = " . $realObjs{$program};
 
335
            $new .= "\n\@KDE_USE_FINAL_FALSE\@$program\_OBJECTS = \$($program\_nofinal\_OBJECTS)";
 
336
            $new .= "\n\@KDE_USE_FINAL_TRUE\@$program\_OBJECTS = \$($program\_final\_OBJECTS)";
 
337
            
 
338
            $final_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" ";
 
339
            $final_install_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" ";
 
340
            $nofinal_lines .= "$program\_OBJECTS=\"\$($program\_nofinal\_OBJECTS)\" ";
 
341
            $nofinal_install_lines .= "$program\_OBJECTS=\"\$($program\_nofinal_OBJECTS)\" ";
 
342
        } else {
 
343
            $new = "$program\_OBJECTS = " . $realObjs{$program};
 
344
        }
 
345
        substituteLine ($lookup, $new);
 
346
    }
 
347
    appendLines($final_lines . "all-am");
 
348
    appendLines($final_install_lines . "install-am");
 
349
    appendLines($nofinal_lines . "all-am");
 
350
    appendLines($nofinal_install_lines . "install-am");
 
351
    
 
352
    my $lookup = 'DEP_FILES\s*=([^\n]*)';
 
353
    if ($MakefileData =~ /\n$lookup\n/o) {
 
354
        $depfiles = $1;
 
355
        
 
356
        if ($dep_finals) {
 
357
            $lines  = "\@KDE_USE_FINAL_TRUE\@DEP_FILES = $dep_files $dep_finals \034\t$depfiles\n";
 
358
            $lines .= "\@KDE_USE_FINAL_FALSE\@DEP_FILES = $dep_files $depfiles\n";
 
359
        } else {
 
360
            $lines = "DEP_FILES = $dep_files $depfiles\n";
 
361
        }
 
362
        
 
363
        substituteLine($lookup, $lines);
 
364
    }
 
365
    
 
366
    my $cvs_lines = "cvs-clean:\n";
 
367
    $cvs_lines .= "\t\$(MAKE) -f \$(top_srcdir)/admin/Makefile.common cvs-clean\n";
 
368
    appendLines($cvs_lines);
 
369
    
 
370
    $cvs_lines  = "kde-rpo-clean:\n";
 
371
    $cvs_lines .= "\t-rm -f *.rpo\n";
 
372
    appendLines($cvs_lines);
 
373
    $target_adds{"clean"} .= "kde-rpo-clean ";
 
374
 
 
375
    # some strange people like to do a install-exec, and expect that also
 
376
    # all modules are installed.  automake doesn't know this, so we need to move
 
377
    # this here from install-data to install-exec.
 
378
    if ($MakefileData =~ m/\nkde_module_LTLIBRARIES\s*=/) {
 
379
      $target_adds{"install-exec-am"} .= "install-kde_moduleLTLIBRARIES";
 
380
      my $lookup = 'install-data-am:\s*(.*)';
 
381
      if ($MakefileData =~ /\n$lookup\n/) {
 
382
        my $newdeps = $1;
 
383
        $newdeps =~ s/\s*install-kde_moduleLTLIBRARIES\s*/ /g;
 
384
        substituteLine($lookup, "install-data-am: " . $newdeps);
 
385
      }
 
386
    }
 
387
    
 
388
    my $lines = "";
 
389
 
 
390
    foreach $add (keys %target_adds) {
 
391
        my $lookup = quotemeta($add) . ':([^\n]*)';
 
392
        if ($MakefileData =~ /\n$lookup\n/) {
 
393
            substituteLine($lookup, "$add: " . $target_adds{$add} . $1);
 
394
        } else {
 
395
            $lines .= "$add: " . $target_adds{$add} . "\n";
 
396
        }
 
397
    }
 
398
    if ($lines) {
 
399
        appendLines($lines);
 
400
    }
 
401
 
 
402
    my $found = 1;
 
403
    
 
404
    while ($found) {
 
405
        if ($MakefileData =~ m/\n(.*)\$\(CXXFLAGS\)(.*)\n/) {
 
406
            my $vor = $1;   # "vor" means before in German
 
407
            my $nach = $2; # "nach" means after in German
 
408
            my $lookup = quotemeta("$1\$(CXXFLAGS)$2");
 
409
            my $replacement = "$1\$(KCXXFLAGS)$2";
 
410
            $MakefileData =~ s/$lookup/$replacement/;
 
411
            $lookup =~ s/\\\$\\\(CXXFLAGS\\\)/\\\$\\\(KCXXFLAGS\\\)/;
 
412
            $replacement = "$vor\$(KCXXFLAGS) \$(KDE_CXXFLAGS)$nach";
 
413
            substituteLine($lookup, $replacement);
 
414
        } else {
 
415
            $found = 0;
 
416
        }
 
417
    }
 
418
 
 
419
    $lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=link) (\$\(CXXLD\).*\$\(KCXXFLAGS\))';
 
420
    
 
421
    if ($MakefileData =~ m/$lookup/ ) {
 
422
        $MakefileData =~ s/$lookup/$1 --tag=CXX $2/;
 
423
    }
 
424
 
 
425
    $lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=compile) (\$\(CXX\).*\$\(KCXXFLAGS\))';
 
426
    if ($MakefileData =~ m/$lookup/ ) {
 
427
        $MakefileData =~ s/$lookup/$1 --tag=CXX $2/;
 
428
    }
 
429
 
 
430
    $MakefileData =~ s/\$\(KCXXFLAGS\)/\$\(CXXFLAGS\)/g;
 
431
 
 
432
    $lookup = '(.*)cp -pr \$\$/\$\$file \$\(distdir\)/\$\$file(.*)';
 
433
    if ($MakefileData =~ m/\n$lookup\n/) {
 
434
        substituteLine($lookup, "$1cp -pr \$\$d/\$\$file \$(distdir)/\$\$file$2");
 
435
    }
 
436
 
 
437
    # Always update the Makefile.in
 
438
    updateMakefile ();
 
439
    return;
 
440
}
 
441
 
 
442
#-----------------------------------------------------------------------------
 
443
 
 
444
# Check to see whether we should process this make file.
 
445
# This is where we look for tags that we need to process.
 
446
# A small amount of initialising on the tags is also done here.
 
447
# And of course we open and/or create the needed make files.
 
448
sub initialise ()
 
449
{
 
450
    if (! -r "Makefile.am") {
 
451
        print STDOUT "found Makefile.in without Makefile.am\n" if ($verbose);
 
452
        return 0;
 
453
    }
 
454
 
 
455
    # Checking for files to process...
 
456
    open (FILEIN, $makefile)
 
457
      || die "Could not open $makefileDir/$makefile: $!\n";
 
458
    # Read the file
 
459
    # stat(FILEIN)[7] might look more elegant, but is slower as it 
 
460
    # requires stat'ing the file
 
461
    seek(FILEIN, 0, 2);
 
462
    my $fsize = tell(FILEIN);
 
463
    seek(FILEIN, 0, 0);
 
464
    read FILEIN, $MakefileData, $fsize;
 
465
    close FILEIN;
 
466
    print "DOS CRLF within $makefileDir/$makefile!\n" if($MakefileData =~ y/\r//d);
 
467
 
 
468
    # Remove the line continuations, but keep them marked
 
469
    # Note: we lose the trailing spaces but that's ok.
 
470
    $MakefileData =~ s/\\\s*\n\s*/\034/g;
 
471
 
 
472
    # If we've processed the file before...
 
473
    restoreMakefile ()      if ($MakefileData =~ /$progId/);
 
474
 
 
475
    foreach $dir (@foreignfiles) {
 
476
      if (substr($makefileDir,0,length($dir)) eq $dir) {
 
477
        return 0;
 
478
      }
 
479
    }
 
480
 
 
481
    %kdeopts = ();
 
482
    $kdeopts{"foreign"} = 0;
 
483
    $kdeopts{"qtonly"} = 0;
 
484
    $kdeopts{"nofinal"} = !$use_final; # default
 
485
 
 
486
    if ($MakefileData =~ /\nKDE_OPTIONS\s*=\s*([^\n]*)\n/) {
 
487
        local @kde_options = split(/[\s\034]/, $1);
 
488
        if (grep(/^foreign$/, @kde_options)) {
 
489
            push(@foreignfiles, $makefileDir . "/");
 
490
            return 0; # don't touch me
 
491
        }
 
492
        for $opt (@kde_options) {
 
493
            if (!defined $kdeopts{$opt}) {
 
494
                print STDERR "Warning: unknown option $opt in $printname\n";
 
495
            } else {
 
496
                $kdeopts{$opt} = 1;
 
497
            }
 
498
        }
 
499
    }
 
500
 
 
501
    # Look for the tags that mean we should process this file.
 
502
    $metasourceTags = 0;
 
503
    $metasourceTags++    while ($MakefileData =~ /\n[^=\#]*METASOURCES\s*=/g);
 
504
 
 
505
    my $pofileTag = 0;
 
506
    $pofileTag++    while ($MakefileData =~ /\nPOFILES\s*=/g);
 
507
    if ($pofileTag > 1)
 
508
      {
 
509
          print STDERR "Error: Only one POFILES tag allowed\n";
 
510
          $errorflag = 1;
 
511
      }
 
512
 
 
513
    while ($MakefileData =~ /\n\.SUFFIXES:([^\n]+)\n/g) {
 
514
        my @list=split(' ', $1);
 
515
        foreach $ext (@list) {
 
516
            if ($ext =~ /^\.$cppExt$/) {
 
517
                $cxxsuffix = $ext;
 
518
                $cxxsuffix =~ s/\.//g;
 
519
                print STDOUT "will use suffix $cxxsuffix\n" if ($verbose);
 
520
                last;
 
521
            }
 
522
        }
 
523
    }
 
524
                                                     
 
525
    while ($MakefileData =~ /\n(\S*)_OBJECTS\s*=[ \t\034]*([^\n]*)\n/g) {
 
526
        
 
527
        my $program = $1;
 
528
        my $objs = $2; # safe them
 
529
        
 
530
        my $ocv = 0;
 
531
        
 
532
        my @objlist = split(/[\s\034]+/, $objs);
 
533
        foreach $obj (@objlist) {
 
534
            if ($obj =~ /\$\((\S+)\)/ ) {
 
535
                my $variable = $1;
 
536
                if ($variable !~ 'OBJEXT') {
 
537
                    $ocv = 1;
 
538
                }
 
539
            }
 
540
        }
 
541
        
 
542
        next if ($ocv);
 
543
 
 
544
        $program =~ s/^am_// if ($program =~ /^am_/);
 
545
        
 
546
        my $sourceprogram = $program;
 
547
        $sourceprogram =~ s/\@am_/\@/ if($sourceprogram =~ /^.*\@am_.+/);
 
548
        
 
549
        print STDOUT "found program $program\n" if ($verbose);
 
550
        push(@programs, $program);
 
551
        
 
552
        $realObjs{$program} = $objs;
 
553
        
 
554
        if ($MakefileData =~ /\n$sourceprogram\_SOURCES\s*=\s*(.*)\n/) {
 
555
            $sources{$program} = $1;
 
556
        } 
 
557
        else {
 
558
            $sources{$program} = "";
 
559
            print STDERR "found program with no _SOURCES: $program\n";
 
560
        }
 
561
        
 
562
        my $realprogram = $program;
 
563
        $realprogram =~ s/_/./g; # unmask to regexp
 
564
        if ($MakefileData =~ /\n($realprogram)(\$\(EXEEXT\)?)?:.*\$\($program\_OBJECTS\)/) {
 
565
            $realname{$program} = $1;
 
566
        } else {
 
567
            # not standard Makefile - nothing to worry about
 
568
            $realname{$program} = "";
 
569
        }
 
570
    }
 
571
    
 
572
    my $lookup = '\nDEPDIR\s*=.*';
 
573
    if ($MakefileData !~ /($lookup)\n/o) {
 
574
        $lookup = '\nbindir\s*=.*';
 
575
        if ($MakefileData =~ /($lookup)\n/) {
 
576
            substituteLine ($lookup, "DEPDIR = .deps\n$1");
 
577
        }
 
578
    } 
 
579
 
 
580
    my @marks = ('MAINTAINERCLEANFILES', 'CLEANFILES', 'DISTCLEANFILES');
 
581
    foreach $mark (@marks) {
 
582
        while ($MakefileData =~ /\n($mark)\s*=\s*([^\n]*)/g) {
 
583
            foreach $file (split('[\034\s]', $2)) {
 
584
                $file =~ s/\.\///;
 
585
                push(@cleanfiles, $file);
 
586
            }
 
587
        }
 
588
    }
 
589
 
 
590
    my $localTag = 0;
 
591
    $localTag++ if ($MakefileData =~ /\ninstall-\S+-local:/);
 
592
    
 
593
    return (!$errorflag);
 
594
}
 
595
 
 
596
#-----------------------------------------------------------------------------
 
597
 
 
598
# Gets the list of user defined directories - relative to $srcdir - where
 
599
# header files could be located.
 
600
sub tag_META_INCLUDES ()
 
601
{
 
602
    my $lookup = '[^=\n]*META_INCLUDES\s*=\s*(.*)';
 
603
    return 1    if ($MakefileData !~ /($lookup)\n/o);
 
604
    print STDOUT "META_INCLUDE processing <$1>\n"       if ($verbose);
 
605
 
 
606
    my $headerStr = $2;
 
607
    removeLine ($lookup, $1);
 
608
 
 
609
    $headerStr =~ tr/\034/ /;
 
610
    my @headerlist = split(' ', $headerStr);
 
611
 
 
612
    foreach $dir (@headerlist)
 
613
    {
 
614
        $dir =~ s#\$\(srcdir\)#.#;
 
615
        if (! -d $dir)
 
616
        {
 
617
            print STDERR "Warning: $dir can't be found. ",
 
618
                            "Must be a relative path to \$(srcdir)\n";
 
619
        }
 
620
        else
 
621
        {
 
622
            push (@headerdirs, $dir);
 
623
        }
 
624
    }
 
625
 
 
626
    return 0;
 
627
}
 
628
 
 
629
#-----------------------------------------------------------------------------
 
630
 
 
631
sub tag_FINAL()
 
632
{
 
633
    my @final_names = ();
 
634
    
 
635
    foreach $program (@programs) {
 
636
        
 
637
        if ($sources{$program} =~ /\(/) {
 
638
            print STDOUT "found ( in $program\_SOURCES. skipping\n" if ($verbose);
 
639
            next;
 
640
        }
 
641
        
 
642
        my $mocsources = "";
 
643
        
 
644
        my @progsources = split(/[\s\034]+/, $sources{$program});
 
645
        my %sourcelist = ();
 
646
        
 
647
        foreach $source (@progsources) {
 
648
            my $suffix = $source;
 
649
            $suffix =~ s/^.*\.([^\.]+)$/$1/;
 
650
            
 
651
            if (defined($sourcelist{$suffix})) {
 
652
                $sourcelist{$suffix} .= " " . $source;
 
653
            } else {
 
654
                $sourcelist{$suffix} .= $source;
 
655
            }
 
656
        }
 
657
        
 
658
        foreach $suffix (keys %sourcelist) {
 
659
            
 
660
            # See if this file contains c++ code. (ie Just check the files suffix against
 
661
            my $suffix_is_cxx = 0;
 
662
            if($suffix =~ /($cppExt)$/) {
 
663
              $cxxsuffix = $1;
 
664
              $suffix_is_cxx = 1;
 
665
            }
 
666
            
 
667
            my $mocfiles_in = ($suffix eq $cxxsuffix) &&
 
668
              defined($depedmocs{$program});
 
669
            
 
670
            my @sourcelist = split(/[\s\034]+/, $sourcelist{$suffix});
 
671
            
 
672
            if ((@sourcelist == 1 && !$mocfiles_in) || $suffix_is_cxx != 1 ) {
 
673
                
 
674
                # we support IDL on our own
 
675
                if ($suffix =~ /^skel$/ || $suffix =~ /^stub/ || $suffix =~ /^h$/
 
676
                    || $suffix =~ /^ui$/ ) {
 
677
                    next;
 
678
                }
 
679
                
 
680
                foreach $file (@sourcelist) {
 
681
                    
 
682
                    $file =~ s/\Q$suffix\E$//;
 
683
                    
 
684
                    $finalObjs{$program} .= $file;
 
685
                    if ($program =~ /_la$/) {
 
686
                        $finalObjs{$program} .= "lo ";
 
687
                    } else {
 
688
                        $finalObjs{$program} .= "o ";
 
689
                    }
 
690
                }
 
691
                next; # suffix
 
692
            }
 
693
            
 
694
            my $source_deps = "";
 
695
            foreach $source (@sourcelist) {
 
696
                if (-f $source) {
 
697
                    $source_deps .= "\$(srcdir)/$source ";
 
698
                } else {
 
699
                    $source_deps .= "$source ";
 
700
                }
 
701
            }
 
702
            
 
703
            $handling = "$program.all_$suffix.$suffix: \$(srcdir)/Makefile.in " . $source_deps . " ";
 
704
            
 
705
            if ($mocfiles_in) {
 
706
                $handling .= $depedmocs{$program};
 
707
                foreach $mocfile (split(' ', $depedmocs{$program})) {
 
708
                   
 
709
                    if ($mocfile =~ m/\.$suffix$/) {
 
710
                        $mocsources .= " " . $mocfile;
 
711
                    }
 
712
                }
 
713
            }
 
714
            
 
715
            $handling .= "\n";
 
716
            $handling .= "\t\@echo 'creating $program.all_$suffix.$suffix ...'; \\\n";
 
717
            $handling .= "\trm -f $program.all_$suffix.files $program.all_$suffix.final; \\\n";
 
718
            $handling .= "\techo \"#define KDE_USE_FINAL 1\" >> $program.all_$suffix.final; \\\n";
 
719
            $handling .= "\tfor file in " . $sourcelist{$suffix} . " $mocsources; do \\\n";
 
720
            $handling .= "\t  echo \"#include \\\"\$\$file\\\"\" >> $program.all_$suffix.files; \\\n";
 
721
            $handling .= "\t  test ! -f \$\(srcdir\)/\$\$file || egrep '^#pragma +implementation' \$\(srcdir\)/\$\$file >> $program.all_$suffix.final; \\\n";
 
722
            $handling .= "\tdone; \\\n";
 
723
            $handling .= "\tcat $program.all_$suffix.final $program.all_$suffix.files  > $program.all_$suffix.$suffix; \\\n";
 
724
            $handling .= "\trm -f $program.all_$suffix.final $program.all_$suffix.files\n";
 
725
            
 
726
            appendLines($handling);
 
727
            
 
728
            push(@final_names, "$program.all_$suffix.$suffix");
 
729
            $finalObjs{$program} .= "$program.all_$suffix.";
 
730
            if ($program =~ /_la$/) {
 
731
                $finalObjs{$program} .= "lo ";
 
732
            } else {
 
733
                $finalObjs{$program} .= "o ";
 
734
            }
 
735
        }
 
736
    }
 
737
    
 
738
    if (!$kdeopts{"nofinal"} && @final_names >= 1) {
 
739
        # add clean-final target
 
740
        my $lines = "$cleantarget-final:\n";
 
741
        $lines .= "\t-rm -f " . join(' ', @final_names) . "\n" if (@final_names);
 
742
        appendLines($lines);
 
743
        $target_adds{"$cleantarget-am"} .= "$cleantarget-final ";
 
744
        
 
745
        foreach $finalfile (@final_names) {
 
746
            $finalfile =~ s/\.[^.]*$/.P/;
 
747
            $dep_finals .= " \$(DEPDIR)/$finalfile";
 
748
        }
 
749
    }
 
750
}
 
751
 
 
752
# Organises the list of headers that we'll use to produce moc files
 
753
# from.
 
754
sub tag_METASOURCES ()
 
755
{
 
756
    local @newObs           = ();  # here we add to create object files
 
757
    local @deped            = ();  # here we add to create moc files
 
758
    local $mocExt           = ".moc";
 
759
    local %mocFiles         = ();
 
760
 
 
761
    my $line = "";
 
762
    my $postEqual = "";
 
763
 
 
764
    my $lookup;
 
765
    my $found = "";
 
766
 
 
767
    if ($metasourceTags > 1) {
 
768
        $lookup = $program . '_METASOURCES\s*=\s*(.*)';
 
769
        return 1    if ($MakefileData !~ /\n($lookup)\n/);
 
770
        $found = $1;
 
771
    } else {
 
772
        $lookup = $program . '_METASOURCES\s*=\s*(.*)';
 
773
        if ($MakefileData !~ /\n($lookup)\n/) {
 
774
            $lookup = 'METASOURCES\s*=\s*(.*)';
 
775
            return 1    if ($MakefileData !~ /\n($lookup)\n/o);
 
776
            $found = $1;
 
777
            $metasourceTags = 0; # we can use the general target only once
 
778
        } else {
 
779
            $found = $1;
 
780
        }
 
781
    }
 
782
    print STDOUT "METASOURCE processing <$found>)\n"      if ($verbose);
 
783
    
 
784
    $postEqual = $found;
 
785
    $postEqual =~ s/[^=]*=//;
 
786
    
 
787
    removeLine ($lookup, $found);
 
788
    
 
789
    # Always find the header files that could be used to "moc"
 
790
    return 1    if (findMocCandidates ());
 
791
    
 
792
    if ($postEqual =~ /AUTO\s*(\S*)|USE_AUTOMOC\s*(\S*)/)
 
793
    {
 
794
        print STDERR "$printname: the argument for AUTO|USE_AUTOMOC is obsolete" if ($+);
 
795
        $mocExt = ".moc.$cxxsuffix";
 
796
        $haveAutomocTag = 1;
 
797
    }
 
798
    else
 
799
    {
 
800
        # Not automoc so read the list of files supplied which
 
801
        # should be .moc files.
 
802
 
 
803
        $postEqual =~ tr/\034/ /;
 
804
 
 
805
        # prune out extra headers - This also checks to make sure that
 
806
        # the list is valid.
 
807
        pruneMocCandidates ($postEqual);
 
808
    }
 
809
 
 
810
    checkMocCandidates ();
 
811
    
 
812
    if (@newObs) {
 
813
        my $ext =  ($program =~ /_la$/) ? ".moc.lo " : ".moc.o ";
 
814
        $realObjs{$program} .= "\034" . join ($ext, @newObs) . $ext;
 
815
        $depedmocs{$program} = join (".moc.$cxxsuffix " , @newObs) . ".moc.$cxxsuffix";
 
816
        foreach $file (@newObs) {
 
817
            $dep_files .= " \$(DEPDIR)/$file.moc.P" if($dep_files !~/$file.moc.P/);
 
818
        }
 
819
    }
 
820
    if (@deped) {
 
821
        $depedmocs{$program} .= " ";
 
822
        $depedmocs{$program} .= join('.moc ', @deped) . ".moc";
 
823
        $depedmocs{$program} .= " ";
 
824
    }
 
825
    addMocRules ();
 
826
    @globalmocs{keys %mocFiles}=values %mocFiles;
 
827
}
 
828
 
 
829
#-----------------------------------------------------------------------------
 
830
 
 
831
# Returns 0 if the line was processed - 1 otherwise.
 
832
# Errors are logged in the global $errorflags
 
833
sub tag_AUTOMAKE ()
 
834
{
 
835
    my $lookup = '.*cd \$\(top_srcdir\)\s+&&[\s\034]+\$\(AUTOMAKE\)(.*)';
 
836
    return 1    if ($MakefileData !~ /\n($lookup)\n/);
 
837
    print STDOUT "AUTOMAKE processing <$1>\n"        if ($verbose);
 
838
 
 
839
    my $newLine = $1."\n\tcd \$(top_srcdir) && perl $thisProg $printname";
 
840
    substituteLine ($lookup, $newLine);
 
841
    $automkCall = $1;
 
842
    return 0;
 
843
}
 
844
 
 
845
#-----------------------------------------------------------------------------
 
846
 
 
847
sub handle_TOPLEVEL()
 
848
{
 
849
    my $pofiles = "";
 
850
    my @restfiles = ();
 
851
    opendir (THISDIR, ".");
 
852
    foreach $entry (readdir(THISDIR)) {
 
853
        next if (-d $entry);
 
854
        
 
855
        next if ($entry eq "CVS" || $entry =~ /^\./  || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/ || $entry =~ /.gmo$/);
 
856
                 
 
857
        if ($entry =~ /\.po$/) {
 
858
             next;
 
859
        }
 
860
        push(@restfiles, $entry);
 
861
    }
 
862
    closedir (THISDIR);
 
863
            
 
864
    if (@restfiles) {
 
865
        $target_adds{"install-data-am"} .= "install-nls-files ";
 
866
        $lines = "install-nls-files:\n";
 
867
        $lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$kdelang\n";
 
868
        for $file (@restfiles) {
 
869
            $lines .= "\t\$(INSTALL_DATA) \$\(srcdir\)/$file \$(DESTDIR)\$(kde_locale)/$kdelang/$file\n";
 
870
        }
 
871
        $target_adds{"uninstall"} .= "uninstall-nls-files ";
 
872
        $lines .= "uninstall-nls-files:\n";
 
873
        for $file (@restfiles) {
 
874
            $lines .= "\t-rm -f \$(DESTDIR)\$(kde_locale)/$kdelang/$file\n";
 
875
        }
 
876
        appendLines($lines);
 
877
    }
 
878
    
 
879
    return 0;
 
880
}
 
881
 
 
882
#-----------------------------------------------------------------------------
 
883
 
 
884
sub tag_SUBDIRS ()
 
885
{
 
886
  if ($MakefileData !~ /\nSUBDIRS\s*=\s*\$\(AUTODIRS\)\s*\n/) {
 
887
    return 1;
 
888
  }
 
889
 
 
890
  my $subdirs = ".";
 
891
 
 
892
  opendir (THISDIR, ".");
 
893
  foreach $entry (readdir(THISDIR)) {
 
894
    next if ($entry eq "CVS" || $entry =~ /^\./);
 
895
    if (-d $entry && -f $entry . "/Makefile.am") {
 
896
      $subdirs .= " $entry";
 
897
      next;
 
898
    }
 
899
  }
 
900
  closedir (THISDIR);
 
901
 
 
902
  my $lines = "SUBDIRS =$subdirs\n";
 
903
  substituteLine('SUBDIRS\s*=.*', $lines);
 
904
  return 0;
 
905
}
 
906
 
 
907
sub tag_IDLFILES ()
 
908
{
 
909
    my @psources = split(/[\034\s]+/, $sources{$program});
 
910
    my $dep_lines = "";
 
911
    my @cppFiles = ();
 
912
    
 
913
    foreach $source (@psources) {
 
914
        
 
915
        my $skel = ($source =~ m/\.skel$/);
 
916
        
 
917
        if ($source =~ m/\.stub$/ || $skel) {
 
918
            
 
919
            my $qs = quotemeta($source);
 
920
            $sources{$program} =~ s/$qs//;
 
921
            $sources_changed{$program} = 1;
 
922
            
 
923
            print STDOUT "adding IDL file $source\n" if ($verbose);
 
924
            
 
925
            $source =~ s/\.(stub|skel)$//;
 
926
            
 
927
            my $sourcename;
 
928
            
 
929
            if ($skel) {
 
930
                $sourcename = "$source\_skel";
 
931
            } else {
 
932
                $sourcename = "$source\_stub";
 
933
            }
 
934
            
 
935
            my $sourcedir = '';
 
936
            if (-f "$makefileDir/$source.h") {
 
937
                $sourcedir = '$(srcdir)/';
 
938
            } else {
 
939
                if ($MakefileData =~ /\n$source\_DIR\s*=\s*(\S+)\n/) {
 
940
                    $sourcedir = $1;
 
941
                    $sourcedir .= "/" if ($sourcedir !~ /\/$/);
 
942
                }
 
943
            }
 
944
            
 
945
            if ($allidls !~ /$source\_kidl/) {
 
946
                
 
947
                $dep_lines .= "$source.kidl: $sourcedir$source.h \$(DCOPIDL_DEPENDENCIES)\n";
 
948
                $dep_lines .= "\t\$(DCOPIDL) $sourcedir$source.h > $source.kidl || ( rm -f $source.kidl ; /bin/false )\n";
 
949
                
 
950
                $allidls .= $source . "_kidl ";
 
951
            }
 
952
            
 
953
            if ($allidls !~ /$sourcename/) {
 
954
                
 
955
                if ($skel) {
 
956
                    $dep_lines .= "$sourcename.$cxxsuffix: $source.kidl\n";
 
957
                    $dep_lines .= "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-stub $source.kidl\n";
 
958
                } else {
 
959
                    $target_adds{"$sourcename.$cxxsuffix"} .= "$sourcename.h ";
 
960
                    $dep_lines .= "$sourcename.h: $source.kidl\n";
 
961
                    $dep_lines .= "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-skel $source.kidl\n";
 
962
                }
 
963
                
 
964
                $allidls .= $sourcename . " ";
 
965
            }
 
966
            
 
967
            $idlfiles{$program} .= $sourcename . " ";
 
968
            
 
969
            if ($program =~ /_la$/) {
 
970
                $realObjs{$program} .= " $sourcename.lo";
 
971
            } else {
 
972
                $realObjs{$program} .= " $sourcename.\$(OBJEXT)";
 
973
            }
 
974
            $sources{$program} .= " $sourcename.$cxxsuffix";
 
975
            $sources_changed{$program} = 1;
 
976
            $important{$program} .= "$sourcename.h " if (!$skel);
 
977
            $idl_output .= "\\\n\t$sourcename.$cxxsuffix $sourcename.h $source.kidl ";
 
978
            push(@cleanfiles, "$sourcename.$cxxsuffix");
 
979
            push(@cleanfiles, "$sourcename.h");
 
980
            push(@cleanfiles, "$sourcename.kidl");
 
981
            $dep_files .= " \$(DEPDIR)/$sourcename.P" if ($dep_files !~/$sourcename.P/);
 
982
        }
 
983
    }
 
984
    if ($dep_lines) {
 
985
        appendLines($dep_lines);
 
986
    }
 
987
    
 
988
    if (0) {
 
989
        my $lookup = "($program)";
 
990
        $lookup .= '(|\$\(EXEEXT\))';
 
991
        $lookup =~ s/\_/./g;
 
992
        $lookup .= ":(.*..$program\_OBJECTS..*)";
 
993
        #    $lookup = quotemeta($lookup);
 
994
        if ($MakefileData =~ /\n$lookup\n/) {
 
995
            
 
996
            my $line = "$1$2: ";
 
997
            foreach $file (split(' ', $idlfiles{$program})) {
 
998
                $line .= "$file.$cxxsuffix ";
 
999
            }
 
1000
            $line .= $3;
 
1001
            substituteLine($lookup, $line);
 
1002
        } else {
 
1003
            print STDERR "no built dependency found $lookup\n";
 
1004
        }
 
1005
    }
 
1006
}
 
1007
 
 
1008
sub tag_UIFILES ()
 
1009
{
 
1010
    my @psources = split(/[\034\s]+/, $sources{$program});
 
1011
    my $dep_lines = "";
 
1012
    my @depFiles = ();
 
1013
    
 
1014
    foreach $source (@psources) {
 
1015
 
 
1016
        if ($source =~ m/\.ui$/) {
 
1017
 
 
1018
            print STDERR "adding UI file $source\n" if ($verbose);
 
1019
 
 
1020
            my $qs = quotemeta($source);
 
1021
            $sources{$program} =~ s/$qs//;
 
1022
            $sources_changed{$program} = 1;
 
1023
      
 
1024
            $source =~ s/\.ui$//;
 
1025
 
 
1026
            my $sourcedir = '';
 
1027
            if (-f "$makefileDir/$source.ui") {
 
1028
                $sourcedir = '$(srcdir)/';
 
1029
            }
 
1030
 
 
1031
            if (!$uiFiles{$source}) {
 
1032
 
 
1033
                $dep_lines .= "$source.$cxxsuffix: $sourcedir$source.ui $source.h $source.moc\n";
 
1034
                $dep_lines .= "\trm -f $source.$cxxsuffix\n";
 
1035
                if (!$kdeopts{"qtonly"}) {
 
1036
                    $dep_lines .= "\techo '#include <klocale.h>' > $source.$cxxsuffix\n";
 
1037
                    $dep_lines .= "\t\$(UIC) -tr \${UIC_TR} -i $source.h $sourcedir$source.ui | sed -e \"s,\${UIC_TR}( \\\"\\\" ),QString::null,g\" | sed -e \"s,\${UIC_TR}( \\\"\\\"\\, \\\"\\\" ),QString::null,g\" >> $source.$cxxsuffix || rm -f $source.$cxxsuffix\n";
 
1038
                } else {
 
1039
                    $dep_lines .= "\t\$(UIC) -i $source.h $sourcedir$source.ui > $source.$cxxsuffix || rm -f $source.$cxxsuffix\n";
 
1040
                }
 
1041
                $dep_lines .= "\techo '#include \"$source.moc\"' >> $source.$cxxsuffix\n\n";
 
1042
                $dep_lines .= "$source.h: $sourcedir$source.ui\n";
 
1043
                $dep_lines .= "\t\$(UIC) -o $source.h $sourcedir$source.ui\n\n";
 
1044
                $dep_lines .= "$source.moc: $source.h\n";
 
1045
                $dep_lines .= "\t\$(MOC) $source.h -o $source.moc\n";
 
1046
 
 
1047
                $uiFiles{$source} = 1;
 
1048
                $depedmocs{$program} .= " $source.moc";
 
1049
                $globalmocs{$source} = "\035$source.h\035$source.cpp";
 
1050
            }
 
1051
            
 
1052
            if ($program =~ /_la$/) {
 
1053
                $realObjs{$program} .= " $source.lo";
 
1054
            } else {
 
1055
                $realObjs{$program} .= " $source.\$(OBJEXT)";
 
1056
            }
 
1057
            $sources{$program} .= " $source.$cxxsuffix";
 
1058
            $sources_changed{$program} = 1;
 
1059
            $important{$program} .= "$source.h ";
 
1060
            $ui_output .= "\\\n\t$source.$cxxsuffix $source.h $source.moc ";
 
1061
            push(@cleanfiles, "$source.$cxxsuffix");
 
1062
            push(@cleanfiles, "source.h");
 
1063
            push(@cleanfiles, "$source.moc");
 
1064
            $dep_files .= " \$(DEPDIR)/$source.P" if($dep_files !~/$source.P/ );
 
1065
        }
 
1066
    }
 
1067
    if ($dep_lines) {
 
1068
        appendLines($dep_lines);
 
1069
    }
 
1070
}
 
1071
 
 
1072
sub tag_ICON()
 
1073
{
 
1074
    my $lookup = '([^\s]*)_ICON\s*=\s*([^\n]*)';
 
1075
    my $install = "";
 
1076
    my $uninstall = "";
 
1077
 
 
1078
    while ($MakefileData =~ /\n$lookup/og) {
 
1079
        my $destdir;
 
1080
        if ($1 eq "KDE") {
 
1081
            $destdir = "kde_icondir";
 
1082
        } else {
 
1083
            $destdir = $1 . "dir";
 
1084
        }
 
1085
        my $iconauto = ($2 =~ /AUTO\s*$/);
 
1086
        my @appnames = ();
 
1087
        if ( ! $iconauto ) {
 
1088
            my @_appnames = split(" ", $2);
 
1089
            print STDOUT "KDE_ICON processing <@_appnames>\n"   if ($verbose);
 
1090
            foreach $appname (@_appnames) {
 
1091
                push(@appnames, quotemeta($appname));
 
1092
            }
 
1093
        } else {
 
1094
            print STDOUT "KDE_ICON processing <AUTO>\n"   if ($verbose);
 
1095
        }
 
1096
 
 
1097
        my @files = ();
 
1098
        opendir (THISDIR, ".");
 
1099
        foreach $entry (readdir(THISDIR)) {
 
1100
            next if ($entry eq "CVS" || $entry =~ /^\./  || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
 
1101
            next if (! -f $entry);
 
1102
            if ( $iconauto )
 
1103
              {
 
1104
                  push(@files, $entry)
 
1105
                    if ($entry =~ /\.xpm/ || $entry =~ /\.png/);
 
1106
              } else {
 
1107
                  foreach $appname (@appnames) {
 
1108
                      push(@files, $entry)
 
1109
                        if ($entry =~ /-$appname\.xpm/ || $entry =~ /-$appname\.png/);
 
1110
                  }
 
1111
              }
 
1112
        }
 
1113
        closedir (THISDIR);
 
1114
        
 
1115
        my %directories = ();
 
1116
        
 
1117
        foreach $file (@files) {
 
1118
            my $newfile = $file;
 
1119
            my $prefix = $file;
 
1120
            $prefix =~ s/\.(png|xpm)$//;
 
1121
            my $appname = $prefix;
 
1122
            $appname =~ s/^[^-]+-// if ($appname =~ /-/) ;
 
1123
            $appname =~ s/^[^-]+-// if ($appname =~ /-/) ;
 
1124
            $appname = quotemeta($appname);
 
1125
            $prefix =~ s/$appname$//;
 
1126
            $prefix =~ s/-$//;
 
1127
            
 
1128
            $prefix = 'lo16-app' if ($prefix eq 'mini');
 
1129
            $prefix = 'lo32-app' if ($prefix eq 'lo');
 
1130
            $prefix = 'hi48-app' if ($prefix eq 'large');
 
1131
            $prefix .= '-app' if ($prefix =~ m/^...$/);
 
1132
            
 
1133
            my $type = $prefix;
 
1134
            $type =~ s/^.*-([^-]+)$/$1/;
 
1135
            $prefix =~ s/^(.*)-[^-]+$/$1/;
 
1136
            
 
1137
            my %type_hash =
 
1138
              (
 
1139
               'action' => 'actions',
 
1140
               'app' => 'apps',
 
1141
               'device' => 'devices',
 
1142
               'filesys' => 'filesystems',
 
1143
               'mime' => 'mimetypes'
 
1144
              );
 
1145
            
 
1146
            if (! defined $type_hash{$type} ) {
 
1147
                print STDERR "unknown icon type $type in $printname ($file)\n";
 
1148
                next;
 
1149
            }
 
1150
            
 
1151
            my %dir_hash =
 
1152
              (
 
1153
               'los' => 'locolor/16x16',
 
1154
               'lom' => 'locolor/32x32',
 
1155
               'him' => 'hicolor/32x32',
 
1156
               'hil' => 'hicolor/48x48',
 
1157
               'lo16' => 'locolor/16x16',
 
1158
               'lo22' => 'locolor/22x22',
 
1159
               'lo32' => 'locolor/32x32',
 
1160
               'hi16' => 'hicolor/16x16',
 
1161
               'hi22' => 'hicolor/22x22',
 
1162
               'hi32' => 'hicolor/32x32',
 
1163
               'hi48' => 'hicolor/48x48',
 
1164
               'hi64' => 'hicolor/64x64',
 
1165
               'hisc' => 'hicolor/scalable'
 
1166
              );
 
1167
            
 
1168
            $newfile =~ s@.*-($appname\.(png|xpm?))@$1@;
 
1169
            
 
1170
            if (! defined $dir_hash{$prefix}) {
 
1171
                print STDERR "unknown icon prefix $prefix in $printname\n";
 
1172
                next;
 
1173
            }
 
1174
            
 
1175
            my $dir = $dir_hash{$prefix} . "/" . $type_hash{$type};
 
1176
            if ($newfile =~ /-[^\.]/) {
 
1177
                my $tmp = $newfile;
 
1178
                $tmp =~ s/^([^-]+)-.*$/$1/;
 
1179
                $dir = $dir . "/" . $tmp;
 
1180
                $newfile =~ s/^[^-]+-//;
 
1181
            }
 
1182
            
 
1183
            if (!defined $directories{$dir}) {
 
1184
                $install .= "\t\$(mkinstalldirs) \$(DESTDIR)\$($destdir)/$dir\n";
 
1185
                $directories{$dir} = 1;
 
1186
            }
 
1187
            
 
1188
            $install .= "\t\$(INSTALL_DATA) \$(srcdir)/$file \$(DESTDIR)\$($destdir)/$dir/$newfile\n";
 
1189
            $uninstall .= "\t-rm -f \$(DESTDIR)\$($destdir)/$dir/$newfile\n";
 
1190
            
 
1191
        }
 
1192
    }
 
1193
 
 
1194
    if (length($install)) {
 
1195
        $target_adds{"install-data-am"} .= "install-kde-icons ";
 
1196
        $target_adds{"uninstall-am"} .= "uninstall-kde-icons ";
 
1197
        appendLines("install-kde-icons:\n" . $install . "\nuninstall-kde-icons:\n" . $uninstall);
 
1198
    }
 
1199
}
 
1200
 
 
1201
sub handle_POFILES($$)
 
1202
{
 
1203
  my @pofiles = split(" ", $_[0]);
 
1204
  my $lang = $_[1];
 
1205
 
 
1206
  # Build rules for creating the gmo files
 
1207
  my $tmp = "";
 
1208
  my $allgmofiles     = "";
 
1209
  my $pofileLine   = "POFILES =";
 
1210
  foreach $pofile (@pofiles)
 
1211
    {
 
1212
        $pofile =~ /(.*)\.[^\.]*$/;          # Find name minus extension
 
1213
        $tmp .= "$1.gmo: $pofile\n";
 
1214
        $tmp .= "\trm -f $1.gmo; \$(GMSGFMT) -o $1.gmo \$(srcdir)/$pofile\n";
 
1215
        $tmp .= "\ttest ! -f $1.gmo || touch $1.gmo\n";
 
1216
        $allgmofiles .= " $1.gmo";
 
1217
        $pofileLine  .= " $1.po";
 
1218
    }
 
1219
  appendLines ($tmp);
 
1220
  my $lookup = 'POFILES\s*=([^\n]*)';
 
1221
  if ($MakefileData !~ /\n$lookup/o) {
 
1222
    appendLines("$pofileLine\nGMOFILES =$allgmofiles");
 
1223
  } else {
 
1224
    substituteLine ($lookup, "$pofileLine\nGMOFILES =$allgmofiles");
 
1225
  }
 
1226
 
 
1227
    if ($allgmofiles) {
 
1228
 
 
1229
        # Add the "clean" rule so that the maintainer-clean does something
 
1230
        appendLines ("clean-nls:\n\t-rm -f $allgmofiles\n");
 
1231
 
 
1232
        $target_adds{"maintainer-clean"} .= "clean-nls ";
 
1233
 
 
1234
        $lookup = 'DISTFILES\s*=\s*(.*)';
 
1235
        if ($MakefileData =~ /\n$lookup\n/o) {
 
1236
          $tmp = "DISTFILES = \$(GMOFILES) \$(POFILES) $1";
 
1237
          substituteLine ($lookup, $tmp);
 
1238
        }
 
1239
    }
 
1240
 
 
1241
  $target_adds{"install-data-am"} .= "install-nls ";
 
1242
 
 
1243
  $tmp = "install-nls:\n";
 
1244
  if ($lang) {
 
1245
    $tmp  .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES\n";
 
1246
  }
 
1247
  $tmp .= "\t\@for base in ";
 
1248
  foreach $pofile (@pofiles)
 
1249
    {
 
1250
      $pofile =~ /(.*)\.[^\.]*$/;          # Find name minus extension
 
1251
      $tmp .= "$1 ";
 
1252
    }
 
1253
 
 
1254
  $tmp .= "; do \\\n";
 
1255
  if ($lang) {
 
1256
    $tmp .= "\t  echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n";
 
1257
    $tmp .= "\t  test ! -f \$\$base.gmo || \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n"
 
1258
  } else {
 
1259
    $tmp .= "\t  echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
 
1260
    $tmp .= "\t  \$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES ; \\\n";
 
1261
    $tmp .= "\t  test ! -f \$\$base.gmo || \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
 
1262
  }
 
1263
  $tmp .= "\tdone\n\n";
 
1264
  appendLines ($tmp);
 
1265
 
 
1266
  $target_adds{"uninstall"} .= "uninstall-nls ";
 
1267
 
 
1268
  $tmp = "uninstall-nls:\n";
 
1269
  foreach $pofile (@pofiles)
 
1270
    {
 
1271
      $pofile =~ /(.*)\.[^\.]*$/;          # Find name minus extension
 
1272
      if ($lang) {
 
1273
        $tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/$1.mo\n";
 
1274
      } else {
 
1275
        $tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$1/LC_MESSAGES/\$(PACKAGE).mo\n";
 
1276
      }
 
1277
    }
 
1278
  appendLines($tmp);
 
1279
 
 
1280
  $target_adds{"all"} .= "all-nls ";
 
1281
 
 
1282
  $tmp = "all-nls: \$(GMOFILES)\n";
 
1283
 
 
1284
  appendLines($tmp);
 
1285
 
 
1286
  $target_adds{"distdir"} .= "distdir-nls ";
 
1287
 
 
1288
  $tmp = "distdir-nls:\$(GMOFILES)\n";
 
1289
  $tmp .= "\tfor file in \$(POFILES); do \\\n";
 
1290
  $tmp .= "\t  cp \$(srcdir)/\$\$file \$(distdir); \\\n";
 
1291
  $tmp .= "\tdone\n";
 
1292
  $tmp .= "\tfor file in \$(GMOFILES); do \\\n";
 
1293
  $tmp .= "\t  cp \$(srcdir)/\$\$file \$(distdir); \\\n";
 
1294
  $tmp .= "\tdone\n";
 
1295
 
 
1296
  appendLines ($tmp);
 
1297
 
 
1298
  if (!$lang) {
 
1299
    appendLines("merge:\n\t\$(MAKE) -f \$(top_srcdir)/admin/Makefile.common package-merge POFILES=\"\${POFILES}\" PACKAGE=\${PACKAGE}\n\n");
 
1300
  }
 
1301
 
 
1302
}
 
1303
 
 
1304
#-----------------------------------------------------------------------------
 
1305
 
 
1306
# Returns 0 if the line was processed - 1 otherwise.
 
1307
# Errors are logged in the global $errorflags
 
1308
sub tag_POFILES ()
 
1309
{
 
1310
    my $lookup = 'POFILES\s*=([^\n]*)';
 
1311
    return 1    if ($MakefileData !~ /\n$lookup/o);
 
1312
    print STDOUT "POFILES processing <$1>\n"   if ($verbose);
 
1313
 
 
1314
    my $tmp = $1;
 
1315
 
 
1316
    # make sure these are all gone.
 
1317
    if ($MakefileData =~ /\n\.po\.gmo:\n/)
 
1318
    {
 
1319
        print STDERR "Warning: Found old .po.gmo rules in $printname. New po rules not added\n";
 
1320
        return 1;
 
1321
    }
 
1322
 
 
1323
    # Either find the pofiles in the directory (AUTO) or use
 
1324
    # only the specified po files.
 
1325
    my $pofiles = "";
 
1326
    if ($tmp =~ /^\s*AUTO\s*$/)
 
1327
    {
 
1328
        opendir (THISDIR, ".");
 
1329
        $pofiles =  join(" ", grep(/\.po$/, readdir(THISDIR)));
 
1330
        closedir (THISDIR);
 
1331
        print STDOUT "pofiles found = $pofiles\n"   if ($verbose);
 
1332
        if (-f "charset" && -f "kdelibs.po") {
 
1333
            handle_TOPLEVEL();
 
1334
        }
 
1335
    }
 
1336
    else
 
1337
    {
 
1338
        $tmp =~ s/\034/ /g;
 
1339
        $pofiles = $tmp;
 
1340
    }
 
1341
    return 1    if (!$pofiles);        # Nothing to do
 
1342
 
 
1343
    handle_POFILES($pofiles, $kdelang);
 
1344
 
 
1345
    return 0;
 
1346
}
 
1347
 
 
1348
sub helper_LOCALINSTALL($)
 
1349
{
 
1350
  my $lookup = "\n" . $_[0] . ":";
 
1351
  if ($MakefileData =~ /($lookup)/) {
 
1352
 
 
1353
    my $install = $MakefileData;
 
1354
    $install =~ s/\n/\035/g;
 
1355
    $install =~ s/.*\035$_[0]:[^\035]*\035//;
 
1356
    my $emptyline = 0;
 
1357
    while (! $emptyline) {
 
1358
      if ($install =~ /([^\035]*)\035(.*)/) {
 
1359
        local $line = $1;
 
1360
        $install = $2;
 
1361
        if ($line !~ /^\s*$/ && $line !~ /^(\@.*\@)*\t/) {
 
1362
          $emptyline = 1;
 
1363
        } else {
 
1364
          replaceDestDir($line);
 
1365
        }
 
1366
      } else {
 
1367
        $emptyline = 1;
 
1368
      }
 
1369
    }
 
1370
  }
 
1371
 
 
1372
}
 
1373
 
 
1374
sub tag_LOCALINSTALL ()
 
1375
{
 
1376
  helper_LOCALINSTALL('install-exec-local');
 
1377
  helper_LOCALINSTALL('install-data-local');
 
1378
  helper_LOCALINSTALL('uninstall-local');
 
1379
 
 
1380
  return 0;
 
1381
}
 
1382
 
 
1383
sub replaceDestDir($) {
 
1384
  local $line = $_[0];
 
1385
 
 
1386
  if (   $line =~ /^\s*(\@.*\@)*\s*\$\(mkinstalldirs\)/
 
1387
      || $line =~ /^\s*(\@.*\@)*\s*\$\(INSTALL\S*\)/
 
1388
      || $line =~ /^\s*(\@.*\@)*\s*(-?rm.*) \S*$/)
 
1389
  {
 
1390
    $line =~ s/^(.*) ([^\s]*)\s*$/$1 \$(DESTDIR)$2/ if ($line !~ /\$\(DESTDIR\)/);
 
1391
  }
 
1392
 
 
1393
  if ($line ne $_[0]) {
 
1394
    $_[0] = quotemeta $_[0];
 
1395
    substituteLine($_[0], $line);
 
1396
  }
 
1397
}
 
1398
 
 
1399
#---------------------------------------------------------------------------
 
1400
sub tag_CLOSURE () {
 
1401
    return if ($program !~ /_la$/);
 
1402
    
 
1403
    my $lookup = quotemeta($realname{$program}) . ":.*?\n\t.*?\\((.*?)\\) .*\n";
 
1404
    $MakefileData =~ m/$lookup/;
 
1405
    return if ($1 !~ /CXXLINK/);
 
1406
 
 
1407
    if ($MakefileData !~ /\n$program\_LDFLAGS\s*=.*-no-undefined/ &&
 
1408
        $MakefileData !~ /\n$program\_LDFLAGS\s*=.*KDE_PLUGIN/ ) {
 
1409
        print STDERR "Report: $program contains undefined in $printname\n" if ($program =~ /^lib/ && $dryrun);
 
1410
        return;
 
1411
    }
 
1412
    my $closure = $realname{$program} . ".closure";
 
1413
    my $lines = "$closure: \$($program\_OBJECTS) \$($program\_DEPENDENCIES)\n";
 
1414
    $lines .= "\t\@echo \"int main() {return 0;}\" > $program\_closure.$cxxsuffix\n";
 
1415
    $lines .= "\t\@\$\(LTCXXCOMPILE\) -c $program\_closure.$cxxsuffix\n";
 
1416
    $lines .= "\t\$\(CXXLINK\) $program\_closure.lo \$($program\_LDFLAGS) \$($program\_OBJECTS) \$($program\_LIBADD) \$(LIBS)\n";
 
1417
    $lines .= "\t\@rm -f $program\_closure.* $closure\n";
 
1418
    $lines .= "\t\@echo \"timestamp\" > $closure\n";
 
1419
    $lines .= "\n";
 
1420
    appendLines($lines);
 
1421
    $lookup = $realname{$program} . ": (.*)";
 
1422
    if ($MakefileData =~ /\n$lookup\n/) {
 
1423
        $lines  = "\@KDE_USE_CLOSURE_TRUE@". $realname{$program} . ": $closure $1";
 
1424
        $lines .= "\n\@KDE_USE_CLOSURE_FALSE@" . $realname{$program} . ": $1";
 
1425
        substituteLine($lookup, $lines);
 
1426
    }
 
1427
    $closure_output .= " $closure";
 
1428
}
 
1429
 
 
1430
sub tag_DIST () {
 
1431
    my %foundfiles = ();
 
1432
    opendir (THISDIR, ".");
 
1433
    foreach $entry (readdir(THISDIR)) {
 
1434
        next if ($entry eq "CVS" || $entry =~ /^\./  || $entry =~ /^Makefile$$/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
 
1435
        next if (! -f $entry);
 
1436
        next if ($entry =~ /\.moc/ || $entry =~ /\.lo$/ || $entry =~ /\.la$/ || $entry =~ /\.o/);
 
1437
        next if ($entry =~ /.+meta_unload.$cppExt$/ || $entry =~ /\.all_$cppExt\.$cppExt$/);
 
1438
        $foundfiles{$entry} = 1;
 
1439
    }
 
1440
    closedir (THISDIR);
 
1441
 
 
1442
    my @marks = ("EXTRA_DIST", "DIST_COMMON", '\S*_SOURCES', '\S*_HEADERS', 'MAINTAINERCLEANFILES', 'CLEANFILES', 'DISTCLEANFILES', '\S*_OBJECTS');
 
1443
    foreach $mark (@marks) {
 
1444
        while ($MakefileData =~ /\n($mark)\s*=\s*([^\n]*)/g) {
 
1445
            foreach $file (split('[\034\s]', $2)) {
 
1446
                $file =~ s/\.\///;
 
1447
                $foundfiles{$file} = 0 if (defined $foundfiles{$file});
 
1448
            }
 
1449
        }
 
1450
    }
 
1451
    my @files = ("Makefile", "config.cache", "config.log", "stamp-h",
 
1452
                 "stamp-h1", "stamp-h1", "config.h", "Makefile", "config.status", "config.h", "libtool");
 
1453
    foreach $file (@files) {
 
1454
        $foundfiles{$file} = 0 if (defined $foundfiles{$file});
 
1455
    }
 
1456
 
 
1457
    my $KDE_DIST = "";
 
1458
    foreach $file (keys %foundfiles) {
 
1459
        if ($foundfiles{$file} == 1) {
 
1460
            $KDE_DIST .= "$file ";
 
1461
        }
 
1462
    }
 
1463
    if ($KDE_DIST) {
 
1464
        print "KDE_DIST $printname $KDE_DIST\n" if ($verbose);
 
1465
        
 
1466
        my $lookup = "DISTFILES *=(.*)";
 
1467
        if ($MakefileData =~ /\n$lookup\n/o) {
 
1468
            substituteLine($lookup, "KDE_DIST=$KDE_DIST\n\nDISTFILES=$1 \$(KDE_DIST)\n");
 
1469
        }
 
1470
    }
 
1471
}
 
1472
 
 
1473
#-----------------------------------------------------------------------------
 
1474
# Returns 0 if the line was processed - 1 otherwise.
 
1475
# Errors are logged in the global $errorflags
 
1476
sub tag_DOCFILES ()
 
1477
{
 
1478
#    if ($MakefileData =~ /\nSUBDIRS\s*=/) { # subdirs
 
1479
#      $MakefileData =~ /\n(.*-recursive:\s*)\n/;
 
1480
#      my $orig_rules = $1;
 
1481
#      my $rules = $orig_rules;
 
1482
#      $rules =~ s/:\s*$//;
 
1483
#      substituteLine($orig_rules, "$rules docs-recursive:");
 
1484
#      appendLines("docs: docs-recursive docs-am\n");
 
1485
#    } else {
 
1486
#      appendLines("docs: docs-am\n");
 
1487
#    }
 
1488
    $target_adds{"all"} .= "docs-am ";
 
1489
 
 
1490
    my $lookup = 'KDE_DOCS\s*=\s*([^\n]*)';
 
1491
    goto nodocs    if ($MakefileData !~ /\n$lookup/o);
 
1492
    print STDOUT "KDE_DOCS processing <$1>\n"   if ($verbose);
 
1493
 
 
1494
    my $tmp = $1;
 
1495
 
 
1496
    # Either find the files in the directory (AUTO) or use
 
1497
    # only the specified po files.
 
1498
    my $files = "";
 
1499
    my $appname = $tmp;
 
1500
    $appname =~ s/^(\S*)\s*.*$/$1/;
 
1501
    if ($appname =~ /AUTO/) {
 
1502
      $appname = basename($makefileDir);
 
1503
      if ("$appname" eq "en") {
 
1504
          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";
 
1505
          exit(1);
 
1506
      }
 
1507
    }
 
1508
 
 
1509
    if ($tmp !~ / - /)
 
1510
    {
 
1511
        opendir (THISDIR, ".");
 
1512
        foreach $entry (readdir(THISDIR)) {
 
1513
          next if ($entry eq "CVS" || $entry =~ /^\./  || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
 
1514
          next if (! -f $entry);
 
1515
          $files .= "$entry ";
 
1516
        }
 
1517
        closedir (THISDIR);
 
1518
        print STDOUT "docfiles found = $files\n"   if ($verbose);
 
1519
    }
 
1520
    else
 
1521
    {
 
1522
        $tmp =~ s/\034/ /g;
 
1523
        $tmp =~ s/^\S*\s*-\s*//;
 
1524
        $files = $tmp;
 
1525
    }
 
1526
    goto nodocs if (!$files);        # Nothing to do
 
1527
 
 
1528
    if ($files =~ /(^| )index\.docbook($| )/) {
 
1529
      
 
1530
      my $lines = "";
 
1531
      my $lookup = 'MEINPROC\s*=';
 
1532
      if ($MakefileData !~ /\n($lookup)/) {
 
1533
        $lines = "MEINPROC=/\$(kde_bindir)/meinproc\n";
 
1534
      }
 
1535
      $lookup = 'KDE_XSL_STYLESHEET\s*=';
 
1536
      if ($MakefileData !~ /\n($lookup)/) {
 
1537
        $lines .= "KDE_XSL_STYLESHEET=/\$(kde_datadir)/ksgmltools2/customization/kde-chunk.xsl\n";
 
1538
      }
 
1539
      $lookup = '\nindex.cache.bz2:';
 
1540
      if ($MakefileData !~ /\n($lookup)/) {
 
1541
         $lines .= "index.cache.bz2: \$(srcdir)/index.docbook \$(KDE_XSL_STYLESHEET) $files\n";
 
1542
         $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";
 
1543
         $lines .= "\n";
 
1544
      }
 
1545
 
 
1546
      $lines .= "docs-am: index.cache.bz2\n";  
 
1547
      $lines .= "\n";
 
1548
      $lines .= "install-docs: docs-am install-nls\n";
 
1549
      $lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n";
 
1550
      $lines .= "\t\@if test -f index.cache.bz2; then \\\n";
 
1551
      $lines .= "\techo \$(INSTALL_DATA) index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n";
 
1552
      $lines .= "\t\$(INSTALL_DATA) index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n";
 
1553
      $lines .= "\tfi\n";
 
1554
      $lines .= "\t-rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n";
 
1555
      $lines .= "\t\$(LN_S) \$(kde_libs_htmldir)/$kdelang/common \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n";
 
1556
 
 
1557
      $lines .= "\n";
 
1558
      $lines .= "uninstall-docs:\n";
 
1559
      $lines .= "\t-rm -rf \$(kde_htmldir)/$kdelang/$appname\n";
 
1560
      $lines .= "\n";
 
1561
      $lines .= "clean-docs:\n";
 
1562
      $lines .= "\t-rm -f index.cache.bz2\n";
 
1563
      $lines .= "\n";
 
1564
      $target_adds{"install-data-am"} .= "install-docs ";
 
1565
      $target_adds{"uninstall"} .= "uninstall-docs ";
 
1566
      $target_adds{"clean-am"} .= "clean-docs ";
 
1567
      appendLines ($lines);
 
1568
    } else {
 
1569
      appendLines("docs-am: $files\n");
 
1570
    }
 
1571
 
 
1572
    $target_adds{"install-data-am"} .= "install-nls";
 
1573
    $target_adds{"uninstall"} .= "uninstall-nls ";
 
1574
 
 
1575
    $tmp = "install-nls:\n";
 
1576
    $tmp .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n";
 
1577
    $tmp .= "\t\@for base in $files; do \\\n";
 
1578
    $tmp .= "\t  echo \$(INSTALL_DATA) \$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
 
1579
    $tmp .= "\t  \$(INSTALL_DATA) \$(srcdir)/\$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
 
1580
    $tmp .= "\tdone\n";
 
1581
    if ($appname eq 'common') {
 
1582
      $tmp .= "\t\@echo \"merging common and language specific dir\" ;\\\n";
 
1583
      $tmp .= "\tif test ! -e \$(kde_htmldir)/en/common/kde-common.css; then echo 'no english docs found in \$(kde_htmldir)/en/common/'; exit 1; fi \n";
 
1584
      $tmp .= "\t\@com_files=`cd \$(kde_htmldir)/en/common && echo *` ;\\\n";
 
1585
      $tmp .= "\tcd \$(DESTDIR)\$(kde_htmldir)/$kdelang/common ;\\\n";
 
1586
      $tmp .= "\tif test -n \"\$\$com_files\"; then for p in \$\$com_files ; do \\\n";
 
1587
      $tmp .= "\t  case \" $files \" in \\\n";
 
1588
      $tmp .= "\t    *\" \$\$p \"*) ;; \\\n";
 
1589
      $tmp .= "\t    *) test ! -e \$\$p && echo \$(LN_S) ../../en/common/\$\$p \$(DESTDIR)\$(kde_htmldir)/$kdelang/common/\$\$p && \$(LN_S) ../../en/common/\$\$p \$\$p ;; \\\n";
 
1590
      $tmp .= "\t  esac ; \\\n";
 
1591
      $tmp .= "\tdone ; fi ; true\n";
 
1592
    }
 
1593
    $tmp .= "\n";
 
1594
    $tmp .= "uninstall-nls:\n";
 
1595
    $tmp .= "\tfor base in $files; do \\\n";
 
1596
    $tmp .= "\t  rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
 
1597
    $tmp .= "\tdone\n\n";
 
1598
    appendLines ($tmp);
 
1599
 
 
1600
    $target_adds{"distdir"} .= "distdir-nls ";
 
1601
 
 
1602
    $tmp = "distdir-nls:\n";
 
1603
    $tmp .= "\tfor file in $files; do \\\n";
 
1604
    $tmp .= "\t  cp \$(srcdir)/\$\$file \$(distdir); \\\n";
 
1605
    $tmp .= "\tdone\n";
 
1606
 
 
1607
    appendLines ($tmp);
 
1608
 
 
1609
    return 0;
 
1610
 
 
1611
  nodocs:
 
1612
    appendLines("docs-am:\n");
 
1613
    return 1;
 
1614
}
 
1615
 
 
1616
#-----------------------------------------------------------------------------
 
1617
# Find headers in any of the source directories specified previously, that
 
1618
# are candidates for "moc-ing".
 
1619
sub findMocCandidates ()
 
1620
{
 
1621
    foreach $dir (@headerdirs)
 
1622
    {
 
1623
        my @list = ();
 
1624
        opendir (SRCDIR, "$dir");
 
1625
        @hFiles = grep { /.+\.$hExt$/o } readdir(SRCDIR);
 
1626
        closedir SRCDIR;
 
1627
        foreach $hf (@hFiles)
 
1628
        {
 
1629
            next if ($hf =~ /^\.\#/);
 
1630
            $hf =~ /(.*)\.[^\.]*$/;          # Find name minus extension
 
1631
            next if ($uiFiles{$1});
 
1632
            open (HFIN, "$dir/$hf") || die "Could not open $dir/$hf: $!\n";
 
1633
            my $hfsize = 0;
 
1634
            seek(HFIN, 0, 2);
 
1635
            $hfsize = tell(HFIN);
 
1636
            seek(HFIN, 0, 0);
 
1637
            read HFIN, $hfData, $hfsize;
 
1638
            close HFIN;
 
1639
            # push (@list, $hf) if(index($hfData, "Q_OBJECT") >= 0); ### fast but doesn't handle //Q_OBJECT
 
1640
            if ( $hfData =~ /{([^}]*)Q_OBJECT/s ) {              ## handle " { friend class blah; Q_OBJECT "
 
1641
                push (@list, $hf) unless $1 =~ m://[^\n]*Q_OBJECT[^\n]*$:s;  ## handle "// Q_OBJECT"
 
1642
            }
 
1643
        }
 
1644
        # The assoc array of root of headerfile and header filename
 
1645
        foreach $hFile (@list)
 
1646
        {
 
1647
            $hFile =~ /(.*)\.[^\.]*$/;          # Find name minus extension
 
1648
            if ($mocFiles{$1})
 
1649
            {
 
1650
              print STDERR "Warning: Multiple header files found for $1\n";
 
1651
              next;                           # Use the first one
 
1652
            }
 
1653
            $mocFiles{$1} = "$dir\035$hFile";   # Add relative dir
 
1654
        }
 
1655
    }
 
1656
 
 
1657
    return 0;
 
1658
}
 
1659
 
 
1660
#-----------------------------------------------------------------------------
 
1661
 
 
1662
# The programmer has specified a moc list. Prune out the moc candidates
 
1663
# list that we found based on looking at the header files. This generates
 
1664
# a warning if the programmer gets the list wrong, but this doesn't have
 
1665
# to be fatal here.
 
1666
sub pruneMocCandidates ($)
 
1667
{
 
1668
    my %prunedMoc = ();
 
1669
    local @mocList = split(' ', $_[0]);
 
1670
 
 
1671
    foreach $mocname (@mocList)
 
1672
    {
 
1673
        $mocname =~ s/\.moc$//;
 
1674
        if ($mocFiles{$mocname})
 
1675
        {
 
1676
            $prunedMoc{$mocname} = $mocFiles{$mocname};
 
1677
        }
 
1678
        else
 
1679
        {
 
1680
            my $print = $makefileDir;
 
1681
            $print =~ s/^\Q$topdir\E\\//;
 
1682
            # They specified a moc file but we can't find a header that
 
1683
            # will generate this moc file. That's possible fatal!
 
1684
            print STDERR "Warning: No moc-able header file for $print/$mocname\n";
 
1685
        }
 
1686
    }
 
1687
 
 
1688
    undef %mocFiles;
 
1689
    %mocFiles = %prunedMoc;
 
1690
}
 
1691
 
 
1692
#-----------------------------------------------------------------------------
 
1693
 
 
1694
# Finds the cpp files (If they exist).
 
1695
# The cpp files get appended to the header file separated by \035
 
1696
sub checkMocCandidates ()
 
1697
{
 
1698
    my @cppFiles;
 
1699
    my $cpp2moc;  # which c++ file includes which .moc files
 
1700
    my $moc2cpp;  # which moc file is included by which c++ files
 
1701
 
 
1702
    return unless (keys %mocFiles);
 
1703
    opendir(THISDIR, ".") || return;
 
1704
    @cppFiles = grep { /.+\.$cppExt$/o  && !/.+\.moc\.$cppExt$/o
 
1705
                         && !/.+\.all_$cppExt\.$cppExt$/o } readdir(THISDIR);
 
1706
    closedir THISDIR;
 
1707
    return unless (@cppFiles);
 
1708
    my $files = join (" ", @cppFiles);
 
1709
    $cpp2moc = {};
 
1710
    $moc2cpp = {};
 
1711
    foreach $cxxf (@cppFiles)
 
1712
    {
 
1713
      open (CXXFIN, $cxxf) || die "Could not open $cxxf: $!\n";
 
1714
      seek(CXXFIN, 0, 2);
 
1715
      my $cxxfsize = tell(CXXFIN);
 
1716
      seek(CXXFIN, 0, 0);
 
1717
      read CXXFIN, $cxxfData, $cxxfsize;
 
1718
      close CXXFIN;
 
1719
      while(($cxxfData =~ m/^[ \t]*\#include\s*[<\"](.*\.moc)[>\"]/gm)) {
 
1720
        $cpp2moc->{$cxxf}->{$1} = 1;
 
1721
        $moc2cpp->{$1}->{$cxxf} = 1;
 
1722
      }
 
1723
    }
 
1724
    foreach my $mocFile (keys (%mocFiles))
 
1725
    {
 
1726
        @cppFiles = keys %{$moc2cpp->{"$mocFile.moc"}};
 
1727
        if (@cppFiles == 1) {
 
1728
            $mocFiles{$mocFile} .= "\035" . $cppFiles[0];
 
1729
            push(@deped, $mocFile);
 
1730
        } elsif (@cppFiles == 0) {
 
1731
            push (@newObs, $mocFile);           # Produce new object file
 
1732
            next    if ($haveAutomocTag);       # This is expected...
 
1733
            # But this is an error we can deal with - let them know
 
1734
            print STDERR
 
1735
                "Warning: No c++ file that includes $mocFile.moc\n";
 
1736
        } else {
 
1737
            # We can't decide which file to use, so it's fatal. Although as a
 
1738
            # guess we could use the mocFile.cpp file if it's in the list???
 
1739
            print STDERR
 
1740
                "Error: Multiple c++ files that include $mocFile.moc\n";
 
1741
            print STDERR "\t",join ("\t", @cppFiles),"\n";
 
1742
            $errorflag = 1;
 
1743
            delete $mocFiles{$mocFile};
 
1744
            # Let's continue and see what happens - They have been told!
 
1745
        }
 
1746
    }
 
1747
}
 
1748
 
 
1749
#-----------------------------------------------------------------------------
 
1750
 
 
1751
# Add the rules for generating moc source from header files
 
1752
# For Automoc output *.moc.cpp but normally we'll output *.moc
 
1753
# (We must compile *.moc.cpp separately. *.moc files are included
 
1754
# in the appropriate *.cpp file by the programmer)
 
1755
sub addMocRules ()
 
1756
{
 
1757
    my $cppFile;
 
1758
    my $hFile;
 
1759
 
 
1760
    foreach $mocFile (keys (%mocFiles))
 
1761
    {
 
1762
        undef $cppFile;
 
1763
        ($dir, $hFile, $cppFile) =  split ("\035", $mocFiles{$mocFile}, 3);
 
1764
        $dir =~ s#^\.#\$(srcdir)#;
 
1765
        if (defined ($cppFile))
 
1766
        {
 
1767
            $target_adds{"\$(srcdir)/$cppFile"} .= "$mocFile.moc ";
 
1768
            appendLines ("$mocFile.moc: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile.moc\n");
 
1769
            $cleanMoc .= " $mocFile.moc";
 
1770
        }
 
1771
        else
 
1772
        {
 
1773
            appendLines ("$mocFile$mocExt: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile$mocExt\n");
 
1774
            $cleanMoc .= " $mocFile$mocExt";
 
1775
        }
 
1776
    }
 
1777
}
 
1778
 
 
1779
sub make_meta_classes ()
 
1780
{
 
1781
    return if ($kdeopts{"qtonly"});
 
1782
 
 
1783
    my $cppFile;
 
1784
    my $hFile;
 
1785
    my $moc_class_headers = "";
 
1786
    foreach $program (@programs) {
 
1787
        my $mocs = "";
 
1788
        my @progsources = split(/[\s\034]+/, $sources{$program});
 
1789
        my @depmocs = split(' ', $depedmocs{$program});
 
1790
        my %shash = (), %mhash = ();
 
1791
        @shash{@progsources} = 1;  # we are only interested in the existence
 
1792
        @mhash{@depmocs} = 1;
 
1793
 
 
1794
        print STDOUT "program=$program\n" if ($verbose);
 
1795
        print STDOUT "psources=[".join(' ', keys %shash)."]\n" if ($verbose);
 
1796
        print STDOUT "depmocs=[".join(' ', keys %mhash)."]\n" if ($verbose);
 
1797
        print STDOUT "globalmocs=[".join(' ', keys(%globalmocs))."]\n" if ($verbose);
 
1798
        foreach my $mocFile (keys (%globalmocs))
 
1799
        {
 
1800
            undef $cppFile;
 
1801
            ($dir, $hFile, $cppFile) = split ("\035", $globalmocs{$mocFile}, 3);
 
1802
            $dir =~ s#^\.#\$(srcdir)#;
 
1803
            if (defined ($cppFile))
 
1804
            {
 
1805
                $mocs .= " $mocFile.moc" if exists $shash{$cppFile};
 
1806
            }
 
1807
            else
 
1808
            {
 
1809
                # Bah. This is the case, if no C++ file includes the .moc
 
1810
                # file. We make a .moc.cpp file for that. Unfortunately this
 
1811
                # is not included in the %sources hash, but rather is mentioned
 
1812
                # in %depedmocs. If the user wants to use AUTO he can't just
 
1813
                # use an unspecific METAINCLUDES. Instead he must use
 
1814
                # program_METAINCLUDES. Anyway, it's not working real nicely.
 
1815
                # E.g. Its not clear what happens if user specifies two
 
1816
                # METAINCLUDES=AUTO in the same Makefile.am.
 
1817
                $mocs .= " $mocFile.moc.$cxxsuffix"
 
1818
                    if exists $mhash{$mocFile.".moc.$cxxsuffix"};
 
1819
            }
 
1820
        }
 
1821
        if ($mocs) {
 
1822
            print STDOUT "==> mocs=[".$mocs."]\n" if ($verbose);
 
1823
            my $sourcename = $program."_meta_unload";
 
1824
            my $ext = ($program =~ /_la$/) ? ".lo" : ".o";
 
1825
            my $srcfile = $sourcename.".$cxxsuffix";
 
1826
            my $objfile = $sourcename.$ext;
 
1827
            $moc_class_headers .= " $srcfile";
 
1828
            my $appl;
 
1829
            $appl  = "$srcfile: $mocs\n";
 
1830
            $appl .= "\t\@echo 'creating $srcfile'\n";
 
1831
            $appl .= "\t\@-rm -f $srcfile\n";
 
1832
            $appl .= "\t\@if test \${kde_qtver} = 2; then \\\n";
 
1833
            $appl .= "\t\techo 'static const char * _metalist_$program\[\] = {' > $srcfile ;\\\n";
 
1834
            $appl .= "\t\tcat $mocs | grep 'char.*className' | ";
 
1835
            $appl .=  "sed -e 's/.*[^A-Za-z0-9_:]\\([A-Za-z0-9_:]*\\)::className.*\$\$/\\\"\\1\\\",/' | sort | uniq >> $srcfile ;\\\n";
 
1836
            $appl .= "\t\techo '0};' >> $srcfile ;\\\n";
 
1837
            $appl .= "\t\techo '#include <kunload.h>' >> $srcfile ;\\\n";
 
1838
            $appl .= "\t\techo '_UNLOAD($program)' >> $srcfile ;\\\n";
 
1839
            $appl .= "\telse echo > $srcfile; fi\n";
 
1840
            $appl .= "\n";
 
1841
            
 
1842
            $realObjs{$program} .= " \034" . $objfile . " ";
 
1843
            $sources{$program} .= " $srcfile";
 
1844
            $sources_changed{$program} = 1;
 
1845
            $dep_files .= " \$(DEPDIR)/$sourcename.P" if($dep_files !~/$sourcename.P/);
 
1846
            appendLines ($appl);
 
1847
        }
 
1848
        print STDOUT "\n" if $verbose;
 
1849
    }
 
1850
    if ($moc_class_headers) {
 
1851
        appendLines ("$cleantarget-moc-classes:\n\t-rm -f $moc_class_headers\n");
 
1852
        $target_adds{"$cleantarget-am"} .= "$cleantarget-moc-classes ";
 
1853
    }
 
1854
}
 
1855
 
 
1856
#-----------------------------------------------------------------------------
 
1857
 
 
1858
sub updateMakefile ()
 
1859
{
 
1860
    return if ($dryrun);
 
1861
 
 
1862
    open (FILEOUT, "> $makefile")
 
1863
                        || die "Could not create $makefile: $!\n";
 
1864
 
 
1865
    print FILEOUT "\# $progId - " . '$Revision: 1.265.2.2 $ '  . "\n";
 
1866
    $MakefileData =~ s/\034/\\\n\t/g;    # Restore continuation lines
 
1867
    print FILEOUT $MakefileData;
 
1868
    close FILEOUT;
 
1869
}
 
1870
 
 
1871
#-----------------------------------------------------------------------------
 
1872
 
 
1873
# The given line needs to be removed from the makefile
 
1874
# Do this by adding the special "removed line" comment at the line start.
 
1875
sub removeLine ($$)
 
1876
{
 
1877
    my ($lookup, $old) = @_;
 
1878
 
 
1879
    $old =~ s/\034/\\\n#>- /g;          # Fix continuation lines
 
1880
    $MakefileData =~ s/\n$lookup/\n#>\- $old/;
 
1881
}
 
1882
 
 
1883
#-----------------------------------------------------------------------------
 
1884
 
 
1885
# Replaces the old line with the new line
 
1886
# old line(s) are retained but tagged as removed. The new line(s) have the
 
1887
# "added" tag placed before it.
 
1888
sub substituteLine ($$)
 
1889
{
 
1890
    my ($lookup, $new) = @_;
 
1891
 
 
1892
    if ($MakefileData =~ /\n($lookup)/) {
 
1893
      $old = $1;
 
1894
      $old =~ s/\034/\\\n#>\- /g;         # Fix continuation lines
 
1895
      $new =~ s/\034/\\\n\t/g;
 
1896
      my $newCount = ($new =~ tr/\n//) + 1;
 
1897
      $MakefileData =~ s/\n$lookup/\n#>- $old\n#>\+ $newCount\n$new/;
 
1898
    } else {
 
1899
      print STDERR "Warning: substitution of \"$lookup\" in $printname failed\n";
 
1900
    }
 
1901
}
 
1902
 
 
1903
#-----------------------------------------------------------------------------
 
1904
 
 
1905
# Slap new lines on the back of the file.
 
1906
sub appendLines ($)
 
1907
{
 
1908
  my ($new) = @_;
 
1909
  $new =~ s/\034/\\\n\t/g;        # Fix continuation lines
 
1910
  my $newCount = ($new =~ tr/\n//) + 1;
 
1911
  $MakefileData .= "\n#>\+ $newCount\n$new";
 
1912
}
 
1913
 
 
1914
#-----------------------------------------------------------------------------
 
1915
 
 
1916
# Restore the Makefile.in to the state it was before we fiddled with it
 
1917
sub restoreMakefile ()
 
1918
{
 
1919
    $MakefileData =~ s/# $progId[^\n\034]*[\n\034]*//g;
 
1920
    # Restore removed lines
 
1921
    $MakefileData =~ s/([\n\034])#>\- /$1/g;
 
1922
    # Remove added lines
 
1923
    while ($MakefileData =~ /[\n\034]#>\+ ([^\n\034]*)/)
 
1924
    {
 
1925
        my $newCount = $1;
 
1926
        my $removeLines = "";
 
1927
        while ($newCount--) {
 
1928
            $removeLines .= "[^\n\034]*([\n\034]|)";
 
1929
        }
 
1930
        $MakefileData =~ s/[\n\034]#>\+.*[\n\034]$removeLines/\n/;
 
1931
    }
 
1932
}
 
1933
 
 
1934
#-----------------------------------------------------------------------------