~ubuntu-branches/ubuntu/raring/qgo/raring

« back to all changes in this revision

Viewing changes to admin/am_edit

  • Committer: Bazaar Package Importer
  • Author(s): Martin A. Godisch
  • Date: 2005-01-01 23:07:10 UTC
  • Revision ID: james.westby@ubuntu.com-20050101230710-fhng6yidm47xlb2i
Tags: upstream-1.0.0-r2
ImportĀ upstreamĀ versionĀ 1.0.0-r2

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