comparison kdiff3/admin/am_edit @ 2:53b8ecbce0cb

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