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