source: trunk/MagicSoft/AMC/activemirrorcontrol/admin/am_edit@ 9488

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