Fixed am_edit so that it installs _ICON lists that are split on multiple lines.
[kdbg.git] / admin / am_edit
blob8ca500dda48732d1949cd47f5dbf796f7a61c637
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 # ...
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>
35 use Cwd;
36 use File::Find;
37 use File::Basename;
39 # Prototype the functions
40 sub initialise ();
41 sub processMakefile ($);
42 sub updateMakefile ();
43 sub restoreMakefile ();
45 sub removeLine ($$);
46 sub appendLines ($);
47 sub substituteLine ($$);
49 sub findMocCandidates ();
50 sub pruneMocCandidates ($);
51 sub checkMocCandidates ();
52 sub addMocRules ();
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();
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;
87 while (defined ($ARGV[0]))
89 $_ = shift;
90 if (/^--version$/)
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;
105 elsif (/^--verbose$|^-v$/)
107 $verbose = 1; # Oh is there a problem...?
109 elsif (/^-p(.+)$|^--path=(.+)$/)
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;
116 elsif (/^--help$|^-h$/)
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";
130 exit 0;
132 elsif (/^--no-final$/)
134 $use_final = 0;
135 $thisProg .= " --no-final";
137 elsif (/^--foreign-libtool$/)
139 $foreign_libtool = 1;
140 $thisProg .= " --foreign-libtool";
142 elsif (/^-n$/)
144 $dryrun = 1;
146 else
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, $_);
156 if ($thisProg =~ /^\// && !$pathoption )
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;
164 # Only scan for files when the user hasn't entered data
165 if (!@makefiles)
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);
174 foreach $makefile (sort(@makefiles))
176 processMakefile ($makefile);
177 last if ($errorflag);
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);
183 exit $errorflag; # causes make to fail if erroflag is set
185 #-----------------------------------------------------------------------------
187 # In conjunction with the "find" call, this builds the list of input files
188 sub add_makefile ()
190 push (@makefiles, $File::Find::name) if (/Makefile.in$/);
193 #-----------------------------------------------------------------------------
195 # Processes a single make file
196 # The parameter contains the full path name of the Makefile.in to use
197 sub processMakefile ($)
199 # some useful globals for the subroutines called here
200 local ($makefile) = @_;
201 local @headerdirs = ('.');
202 local $haveAutomocTag = 0;
203 local $MakefileData = "";
205 local $cxxsuffix = "KKK";
207 local @programs = (); # lists the names of programs and libraries
208 local $program = "";
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 = ();
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
223 local %depedmocs = ();
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 = "";
234 $makefileDir = dirname($makefile);
235 chdir ($makefileDir);
236 $printname = $makefile;
237 $printname =~ s/^\Q$topdir\E\///;
238 $makefile = basename($makefile);
240 print STDOUT "Processing makefile $printname\n" if ($verbose);
242 # Setup and see if we need to do this.
243 return if (!initialise());
245 tag_AUTOMAKE (); # Allows a "make" to redo the Makefile.in
246 tag_META_INCLUDES (); # Supplies directories for src locations
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});
260 if ($important{$program}) {
261 local %source_dict = ();
262 for $source (split(/[\034\s]+/, $sources{$program})) {
263 $source_dict{$source} = 1;
265 for $source (@cleanfiles) {
266 $source_dict{$source} = 0;
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};
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 ";
289 tag_DIST() unless ($kdeopts{"noautodist"});
291 if ($idl_output) {
292 appendLines ("$cleantarget-idl:\n\t-rm -f $idl_output\n");
293 $target_adds{"$cleantarget-am"} .= "$cleantarget-idl ";
296 if ($ui_output) {
297 appendLines ("$cleantarget-ui:\n\t-rm -f $ui_output\n");
298 $target_adds{"$cleantarget-am"} .= "$cleantarget-ui ";
301 if ($closure_output) {
302 appendLines ("$cleantarget-closures:\n\t-rm -f $closure_output\n");
303 $target_adds{"$cleantarget-am"} .= "$cleantarget-closures ";
306 if ($MakefileData =~ /\nKDE_LANG\s*=\s*(\S*)\s*\n/) {
307 $kdelang = '$(KDE_LANG)'
308 } else {
309 $kdelang = '';
312 tag_POFILES (); # language rules for po directory
313 tag_DOCFILES (); # language rules for doc directories
314 tag_LOCALINSTALL(); # add $(DESTDIR) before all kde_ dirs
315 tag_ICON();
316 tag_SUBDIRS();
318 my $tmp = "force-reedit:\n";
319 $tmp .= "\t$automkCall\n\tcd \$(top_srcdir) && perl $thisProg $printname\n\n";
320 appendLines($tmp);
322 make_meta_classes();
323 tag_COMPILE_FIRST();
324 tag_FINAL() if (!$kdeopts{"nofinal"});
326 my $final_lines = "final:\n\t\$(MAKE) ";
327 my $final_install_lines = "final-install:\n\t\$(MAKE) ";
328 my $nofinal_lines = "no-final:\n\t\$(MAKE) ";
329 my $nofinal_install_lines = "no-final-install:\n\t\$(MAKE) ";
331 foreach $program (@programs) {
333 my $lookup = "$program\_OBJECTS.*=[^\n]*";
335 my $new = "";
337 my @list = split(/[\034\s]+/, $realObjs{$program});
339 if (!$kdeopts{"nofinal"} && @list > 1 && $finalObjs{$program}) {
341 $new .= "$program\_final\_OBJECTS = " . $finalObjs{$program};
342 $new .= "\n$program\_nofinal\_OBJECTS = " . $realObjs{$program};
343 $new .= "\n\@KDE_USE_FINAL_FALSE\@$program\_OBJECTS = \$($program\_nofinal\_OBJECTS)";
344 $new .= "\n\@KDE_USE_FINAL_TRUE\@$program\_OBJECTS = \$($program\_final\_OBJECTS)";
346 $final_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" ";
347 $final_install_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" ";
348 $nofinal_lines .= "$program\_OBJECTS=\"\$($program\_nofinal\_OBJECTS)\" ";
349 $nofinal_install_lines .= "$program\_OBJECTS=\"\$($program\_nofinal_OBJECTS)\" ";
350 } else {
351 $new = "$program\_OBJECTS = " . $realObjs{$program};
353 substituteLine ($lookup, $new);
355 appendLines($final_lines . "all-am");
356 appendLines($final_install_lines . "install-am");
357 appendLines($nofinal_lines . "all-am");
358 appendLines($nofinal_install_lines . "install-am");
360 my $lookup = 'DEP_FILES\s*=([^\n]*)';
361 if ($MakefileData =~ /\n$lookup\n/o) {
362 $depfiles = $1;
364 if ($dep_finals) {
365 $lines = "\@KDE_USE_FINAL_TRUE\@DEP_FILES = $dep_files $dep_finals \034\t$depfiles\n";
366 $lines .= "\@KDE_USE_FINAL_FALSE\@DEP_FILES = $dep_files $depfiles\n";
367 } else {
368 $lines = "DEP_FILES = $dep_files $depfiles\n";
371 substituteLine($lookup, $lines);
374 my $cvs_lines = "cvs-clean:\n";
375 $cvs_lines .= "\t\$(MAKE) -f \$(top_srcdir)/admin/Makefile.common cvs-clean\n";
376 appendLines($cvs_lines);
378 $cvs_lines = "kde-rpo-clean:\n";
379 $cvs_lines .= "\t-rm -f *.rpo\n";
380 appendLines($cvs_lines);
381 $target_adds{"clean"} .= "kde-rpo-clean ";
383 # some strange people like to do a install-exec, and expect that also
384 # all modules are installed. automake doesn't know this, so we need to move
385 # this here from install-data to install-exec.
386 if ($MakefileData =~ m/\nkde_module_LTLIBRARIES\s*=/) {
387 $target_adds{"install-exec-am"} .= "install-kde_moduleLTLIBRARIES";
388 my $lookup = 'install-data-am:\s*(.*)';
389 if ($MakefileData =~ /\n$lookup\n/) {
390 my $newdeps = $1;
391 $newdeps =~ s/\s*install-kde_moduleLTLIBRARIES\s*/ /g;
392 substituteLine($lookup, "install-data-am: " . $newdeps);
396 my $lines = "";
398 foreach $add (keys %target_adds) {
399 my $lookup = quotemeta($add) . ':([^\n]*)';
400 if ($MakefileData =~ /\n$lookup\n/) {
401 substituteLine($lookup, "$add: " . $target_adds{$add} . $1);
402 } else {
403 $lines .= "$add: " . $target_adds{$add} . "\n";
406 if ($lines) {
407 appendLines($lines);
410 my $found = 1;
412 while ($found) {
413 if ($MakefileData =~ m/\n(.*)\$\(CXXFLAGS\)(.*)\n/) {
414 my $vor = $1; # "vor" means before in German
415 my $nach = $2; # "nach" means after in German
416 my $lookup = quotemeta("$1\$(CXXFLAGS)$2");
417 my $replacement = "$1\$(KCXXFLAGS)$2";
418 $MakefileData =~ s/$lookup/$replacement/;
419 $lookup =~ s/\\\$\\\(CXXFLAGS\\\)/\\\$\\\(KCXXFLAGS\\\)/;
420 $replacement = "$vor\$(KCXXFLAGS) \$(KDE_CXXFLAGS)$nach";
421 substituteLine($lookup, $replacement);
422 } else {
423 $found = 0;
427 if($foreign_libtool == 0) {
428 $lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=link) (\$\(CXXLD\).*\$\(KCXXFLAGS\))';
430 if ($MakefileData =~ m/$lookup/ ) {
431 $MakefileData =~ s/$lookup/$1 --tag=CXX $2/;
434 $lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=compile)\s+(\$\(CXX\)\s+)';
435 if ($MakefileData =~ m/$lookup/ ) {
436 $MakefileData =~ s/$lookup/$1 --tag=CXX $2/;
440 $MakefileData =~ s/\$\(KCXXFLAGS\)/\$\(CXXFLAGS\)/g;
442 $lookup = '(.*)cp -pr \$\$/\$\$file \$\(distdir\)/\$\$file(.*)';
443 if ($MakefileData =~ m/\n$lookup\n/) {
444 substituteLine($lookup, "$1cp -pr \$\$d/\$\$file \$(distdir)/\$\$file$2");
447 # Always update the Makefile.in
448 updateMakefile ();
449 return;
452 #-----------------------------------------------------------------------------
454 # Check to see whether we should process this make file.
455 # This is where we look for tags that we need to process.
456 # A small amount of initialising on the tags is also done here.
457 # And of course we open and/or create the needed make files.
458 sub initialise ()
460 if (! -r "Makefile.am") {
461 print STDOUT "found Makefile.in without Makefile.am\n" if ($verbose);
462 return 0;
465 # Checking for files to process...
466 open (FILEIN, $makefile)
467 || die "Could not open $makefileDir/$makefile: $!\n";
468 # Read the file
469 # stat(FILEIN)[7] might look more elegant, but is slower as it
470 # requires stat'ing the file
471 seek(FILEIN, 0, 2);
472 my $fsize = tell(FILEIN);
473 seek(FILEIN, 0, 0);
474 read FILEIN, $MakefileData, $fsize;
475 close FILEIN;
476 print "DOS CRLF within $makefileDir/$makefile!\n" if($MakefileData =~ y/\r//d);
478 # Remove the line continuations, but keep them marked
479 # Note: we lose the trailing spaces but that's ok.
480 $MakefileData =~ s/\\\s*\n\s*/\034/g;
482 # If we've processed the file before...
483 restoreMakefile () if ($MakefileData =~ /$progId/);
485 foreach $dir (@foreignfiles) {
486 if (substr($makefileDir,0,length($dir)) eq $dir) {
487 return 0;
491 %kdeopts = ();
492 $kdeopts{"foreign"} = 0;
493 $kdeopts{"qtonly"} = 0;
494 $kdeopts{"noautodist"} = 0;
495 $kdeopts{"foreign-libtool"} = $foreign_libtool;
496 $kdeopts{"nofinal"} = !$use_final; # default
498 if ($MakefileData =~ /\nKDE_OPTIONS\s*=\s*([^\n]*)\n/) {
499 local @kde_options = split(/[\s\034]/, $1);
500 if (grep(/^foreign$/, @kde_options)) {
501 push(@foreignfiles, $makefileDir . "/");
502 return 0; # don't touch me
504 for $opt (@kde_options) {
505 if (!defined $kdeopts{$opt}) {
506 print STDERR "Warning: unknown option $opt in $printname\n";
507 } else {
508 $kdeopts{$opt} = 1;
513 # Look for the tags that mean we should process this file.
514 $metasourceTags = 0;
515 $metasourceTags++ while ($MakefileData =~ /\n[^=\#]*METASOURCES\s*=/g);
517 my $pofileTag = 0;
518 $pofileTag++ while ($MakefileData =~ /\nPOFILES\s*=/g);
519 if ($pofileTag > 1)
521 print STDERR "Error: Only one POFILES tag allowed\n";
522 $errorflag = 1;
525 while ($MakefileData =~ /\n\.SUFFIXES:([^\n]+)\n/g) {
526 my @list=split(' ', $1);
527 foreach $ext (@list) {
528 if ($ext =~ /^\.$cppExt$/) {
529 $cxxsuffix = $ext;
530 $cxxsuffix =~ s/\.//g;
531 print STDOUT "will use suffix $cxxsuffix\n" if ($verbose);
532 last;
537 while ($MakefileData =~ /\n(\S*)_OBJECTS\s*=[ \t\034]*([^\n]*)\n/g) {
539 my $program = $1;
540 my $objs = $2; # safe them
542 my $ocv = 0;
544 my @objlist = split(/[\s\034]+/, $objs);
545 foreach $obj (@objlist) {
546 if ($obj =~ /\$\((\S+)\)/ ) {
547 my $variable = $1;
548 if ($variable !~ 'OBJEXT') {
549 $ocv = 1;
554 next if ($ocv);
556 $program =~ s/^am_// if ($program =~ /^am_/);
558 my $sourceprogram = $program;
559 $sourceprogram =~ s/\@am_/\@/ if($sourceprogram =~ /^.*\@am_.+/);
561 print STDOUT "found program $program\n" if ($verbose);
562 push(@programs, $program);
564 $realObjs{$program} = $objs;
566 if ($MakefileData =~ /\n$sourceprogram\_SOURCES\s*=\s*(.*)\n/) {
567 $sources{$program} = $1;
569 else {
570 $sources{$program} = "";
571 print STDERR "found program with no _SOURCES: $program\n";
574 my $realprogram = $program;
575 $realprogram =~ s/_/./g; # unmask to regexp
576 if ($MakefileData =~ /\n($realprogram)(\$\(EXEEXT\)?)?:.*\$\($program\_OBJECTS\)/) {
577 $realname{$program} = $1;
578 } else {
579 # not standard Makefile - nothing to worry about
580 $realname{$program} = "";
584 my $lookup = '\nDEPDIR\s*=.*';
585 if ($MakefileData !~ /($lookup)\n/o) {
586 $lookup = '\nbindir\s*=.*';
587 if ($MakefileData =~ /($lookup)\n/) {
588 substituteLine ($lookup, "DEPDIR = .deps\n$1");
592 my @marks = ('MAINTAINERCLEANFILES', 'CLEANFILES', 'DISTCLEANFILES');
593 foreach $mark (@marks) {
594 while ($MakefileData =~ /\n($mark)\s*=\s*([^\n]*)/g) {
595 foreach $file (split('[\034\s]', $2)) {
596 $file =~ s/\.\///;
597 push(@cleanfiles, $file);
602 my $localTag = 0;
603 $localTag++ if ($MakefileData =~ /\ninstall-\S+-local:/);
605 return (!$errorflag);
608 #-----------------------------------------------------------------------------
610 # Gets the list of user defined directories - relative to $srcdir - where
611 # header files could be located.
612 sub tag_META_INCLUDES ()
614 my $lookup = '[^=\n]*META_INCLUDES\s*=\s*(.*)';
615 return 1 if ($MakefileData !~ /($lookup)\n/o);
616 print STDOUT "META_INCLUDE processing <$1>\n" if ($verbose);
618 my $headerStr = $2;
619 removeLine ($lookup, $1);
621 $headerStr =~ tr/\034/ /;
622 my @headerlist = split(' ', $headerStr);
624 foreach $dir (@headerlist)
626 $dir =~ s#\$\(srcdir\)#.#;
627 if (! -d $dir)
629 print STDERR "Warning: $dir can't be found. ",
630 "Must be a relative path to \$(srcdir)\n";
632 else
634 push (@headerdirs, $dir);
638 return 0;
641 #-----------------------------------------------------------------------------
643 sub tag_FINAL()
645 my @final_names = ();
647 foreach $program (@programs) {
649 if ($sources{$program} =~ /\(/) {
650 print STDOUT "found ( in $program\_SOURCES. skipping\n" if ($verbose);
651 next;
654 my $mocsources = "";
656 my @progsources = split(/[\s\034]+/, $sources{$program});
657 my %sourcelist = ();
659 foreach $source (@progsources) {
660 my $suffix = $source;
661 $suffix =~ s/^.*\.([^\.]+)$/$1/;
663 if (defined($sourcelist{$suffix})) {
664 $sourcelist{$suffix} .= " " . $source;
665 } else {
666 $sourcelist{$suffix} .= $source;
670 foreach $suffix (keys %sourcelist) {
672 # See if this file contains c++ code. (ie Just check the files suffix against
673 my $suffix_is_cxx = 0;
674 if($suffix =~ /($cppExt)$/) {
675 $cxxsuffix = $1;
676 $suffix_is_cxx = 1;
679 my $mocfiles_in = ($suffix eq $cxxsuffix) &&
680 defined($depedmocs{$program});
682 my @sourcelist = split(/[\s\034]+/, $sourcelist{$suffix});
684 if ((@sourcelist == 1 && !$mocfiles_in) || $suffix_is_cxx != 1 ) {
686 # we support IDL on our own
687 if ($suffix =~ /^skel$/ || $suffix =~ /^stub/ || $suffix =~ /^signals/
688 || $suffix =~ /^h$/ || $suffix =~ /^ui$/ ) {
689 next;
692 foreach $file (@sourcelist) {
694 $file =~ s/\Q$suffix\E$//;
696 $finalObjs{$program} .= $file;
697 if ($program =~ /_la$/) {
698 $finalObjs{$program} .= "lo ";
699 } else {
700 $finalObjs{$program} .= "o ";
703 next; # suffix
706 my $source_deps = "";
707 foreach $source (@sourcelist) {
708 if (-f $source) {
709 $source_deps .= "\$(srcdir)/$source ";
710 } else {
711 $source_deps .= "$source ";
715 $handling = "$program.all_$suffix.$suffix: \$(srcdir)/Makefile.in " . $source_deps . " ";
717 if ($mocfiles_in) {
718 $handling .= $depedmocs{$program};
719 foreach $mocfile (split(' ', $depedmocs{$program})) {
721 if ($mocfile =~ m/\.$suffix$/) {
722 $mocsources .= " " . $mocfile;
727 $handling .= "\n";
728 $handling .= "\t\@echo 'creating $program.all_$suffix.$suffix ...'; \\\n";
729 $handling .= "\trm -f $program.all_$suffix.files $program.all_$suffix.final; \\\n";
730 $handling .= "\techo \"#define KDE_USE_FINAL 1\" >> $program.all_$suffix.final; \\\n";
731 $handling .= "\tfor file in " . $sourcelist{$suffix} . " $mocsources; do \\\n";
732 $handling .= "\t echo \"#include \\\"\$\$file\\\"\" >> $program.all_$suffix.files; \\\n";
733 $handling .= "\t test ! -f \$\(srcdir\)/\$\$file || egrep '^#pragma +implementation' \$\(srcdir\)/\$\$file >> $program.all_$suffix.final; \\\n";
734 $handling .= "\tdone; \\\n";
735 $handling .= "\tcat $program.all_$suffix.final $program.all_$suffix.files > $program.all_$suffix.$suffix; \\\n";
736 $handling .= "\trm -f $program.all_$suffix.final $program.all_$suffix.files\n";
738 appendLines($handling);
740 push(@final_names, "$program.all_$suffix.$suffix");
741 $finalObjs{$program} .= "$program.all_$suffix.";
742 if ($program =~ /_la$/) {
743 $finalObjs{$program} .= "lo ";
744 } else {
745 $finalObjs{$program} .= "o ";
750 if (!$kdeopts{"nofinal"} && @final_names >= 1) {
751 # add clean-final target
752 my $lines = "$cleantarget-final:\n";
753 $lines .= "\t-rm -f " . join(' ', @final_names) . "\n" if (@final_names);
754 appendLines($lines);
755 $target_adds{"$cleantarget-am"} .= "$cleantarget-final ";
757 foreach $finalfile (@final_names) {
758 $finalfile =~ s/\.[^.]*$/.P/;
759 $dep_finals .= " \$(DEPDIR)/$finalfile";
764 #-----------------------------------------------------------------------------
766 sub tag_COMPILE_FIRST()
768 foreach $program (@programs) {
769 my $lookup = "$program" . '_COMPILE_FIRST\s*=\s*(.*)';
770 if ($MakefileData =~ m/\n$lookup\n/) {
771 my @compilefirst = split(/[\s\034]+/, $1);
772 my @progsources = split(/[\s\034]+/, $sources{$program});
773 my %donesources = ();
774 $handling = "";
775 foreach $source (@progsources) {
776 my @deps = ();
777 my $sdeps = "";
778 if (-f $source) {
779 $sdeps = "\$(srcdir)/$source";
780 } else {
781 $sdeps = "$source";
783 foreach $depend (@compilefirst) {
784 next if ($source eq $depend);
785 # avoid cyclic dependencies
786 next if defined($donesources{$depend});
787 push @deps, $depend;
789 $handling .= "$sdeps: " . join(' ', @deps) . "\n" if (@deps);
790 $donesources{$source} = 1;
792 appendLines($handling) if (length($handling));
797 #-----------------------------------------------------------------------------
800 # Organises the list of headers that we'll use to produce moc files
801 # from.
802 sub tag_METASOURCES ()
804 local @newObs = (); # here we add to create object files
805 local @deped = (); # here we add to create moc files
806 local $mocExt = ".moc";
807 local %mocFiles = ();
809 my $line = "";
810 my $postEqual = "";
812 my $lookup;
813 my $found = "";
815 if ($metasourceTags > 1) {
816 $lookup = $program . '_METASOURCES\s*=\s*(.*)';
817 return 1 if ($MakefileData !~ /\n($lookup)\n/);
818 $found = $1;
819 } else {
820 $lookup = $program . '_METASOURCES\s*=\s*(.*)';
821 if ($MakefileData !~ /\n($lookup)\n/) {
822 $lookup = 'METASOURCES\s*=\s*(.*)';
823 return 1 if ($MakefileData !~ /\n($lookup)\n/o);
824 $found = $1;
825 $metasourceTags = 0; # we can use the general target only once
826 } else {
827 $found = $1;
830 print STDOUT "METASOURCE processing <$found>)\n" if ($verbose);
832 $postEqual = $found;
833 $postEqual =~ s/[^=]*=//;
835 removeLine ($lookup, $found);
837 # Always find the header files that could be used to "moc"
838 return 1 if (findMocCandidates ());
840 if ($postEqual =~ /AUTO\s*(\S*)|USE_AUTOMOC\s*(\S*)/)
842 print STDERR "$printname: the argument for AUTO|USE_AUTOMOC is obsolete" if ($+);
843 $mocExt = ".moc.$cxxsuffix";
844 $haveAutomocTag = 1;
846 else
848 # Not automoc so read the list of files supplied which
849 # should be .moc files.
851 $postEqual =~ tr/\034/ /;
853 # prune out extra headers - This also checks to make sure that
854 # the list is valid.
855 pruneMocCandidates ($postEqual);
858 checkMocCandidates ();
860 if (@newObs) {
861 my $ext = ($program =~ /_la$/) ? ".moc.lo " : ".moc.o ";
862 $realObjs{$program} .= "\034" . join ($ext, @newObs) . $ext;
863 $depedmocs{$program} = join (".moc.$cxxsuffix " , @newObs) . ".moc.$cxxsuffix";
864 foreach $file (@newObs) {
865 $dep_files .= " \$(DEPDIR)/$file.moc.P" if($dep_files !~/$file.moc.P/);
868 if (@deped) {
869 $depedmocs{$program} .= " ";
870 $depedmocs{$program} .= join('.moc ', @deped) . ".moc";
871 $depedmocs{$program} .= " ";
873 addMocRules ();
874 @globalmocs{keys %mocFiles}=values %mocFiles;
877 #-----------------------------------------------------------------------------
879 # Returns 0 if the line was processed - 1 otherwise.
880 # Errors are logged in the global $errorflags
881 sub tag_AUTOMAKE ()
883 my $lookup = '.*cd \$\(top_srcdir\)\s+&&[\s\034]+\$\(AUTOMAKE\)(.*)';
884 return 1 if ($MakefileData !~ /\n($lookup)\n/);
885 print STDOUT "AUTOMAKE processing <$1>\n" if ($verbose);
887 my $newLine = $1."\n\tcd \$(top_srcdir) && perl $thisProg $printname";
888 substituteLine ($lookup, $newLine);
889 $automkCall = $1;
890 return 0;
893 #-----------------------------------------------------------------------------
895 sub handle_TOPLEVEL()
897 my $pofiles = "";
898 my @restfiles = ();
899 opendir (THISDIR, ".");
900 foreach $entry (readdir(THISDIR)) {
901 next if (-d $entry);
903 next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/ || $entry =~ /.gmo$/);
905 if ($entry =~ /\.po$/) {
906 next;
908 push(@restfiles, $entry);
910 closedir (THISDIR);
912 if (@restfiles) {
913 $target_adds{"install-data-am"} .= "install-nls-files ";
914 $lines = "install-nls-files:\n";
915 $lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$kdelang\n";
916 for $file (@restfiles) {
917 $lines .= "\t\$(INSTALL_DATA) \$\(srcdir\)/$file \$(DESTDIR)\$(kde_locale)/$kdelang/$file\n";
919 $target_adds{"uninstall"} .= "uninstall-nls-files ";
920 $lines .= "uninstall-nls-files:\n";
921 for $file (@restfiles) {
922 $lines .= "\t-rm -f \$(DESTDIR)\$(kde_locale)/$kdelang/$file\n";
924 appendLines($lines);
927 return 0;
930 #-----------------------------------------------------------------------------
932 sub tag_SUBDIRS ()
934 if ($MakefileData !~ /\nSUBDIRS\s*=\s*\$\(AUTODIRS\)\s*\n/) {
935 return 1;
938 my $subdirs = ".";
940 opendir (THISDIR, ".");
941 foreach $entry (readdir(THISDIR)) {
942 next if ($entry eq "CVS" || $entry =~ /^\./);
943 if (-d $entry && -f $entry . "/Makefile.am") {
944 $subdirs .= " $entry";
945 next;
948 closedir (THISDIR);
950 my $lines = "SUBDIRS =$subdirs\n";
951 substituteLine('SUBDIRS\s*=.*', $lines);
952 return 0;
955 sub tag_IDLFILES ()
957 my @psources = split(/[\034\s]+/, $sources{$program});
958 my $dep_lines = "";
959 my @cppFiles = ();
961 foreach $source (@psources) {
963 my $skel = ($source =~ m/\.skel$/);
964 my $stub = ($source =~ m/\.stub$/);
965 my $signals = ($source =~ m/\.signals$/);
967 if ($stub || $skel || $signals) {
969 my $qs = quotemeta($source);
970 $sources{$program} =~ s/$qs//;
971 $sources_changed{$program} = 1;
973 print STDOUT "adding IDL file $source\n" if ($verbose);
975 $source =~ s/\.(stub|skel|signals)$//;
977 my $sourcename;
979 if ($skel) {
980 $sourcename = "$source\_skel";
981 } elsif ($stub) {
982 $sourcename = "$source\_stub";
983 } else {
984 $sourcename = "$source\_signals";
987 my $sourcedir = '';
988 if (-f "$makefileDir/$source.h") {
989 $sourcedir = '$(srcdir)/';
990 } else {
991 if ($MakefileData =~ /\n$source\_DIR\s*=\s*(\S+)\n/) {
992 $sourcedir = $1;
993 $sourcedir .= "/" if ($sourcedir !~ /\/$/);
997 if ($allidls !~ /$source\_kidl/) {
999 $dep_lines .= "$source.kidl: $sourcedir$source.h \$(DCOPIDL_DEPENDENCIES)\n";
1000 $dep_lines .= "\t\$(DCOPIDL) $sourcedir$source.h > $source.kidl || ( rm -f $source.kidl ; /bin/false )\n";
1002 $allidls .= $source . "_kidl ";
1005 if ($allidls !~ /$sourcename/) {
1007 $dep_lines_tmp = "";
1009 if ($skel) {
1010 $dep_lines .= "$sourcename.$cxxsuffix: $source.kidl\n";
1011 $dep_lines .= "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-signals --no-stub $source.kidl\n";
1012 } elsif ($stub) {
1013 $dep_lines_tmp = "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-signals --no-skel $source.kidl\n";
1014 } else { # signals
1015 $dep_lines_tmp = "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-stub --no-skel $source.kidl\n";
1018 if ($stub || $signals) {
1019 $target_adds{"$sourcename.$cxxsuffix"} .= "$sourcename.h ";
1020 $dep_lines .= "$sourcename.h: $source.kidl\n";
1021 $dep_lines .= $dep_lines_tmp;
1024 $allidls .= $sourcename . " ";
1027 $idlfiles{$program} .= $sourcename . " ";
1029 if ($program =~ /_la$/) {
1030 $realObjs{$program} .= " $sourcename.lo";
1031 } else {
1032 $realObjs{$program} .= " $sourcename.\$(OBJEXT)";
1034 $sources{$program} .= " $sourcename.$cxxsuffix";
1035 $sources_changed{$program} = 1;
1036 $important{$program} .= "$sourcename.h " if (!$skel);
1037 $idl_output .= "\\\n\t$sourcename.$cxxsuffix $sourcename.h $source.kidl ";
1038 push(@cleanfiles, "$sourcename.$cxxsuffix");
1039 push(@cleanfiles, "$sourcename.h");
1040 push(@cleanfiles, "$sourcename.kidl");
1041 $dep_files .= " \$(DEPDIR)/$sourcename.P" if ($dep_files !~/$sourcename.P/);
1044 if ($dep_lines) {
1045 appendLines($dep_lines);
1048 if (0) {
1049 my $lookup = "($program)";
1050 $lookup .= '(|\$\(EXEEXT\))';
1051 $lookup =~ s/\_/./g;
1052 $lookup .= ":(.*..$program\_OBJECTS..*)";
1053 # $lookup = quotemeta($lookup);
1054 if ($MakefileData =~ /\n$lookup\n/) {
1056 my $line = "$1$2: ";
1057 foreach $file (split(' ', $idlfiles{$program})) {
1058 $line .= "$file.$cxxsuffix ";
1060 $line .= $3;
1061 substituteLine($lookup, $line);
1062 } else {
1063 print STDERR "no built dependency found $lookup\n";
1068 sub tag_UIFILES ()
1070 my @psources = split(/[\034\s]+/, $sources{$program});
1071 my $dep_lines = "";
1072 my @depFiles = ();
1074 foreach $source (@psources) {
1076 if ($source =~ m/\.ui$/) {
1078 print STDERR "adding UI file $source\n" if ($verbose);
1080 my $qs = quotemeta($source);
1081 $sources{$program} =~ s/$qs//;
1082 $sources_changed{$program} = 1;
1084 $source =~ s/\.ui$//;
1086 my $sourcedir = '';
1087 if (-f "$makefileDir/$source.ui") {
1088 $sourcedir = '$(srcdir)/';
1091 if (!$uiFiles{$source}) {
1093 $dep_lines .= "$source.$cxxsuffix: $sourcedir$source.ui $source.h $source.moc\n";
1094 $dep_lines .= "\trm -f $source.$cxxsuffix\n";
1095 if (!$kdeopts{"qtonly"}) {
1096 $dep_lines .= "\techo '#include <klocale.h>' > $source.$cxxsuffix\n";
1097 my ($mangled_source) = $source;
1098 $mangled_source =~ s/[^A-Za-z0-9]/_/g; # get rid of garbage
1099 $dep_lines .= "\t\$(UIC) -tr \${UIC_TR} -i $source.h $sourcedir$source.ui | sed -e \"s,\${UIC_TR}( \\\"\\\" ),QString::null,g\" | sed -e \"s,\${UIC_TR}( \\\"\\\"\\, \\\"\\\" ),QString::null,g\" | sed -e \"s,image\\([0-9][0-9]*\\)_data,img\\1_" . $mangled_source . ",g\" >> $source.$cxxsuffix || rm -f $source.$cxxsuffix\n";
1100 } else {
1101 $dep_lines .= "\t\$(UIC) -i $source.h $sourcedir$source.ui > $source.$cxxsuffix || rm -f $source.$cxxsuffix\n";
1103 $dep_lines .= "\techo '#include \"$source.moc\"' >> $source.$cxxsuffix\n\n";
1104 $dep_lines .= "$source.h: $sourcedir$source.ui\n";
1105 $dep_lines .= "\t\$(UIC) -o $source.h $sourcedir$source.ui\n\n";
1106 $dep_lines .= "$source.moc: $source.h\n";
1107 $dep_lines .= "\t\$(MOC) $source.h -o $source.moc\n";
1109 $uiFiles{$source} = 1;
1110 $depedmocs{$program} .= " $source.moc";
1111 $globalmocs{$source} = "\035$source.h\035$source.cpp";
1114 if ($program =~ /_la$/) {
1115 $realObjs{$program} .= " $source.lo";
1116 } else {
1117 $realObjs{$program} .= " $source.\$(OBJEXT)";
1119 $sources{$program} .= " $source.$cxxsuffix";
1120 $sources_changed{$program} = 1;
1121 $important{$program} .= "$source.h ";
1122 $ui_output .= "\\\n\t$source.$cxxsuffix $source.h $source.moc ";
1123 push(@cleanfiles, "$source.$cxxsuffix");
1124 push(@cleanfiles, "source.h");
1125 push(@cleanfiles, "$source.moc");
1126 $dep_files .= " \$(DEPDIR)/$source.P" if($dep_files !~/$source.P/ );
1129 if ($dep_lines) {
1130 appendLines($dep_lines);
1134 sub tag_ICON()
1136 my $lookup = '([^\s]*)_ICON\s*=\s*([^\n]*)';
1137 my $install = "";
1138 my $uninstall = "";
1140 while ($MakefileData =~ /\n$lookup/og) {
1141 my $destdir;
1142 if ($1 eq "KDE") {
1143 $destdir = "kde_icondir";
1144 } else {
1145 $destdir = $1 . "dir";
1147 my $iconauto = ($2 =~ /AUTO\s*$/);
1148 my @appnames = ();
1149 if ( ! $iconauto ) {
1150 my @_appnames = split(/[\034\s]+/, $2);
1151 print STDOUT "KDE_ICON processing <@_appnames>\n" if ($verbose);
1152 foreach $appname (@_appnames) {
1153 push(@appnames, quotemeta($appname));
1155 } else {
1156 print STDOUT "KDE_ICON processing <AUTO>\n" if ($verbose);
1159 my @files = ();
1160 opendir (THISDIR, ".");
1161 foreach $entry (readdir(THISDIR)) {
1162 next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
1163 next if (! -f $entry);
1164 if ( $iconauto )
1166 push(@files, $entry)
1167 if ($entry =~ /\.xpm/ || $entry =~ /\.png/ || $entry =~ /\.mng/);
1168 } else {
1169 foreach $appname (@appnames) {
1170 push(@files, $entry)
1171 if ($entry =~ /-$appname\.xpm/ || $entry =~ /-$appname\.png/ || $entry =~ /-$appname\.mng/);
1175 closedir (THISDIR);
1177 my %directories = ();
1179 foreach $file (@files) {
1180 my $newfile = $file;
1181 my $prefix = $file;
1182 $prefix =~ s/\.(png|xpm|mng)$//;
1183 my $appname = $prefix;
1184 $appname =~ s/^[^-]+-// if ($appname =~ /-/) ;
1185 $appname =~ s/^[^-]+-// if ($appname =~ /-/) ;
1186 $appname = quotemeta($appname);
1187 $prefix =~ s/$appname$//;
1188 $prefix =~ s/-$//;
1190 $prefix = 'lo16-app' if ($prefix eq 'mini');
1191 $prefix = 'lo32-app' if ($prefix eq 'lo');
1192 $prefix = 'hi48-app' if ($prefix eq 'large');
1193 $prefix .= '-app' if ($prefix =~ m/^...$/);
1195 my $type = $prefix;
1196 $type =~ s/^.*-([^-]+)$/$1/;
1197 $prefix =~ s/^(.*)-[^-]+$/$1/;
1199 my %type_hash =
1201 'action' => 'actions',
1202 'app' => 'apps',
1203 'device' => 'devices',
1204 'filesys' => 'filesystems',
1205 'mime' => 'mimetypes'
1208 if (! defined $type_hash{$type} ) {
1209 print STDERR "unknown icon type $type in $printname ($file)\n";
1210 next;
1213 my %dir_hash =
1215 'los' => 'locolor/16x16',
1216 'lom' => 'locolor/32x32',
1217 'him' => 'hicolor/32x32',
1218 'hil' => 'hicolor/48x48',
1219 'lo16' => 'locolor/16x16',
1220 'lo22' => 'locolor/22x22',
1221 'lo32' => 'locolor/32x32',
1222 'hi16' => 'hicolor/16x16',
1223 'hi22' => 'hicolor/22x22',
1224 'hi32' => 'hicolor/32x32',
1225 'hi48' => 'hicolor/48x48',
1226 'hi64' => 'hicolor/64x64',
1227 'hisc' => 'hicolor/scalable'
1230 $newfile =~ s@.*-($appname\.(png|xpm|mng?))@$1@;
1232 if (! defined $dir_hash{$prefix}) {
1233 print STDERR "unknown icon prefix $prefix in $printname\n";
1234 next;
1237 my $dir = $dir_hash{$prefix} . "/" . $type_hash{$type};
1238 if ($newfile =~ /-[^\.]/) {
1239 my $tmp = $newfile;
1240 $tmp =~ s/^([^-]+)-.*$/$1/;
1241 $dir = $dir . "/" . $tmp;
1242 $newfile =~ s/^[^-]+-//;
1245 if (!defined $directories{$dir}) {
1246 $install .= "\t\$(mkinstalldirs) \$(DESTDIR)\$($destdir)/$dir\n";
1247 $directories{$dir} = 1;
1250 $install .= "\t\$(INSTALL_DATA) \$(srcdir)/$file \$(DESTDIR)\$($destdir)/$dir/$newfile\n";
1251 $uninstall .= "\t-rm -f \$(DESTDIR)\$($destdir)/$dir/$newfile\n";
1256 if (length($install)) {
1257 $target_adds{"install-data-am"} .= "install-kde-icons ";
1258 $target_adds{"uninstall-am"} .= "uninstall-kde-icons ";
1259 appendLines("install-kde-icons:\n" . $install . "\nuninstall-kde-icons:\n" . $uninstall);
1263 sub handle_POFILES($$)
1265 my @pofiles = split(/[\034\s]+/, $_[0]);
1266 my $lang = $_[1];
1268 # Build rules for creating the gmo files
1269 my $tmp = "";
1270 my $allgmofiles = "";
1271 my $pofileLine = "POFILES =";
1272 foreach $pofile (@pofiles)
1274 $pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1275 $tmp .= "$1.gmo: $pofile\n";
1276 $tmp .= "\trm -f $1.gmo; \$(GMSGFMT) -o $1.gmo \$(srcdir)/$pofile\n";
1277 $tmp .= "\ttest ! -f $1.gmo || touch $1.gmo\n";
1278 $allgmofiles .= " $1.gmo";
1279 $pofileLine .= " $1.po";
1281 appendLines ($tmp);
1282 my $lookup = 'POFILES\s*=([^\n]*)';
1283 if ($MakefileData !~ /\n$lookup/o) {
1284 appendLines("$pofileLine\nGMOFILES =$allgmofiles");
1285 } else {
1286 substituteLine ($lookup, "$pofileLine\nGMOFILES =$allgmofiles");
1289 if ($allgmofiles) {
1291 # Add the "clean" rule so that the maintainer-clean does something
1292 appendLines ("clean-nls:\n\t-rm -f $allgmofiles\n");
1294 $target_adds{"maintainer-clean"} .= "clean-nls ";
1296 $lookup = 'DISTFILES\s*=\s*(.*)';
1297 if ($MakefileData =~ /\n$lookup\n/o) {
1298 $tmp = "DISTFILES = \$(GMOFILES) \$(POFILES) $1";
1299 substituteLine ($lookup, $tmp);
1303 $target_adds{"install-data-am"} .= "install-nls ";
1305 $tmp = "install-nls:\n";
1306 if ($lang) {
1307 $tmp .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES\n";
1309 $tmp .= "\t\@for base in ";
1310 foreach $pofile (@pofiles)
1312 $pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1313 $tmp .= "$1 ";
1316 $tmp .= "; do \\\n";
1317 if ($lang) {
1318 $tmp .= "\t echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n";
1319 $tmp .= "\t test ! -f \$\$base.gmo || \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n"
1320 } else {
1321 $tmp .= "\t echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
1322 $tmp .= "\t \$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES ; \\\n";
1323 $tmp .= "\t test ! -f \$\$base.gmo || \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
1325 $tmp .= "\tdone\n\n";
1326 appendLines ($tmp);
1328 $target_adds{"uninstall"} .= "uninstall-nls ";
1330 $tmp = "uninstall-nls:\n";
1331 foreach $pofile (@pofiles)
1333 $pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1334 if ($lang) {
1335 $tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/$1.mo\n";
1336 } else {
1337 $tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$1/LC_MESSAGES/\$(PACKAGE).mo\n";
1340 appendLines($tmp);
1342 $target_adds{"all"} .= "all-nls ";
1344 $tmp = "all-nls: \$(GMOFILES)\n";
1346 appendLines($tmp);
1348 $target_adds{"distdir"} .= "distdir-nls ";
1350 $tmp = "distdir-nls:\$(GMOFILES)\n";
1351 $tmp .= "\tfor file in \$(POFILES); do \\\n";
1352 $tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n";
1353 $tmp .= "\tdone\n";
1354 $tmp .= "\tfor file in \$(GMOFILES); do \\\n";
1355 $tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n";
1356 $tmp .= "\tdone\n";
1358 appendLines ($tmp);
1360 if (!$lang) {
1361 appendLines("merge:\n\t\$(MAKE) -f \$(top_srcdir)/admin/Makefile.common package-merge POFILES=\"\${POFILES}\" PACKAGE=\${PACKAGE}\n\n");
1366 #-----------------------------------------------------------------------------
1368 # Returns 0 if the line was processed - 1 otherwise.
1369 # Errors are logged in the global $errorflags
1370 sub tag_POFILES ()
1372 my $lookup = 'POFILES\s*=([^\n]*)';
1373 return 1 if ($MakefileData !~ /\n$lookup/o);
1374 print STDOUT "POFILES processing <$1>\n" if ($verbose);
1376 my $tmp = $1;
1378 # make sure these are all gone.
1379 if ($MakefileData =~ /\n\.po\.gmo:\n/)
1381 print STDERR "Warning: Found old .po.gmo rules in $printname. New po rules not added\n";
1382 return 1;
1385 # Either find the pofiles in the directory (AUTO) or use
1386 # only the specified po files.
1387 my $pofiles = "";
1388 if ($tmp =~ /^\s*AUTO\s*$/)
1390 opendir (THISDIR, ".");
1391 $pofiles = join(" ", grep(/\.po$/, readdir(THISDIR)));
1392 closedir (THISDIR);
1393 print STDOUT "pofiles found = $pofiles\n" if ($verbose);
1394 if (-f "charset" && -f "kdelibs.po") {
1395 handle_TOPLEVEL();
1398 else
1400 $tmp =~ s/\034/ /g;
1401 $pofiles = $tmp;
1403 return 1 if (!$pofiles); # Nothing to do
1405 handle_POFILES($pofiles, $kdelang);
1407 return 0;
1410 sub helper_LOCALINSTALL($)
1412 my $lookup = "\n" . $_[0] . ":";
1413 if ($MakefileData =~ /($lookup)/) {
1415 my $install = $MakefileData;
1416 $install =~ s/\n/\035/g;
1417 $install =~ s/.*\035$_[0]:[^\035]*\035//;
1418 my $emptyline = 0;
1419 while (! $emptyline) {
1420 if ($install =~ /([^\035]*)\035(.*)/) {
1421 local $line = $1;
1422 $install = $2;
1423 if ($line !~ /^\s*$/ && $line !~ /^(\@.*\@)*\t/) {
1424 $emptyline = 1;
1425 } else {
1426 replaceDestDir($line);
1428 } else {
1429 $emptyline = 1;
1436 sub tag_LOCALINSTALL ()
1438 helper_LOCALINSTALL('install-exec-local');
1439 helper_LOCALINSTALL('install-data-local');
1440 helper_LOCALINSTALL('uninstall-local');
1442 return 0;
1445 sub replaceDestDir($) {
1446 local $line = $_[0];
1448 if ( $line =~ /^\s*(\@.*\@)*\s*\$\(mkinstalldirs\)/
1449 || $line =~ /^\s*(\@.*\@)*\s*\$\(INSTALL\S*\)/
1450 || $line =~ /^\s*(\@.*\@)*\s*(-?rm.*) \S*$/)
1452 $line =~ s/^(.*) ([^\s]+)\s*$/$1 \$(DESTDIR)$2/ if ($line !~ /\$\(DESTDIR\)/);
1455 if ($line ne $_[0]) {
1456 $_[0] = quotemeta $_[0];
1457 substituteLine($_[0], $line);
1461 #---------------------------------------------------------------------------
1462 sub tag_CLOSURE () {
1463 return if ($program !~ /_la$/);
1465 my $lookup = quotemeta($realname{$program}) . ":.*?\n\t.*?\\((.*?)\\) .*\n";
1466 $MakefileData =~ m/$lookup/;
1467 return if ($1 !~ /CXXLINK/);
1469 if ($MakefileData !~ /\n$program\_LDFLAGS\s*=.*-no-undefined/ &&
1470 $MakefileData !~ /\n$program\_LDFLAGS\s*=.*KDE_PLUGIN/ ) {
1471 print STDERR "Report: $program contains undefined in $printname\n" if ($program =~ /^lib/ && $dryrun);
1472 return;
1474 my $closure = $realname{$program} . ".closure";
1475 my $lines = "$closure: \$($program\_OBJECTS) \$($program\_DEPENDENCIES)\n";
1476 $lines .= "\t\@echo \"int main() {return 0;}\" > $program\_closure.$cxxsuffix\n";
1477 $lines .= "\t\@\$\(LTCXXCOMPILE\) -c $program\_closure.$cxxsuffix\n";
1478 $lines .= "\t\$\(CXXLINK\) $program\_closure.lo \$($program\_LDFLAGS) \$($program\_OBJECTS) \$($program\_LIBADD) \$(LIBS)\n";
1479 $lines .= "\t\@rm -f $program\_closure.* $closure\n";
1480 $lines .= "\t\@echo \"timestamp\" > $closure\n";
1481 $lines .= "\n";
1482 appendLines($lines);
1483 $lookup = $realname{$program} . ": (.*)";
1484 if ($MakefileData =~ /\n$lookup\n/) {
1485 $lines = "\@KDE_USE_CLOSURE_TRUE@". $realname{$program} . ": $closure $1";
1486 $lines .= "\n\@KDE_USE_CLOSURE_FALSE@" . $realname{$program} . ": $1";
1487 substituteLine($lookup, $lines);
1489 $closure_output .= " $closure";
1492 sub tag_DIST () {
1493 my %foundfiles = ();
1494 opendir (THISDIR, ".");
1495 foreach $entry (readdir(THISDIR)) {
1496 next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile$$/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
1497 next if (! -f $entry);
1498 next if ($entry =~ /\.moc/ || $entry =~ /\.lo$/ || $entry =~ /\.la$/ || $entry =~ /\.o/);
1499 next if ($entry =~ /.+meta_unload.$cppExt$/ || $entry =~ /\.all_$cppExt\.$cppExt$/);
1500 $foundfiles{$entry} = 1;
1502 closedir (THISDIR);
1504 # doing this for MAINTAINERCLEANFILES would be wrong
1505 my @marks = ("EXTRA_DIST", "DIST_COMMON", '\S*_SOURCES', '\S*_HEADERS', 'CLEANFILES', 'DISTCLEANFILES', '\S*_OBJECTS');
1506 foreach $mark (@marks) {
1507 while ($MakefileData =~ /\n($mark)\s*=\s*([^\n]*)/g) {
1508 foreach $file (split('[\034\s]', $2)) {
1509 $file =~ s/\.\///;
1510 $foundfiles{$file} = 0 if (defined $foundfiles{$file});
1514 my @files = ("Makefile", "config.cache", "config.log", "stamp-h",
1515 "stamp-h1", "stamp-h1", "config.h", "Makefile",
1516 "config.status", "config.h", "libtool", "core" );
1517 foreach $file (@files) {
1518 $foundfiles{$file} = 0 if (defined $foundfiles{$file});
1521 # don't distribute programs and libraries
1522 $foundfiles{$realname{$_}} = 0 foreach @programs;
1524 my $KDE_DIST = "";
1525 foreach $file (keys %foundfiles) {
1526 if ($foundfiles{$file} == 1) {
1527 $KDE_DIST .= "$file ";
1530 if ($KDE_DIST) {
1531 print "KDE_DIST $printname $KDE_DIST\n" if ($verbose);
1533 my $lookup = "DISTFILES *=(.*)";
1534 if ($MakefileData =~ /\n$lookup\n/o) {
1535 substituteLine($lookup, "KDE_DIST=$KDE_DIST\n\nDISTFILES=$1 \$(KDE_DIST)\n");
1540 #-----------------------------------------------------------------------------
1541 # Returns 0 if the line was processed - 1 otherwise.
1542 # Errors are logged in the global $errorflags
1543 sub tag_DOCFILES ()
1545 # if ($MakefileData =~ /\nSUBDIRS\s*=/) { # subdirs
1546 # $MakefileData =~ /\n(.*-recursive:\s*)\n/;
1547 # my $orig_rules = $1;
1548 # my $rules = $orig_rules;
1549 # $rules =~ s/:\s*$//;
1550 # substituteLine($orig_rules, "$rules docs-recursive:");
1551 # appendLines("docs: docs-recursive docs-am\n");
1552 # } else {
1553 # appendLines("docs: docs-am\n");
1555 $target_adds{"all"} .= "docs-am ";
1557 my $lookup = 'KDE_DOCS\s*=\s*([^\n]*)';
1558 goto nodocs if ($MakefileData !~ /\n$lookup/o);
1559 print STDOUT "KDE_DOCS processing <$1>\n" if ($verbose);
1561 my $tmp = $1;
1563 # Either find the files in the directory (AUTO) or use
1564 # only the specified po files.
1565 my $files = "";
1566 my $appname = $tmp;
1567 $appname =~ s/^(\S*)\s*.*$/$1/;
1568 if ($appname =~ /AUTO/) {
1569 $appname = basename($makefileDir);
1570 if ("$appname" eq "en") {
1571 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";
1572 exit(1);
1576 if ($tmp !~ / - /)
1578 opendir (THISDIR, ".");
1579 foreach $entry (readdir(THISDIR)) {
1580 next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
1581 next if (! -f $entry);
1582 $files .= "$entry ";
1584 closedir (THISDIR);
1585 print STDOUT "docfiles found = $files\n" if ($verbose);
1587 else
1589 $tmp =~ s/\034/ /g;
1590 $tmp =~ s/^\S*\s*-\s*//;
1591 $files = $tmp;
1593 goto nodocs if (!$files); # Nothing to do
1595 if ($files =~ /(^| )index\.docbook($| )/) {
1597 my $lines = "";
1598 my $lookup = 'MEINPROC\s*=';
1599 if ($MakefileData !~ /\n($lookup)/) {
1600 $lines = "MEINPROC=/\$(kde_bindir)/meinproc\n";
1602 $lookup = 'KDE_XSL_STYLESHEET\s*=';
1603 if ($MakefileData !~ /\n($lookup)/) {
1604 $lines .= "KDE_XSL_STYLESHEET=/\$(kde_datadir)/ksgmltools2/customization/kde-chunk.xsl\n";
1606 $lookup = '\nindex.cache.bz2:';
1607 if ($MakefileData !~ /\n($lookup)/) {
1608 $lines .= "index.cache.bz2: \$(srcdir)/index.docbook \$(KDE_XSL_STYLESHEET) $files\n";
1609 $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";
1610 $lines .= "\n";
1613 $lines .= "docs-am: index.cache.bz2\n";
1614 $lines .= "\n";
1615 $lines .= "install-docs: docs-am install-nls\n";
1616 $lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n";
1617 $lines .= "\t\@if test -f index.cache.bz2; then \\\n";
1618 $lines .= "\techo \$(INSTALL_DATA) index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n";
1619 $lines .= "\t\$(INSTALL_DATA) index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n";
1620 $lines .= "\tfi\n";
1621 $lines .= "\t-rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n";
1622 $lines .= "\t\$(LN_S) \$(kde_libs_htmldir)/$kdelang/common \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n";
1624 $lines .= "\n";
1625 $lines .= "uninstall-docs:\n";
1626 $lines .= "\t-rm -rf \$(kde_htmldir)/$kdelang/$appname\n";
1627 $lines .= "\n";
1628 $lines .= "clean-docs:\n";
1629 $lines .= "\t-rm -f index.cache.bz2\n";
1630 $lines .= "\n";
1631 $target_adds{"install-data-am"} .= "install-docs ";
1632 $target_adds{"uninstall"} .= "uninstall-docs ";
1633 $target_adds{"clean-am"} .= "clean-docs ";
1634 appendLines ($lines);
1635 } else {
1636 appendLines("docs-am: $files\n");
1639 $target_adds{"install-data-am"} .= "install-nls";
1640 $target_adds{"uninstall"} .= "uninstall-nls ";
1642 $tmp = "install-nls:\n";
1643 $tmp .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n";
1644 $tmp .= "\t\@for base in $files; do \\\n";
1645 $tmp .= "\t echo \$(INSTALL_DATA) \$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1646 $tmp .= "\t \$(INSTALL_DATA) \$(srcdir)/\$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1647 $tmp .= "\tdone\n";
1648 if ($appname eq 'common') {
1649 $tmp .= "\t\@echo \"merging common and language specific dir\" ;\\\n";
1650 $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";
1651 $tmp .= "\t\@com_files=`cd \$(kde_htmldir)/en/common && echo *` ;\\\n";
1652 $tmp .= "\tcd \$(DESTDIR)\$(kde_htmldir)/$kdelang/common ;\\\n";
1653 $tmp .= "\tif test -n \"\$\$com_files\"; then for p in \$\$com_files ; do \\\n";
1654 $tmp .= "\t case \" $files \" in \\\n";
1655 $tmp .= "\t *\" \$\$p \"*) ;; \\\n";
1656 $tmp .= "\t *) test ! -e \$\$p && echo \$(LN_S) ../../en/common/\$\$p \$(DESTDIR)\$(kde_htmldir)/$kdelang/common/\$\$p && \$(LN_S) ../../en/common/\$\$p \$\$p ;; \\\n";
1657 $tmp .= "\t esac ; \\\n";
1658 $tmp .= "\tdone ; fi ; true\n";
1660 $tmp .= "\n";
1661 $tmp .= "uninstall-nls:\n";
1662 $tmp .= "\tfor base in $files; do \\\n";
1663 $tmp .= "\t rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1664 $tmp .= "\tdone\n\n";
1665 appendLines ($tmp);
1667 $target_adds{"distdir"} .= "distdir-nls ";
1669 $tmp = "distdir-nls:\n";
1670 $tmp .= "\tfor file in $files; do \\\n";
1671 $tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n";
1672 $tmp .= "\tdone\n";
1674 appendLines ($tmp);
1676 return 0;
1678 nodocs:
1679 appendLines("docs-am:\n");
1680 return 1;
1683 #-----------------------------------------------------------------------------
1684 # Find headers in any of the source directories specified previously, that
1685 # are candidates for "moc-ing".
1686 sub findMocCandidates ()
1688 foreach $dir (@headerdirs)
1690 my @list = ();
1691 opendir (SRCDIR, "$dir");
1692 @hFiles = grep { /.+\.$hExt$/o && !/^\./ } readdir(SRCDIR);
1693 closedir SRCDIR;
1694 foreach $hf (@hFiles)
1696 next if ($hf =~ /^\.\#/);
1697 $hf =~ /(.*)\.[^\.]*$/; # Find name minus extension
1698 next if ($uiFiles{$1});
1699 open (HFIN, "$dir/$hf") || die "Could not open $dir/$hf: $!\n";
1700 my $hfsize = 0;
1701 seek(HFIN, 0, 2);
1702 $hfsize = tell(HFIN);
1703 seek(HFIN, 0, 0);
1704 read HFIN, $hfData, $hfsize;
1705 close HFIN;
1706 # push (@list, $hf) if(index($hfData, "Q_OBJECT") >= 0); ### fast but doesn't handle //Q_OBJECT
1707 if ( $hfData =~ /{([^}]*)Q_OBJECT/s ) { ## handle " { friend class blah; Q_OBJECT "
1708 push (@list, $hf) unless $1 =~ m://[^\n]*Q_OBJECT[^\n]*$:s; ## handle "// Q_OBJECT"
1711 # The assoc array of root of headerfile and header filename
1712 foreach $hFile (@list)
1714 $hFile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1715 if ($mocFiles{$1})
1717 print STDERR "Warning: Multiple header files found for $1\n";
1718 next; # Use the first one
1720 $mocFiles{$1} = "$dir\035$hFile"; # Add relative dir
1724 return 0;
1727 #-----------------------------------------------------------------------------
1729 # The programmer has specified a moc list. Prune out the moc candidates
1730 # list that we found based on looking at the header files. This generates
1731 # a warning if the programmer gets the list wrong, but this doesn't have
1732 # to be fatal here.
1733 sub pruneMocCandidates ($)
1735 my %prunedMoc = ();
1736 local @mocList = split(' ', $_[0]);
1738 foreach $mocname (@mocList)
1740 $mocname =~ s/\.moc$//;
1741 if ($mocFiles{$mocname})
1743 $prunedMoc{$mocname} = $mocFiles{$mocname};
1745 else
1747 my $print = $makefileDir;
1748 $print =~ s/^\Q$topdir\E\\//;
1749 # They specified a moc file but we can't find a header that
1750 # will generate this moc file. That's possible fatal!
1751 print STDERR "Warning: No moc-able header file for $print/$mocname\n";
1755 undef %mocFiles;
1756 %mocFiles = %prunedMoc;
1759 #-----------------------------------------------------------------------------
1761 # Finds the cpp files (If they exist).
1762 # The cpp files get appended to the header file separated by \035
1763 sub checkMocCandidates ()
1765 my @cppFiles;
1766 my $cpp2moc; # which c++ file includes which .moc files
1767 my $moc2cpp; # which moc file is included by which c++ files
1769 return unless (keys %mocFiles);
1770 opendir(THISDIR, ".") || return;
1771 @cppFiles = grep { /.+\.$cppExt$/o && !/.+\.moc\.$cppExt$/o
1772 && !/.+\.all_$cppExt\.$cppExt$/o
1773 && !/^\./ } readdir(THISDIR);
1774 closedir THISDIR;
1775 return unless (@cppFiles);
1776 my $files = join (" ", @cppFiles);
1777 $cpp2moc = {};
1778 $moc2cpp = {};
1779 foreach $cxxf (@cppFiles)
1781 open (CXXFIN, $cxxf) || die "Could not open $cxxf: $!\n";
1782 seek(CXXFIN, 0, 2);
1783 my $cxxfsize = tell(CXXFIN);
1784 seek(CXXFIN, 0, 0);
1785 read CXXFIN, $cxxfData, $cxxfsize;
1786 close CXXFIN;
1787 while(($cxxfData =~ m/^[ \t]*\#include\s*[<\"](.*\.moc)[>\"]/gm)) {
1788 $cpp2moc->{$cxxf}->{$1} = 1;
1789 $moc2cpp->{$1}->{$cxxf} = 1;
1792 foreach my $mocFile (keys (%mocFiles))
1794 @cppFiles = keys %{$moc2cpp->{"$mocFile.moc"}};
1795 if (@cppFiles == 1) {
1796 $mocFiles{$mocFile} .= "\035" . $cppFiles[0];
1797 push(@deped, $mocFile);
1798 } elsif (@cppFiles == 0) {
1799 push (@newObs, $mocFile); # Produce new object file
1800 next if ($haveAutomocTag); # This is expected...
1801 # But this is an error we can deal with - let them know
1802 print STDERR
1803 "Warning: No c++ file that includes $mocFile.moc\n";
1804 } else {
1805 # We can't decide which file to use, so it's fatal. Although as a
1806 # guess we could use the mocFile.cpp file if it's in the list???
1807 print STDERR
1808 "Error: Multiple c++ files that include $mocFile.moc\n";
1809 print STDERR "\t",join ("\t", @cppFiles),"\n";
1810 $errorflag = 1;
1811 delete $mocFiles{$mocFile};
1812 # Let's continue and see what happens - They have been told!
1817 #-----------------------------------------------------------------------------
1819 # Add the rules for generating moc source from header files
1820 # For Automoc output *.moc.cpp but normally we'll output *.moc
1821 # (We must compile *.moc.cpp separately. *.moc files are included
1822 # in the appropriate *.cpp file by the programmer)
1823 sub addMocRules ()
1825 my $cppFile;
1826 my $hFile;
1828 foreach $mocFile (keys (%mocFiles))
1830 undef $cppFile;
1831 ($dir, $hFile, $cppFile) = split ("\035", $mocFiles{$mocFile}, 3);
1832 $dir =~ s#^\.#\$(srcdir)#;
1833 if (defined ($cppFile))
1835 $target_adds{"\$(srcdir)/$cppFile"} .= "$mocFile.moc ";
1836 appendLines ("$mocFile.moc: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile.moc\n");
1837 $cleanMoc .= " $mocFile.moc";
1839 else
1841 appendLines ("$mocFile$mocExt: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile$mocExt\n");
1842 $cleanMoc .= " $mocFile$mocExt";
1847 sub make_meta_classes ()
1849 return if ($kdeopts{"qtonly"});
1851 my $cppFile;
1852 my $hFile;
1853 my $moc_class_headers = "";
1854 foreach $program (@programs) {
1855 my $mocs = "";
1856 my @progsources = split(/[\s\034]+/, $sources{$program});
1857 my @depmocs = split(' ', $depedmocs{$program});
1858 my %shash = (), %mhash = ();
1859 @shash{@progsources} = 1; # we are only interested in the existence
1860 @mhash{@depmocs} = 1;
1862 print STDOUT "program=$program\n" if ($verbose);
1863 print STDOUT "psources=[".join(' ', keys %shash)."]\n" if ($verbose);
1864 print STDOUT "depmocs=[".join(' ', keys %mhash)."]\n" if ($verbose);
1865 print STDOUT "globalmocs=[".join(' ', keys(%globalmocs))."]\n" if ($verbose);
1866 foreach my $mocFile (keys (%globalmocs))
1868 undef $cppFile;
1869 ($dir, $hFile, $cppFile) = split ("\035", $globalmocs{$mocFile}, 3);
1870 $dir =~ s#^\.#\$(srcdir)#;
1871 if (defined ($cppFile))
1873 $mocs .= " $mocFile.moc" if exists $shash{$cppFile};
1875 else
1877 # Bah. This is the case, if no C++ file includes the .moc
1878 # file. We make a .moc.cpp file for that. Unfortunately this
1879 # is not included in the %sources hash, but rather is mentioned
1880 # in %depedmocs. If the user wants to use AUTO he can't just
1881 # use an unspecific METAINCLUDES. Instead he must use
1882 # program_METAINCLUDES. Anyway, it's not working real nicely.
1883 # E.g. Its not clear what happens if user specifies two
1884 # METAINCLUDES=AUTO in the same Makefile.am.
1885 $mocs .= " $mocFile.moc.$cxxsuffix"
1886 if exists $mhash{$mocFile.".moc.$cxxsuffix"};
1889 if ($mocs) {
1890 print STDOUT "==> mocs=[".$mocs."]\n" if ($verbose);
1891 my $sourcename = $program."_meta_unload";
1892 my $ext = ($program =~ /_la$/) ? ".lo" : ".o";
1893 my $srcfile = $sourcename.".$cxxsuffix";
1894 my $objfile = $sourcename.$ext;
1895 $moc_class_headers .= " $srcfile";
1896 my $appl;
1897 $appl = "$srcfile: $mocs\n";
1898 $appl .= "\t\@echo 'creating $srcfile'\n";
1899 $appl .= "\t\@-rm -f $srcfile\n";
1900 $appl .= "\t\@if test \${kde_qtver} = 2; then \\\n";
1901 $appl .= "\t\techo 'static const char * _metalist_$program\[\] = {' > $srcfile ;\\\n";
1902 $appl .= "\t\tcat $mocs | grep 'char.*className' | ";
1903 $appl .= "sed -e 's/.*[^A-Za-z0-9_:]\\([A-Za-z0-9_:]*\\)::className.*\$\$/\\\"\\1\\\",/' | sort | uniq >> $srcfile ;\\\n";
1904 $appl .= "\t\techo '0};' >> $srcfile ;\\\n";
1905 $appl .= "\t\techo '#include <kunload.h>' >> $srcfile ;\\\n";
1906 $appl .= "\t\techo '_UNLOAD($program)' >> $srcfile ;\\\n";
1907 $appl .= "\telse echo > $srcfile; fi\n";
1908 $appl .= "\n";
1910 $realObjs{$program} .= " \034" . $objfile . " ";
1911 $sources{$program} .= " $srcfile";
1912 $sources_changed{$program} = 1;
1913 $dep_files .= " \$(DEPDIR)/$sourcename.P" if($dep_files !~/$sourcename.P/);
1914 appendLines ($appl);
1916 print STDOUT "\n" if $verbose;
1918 if ($moc_class_headers) {
1919 appendLines ("$cleantarget-moc-classes:\n\t-rm -f $moc_class_headers\n");
1920 $target_adds{"$cleantarget-am"} .= "$cleantarget-moc-classes ";
1924 #-----------------------------------------------------------------------------
1926 sub updateMakefile ()
1928 return if ($dryrun);
1930 open (FILEOUT, "> $makefile")
1931 || die "Could not create $makefile: $!\n";
1933 print FILEOUT "\# $progId - " . '$Revision: 1.305.2.1 $ ' . "\n";
1934 $MakefileData =~ s/\034/\\\n\t/g; # Restore continuation lines
1935 print FILEOUT $MakefileData;
1936 close FILEOUT;
1939 #-----------------------------------------------------------------------------
1941 # The given line needs to be removed from the makefile
1942 # Do this by adding the special "removed line" comment at the line start.
1943 sub removeLine ($$)
1945 my ($lookup, $old) = @_;
1947 $old =~ s/\034/\\\n#>- /g; # Fix continuation lines
1948 $MakefileData =~ s/\n$lookup/\n#>\- $old/;
1951 #-----------------------------------------------------------------------------
1953 # Replaces the old line with the new line
1954 # old line(s) are retained but tagged as removed. The new line(s) have the
1955 # "added" tag placed before it.
1956 sub substituteLine ($$)
1958 my ($lookup, $new) = @_;
1960 if ($MakefileData =~ /\n($lookup)/) {
1961 $old = $1;
1962 $old =~ s/\034/\\\n#>\- /g; # Fix continuation lines
1963 $new =~ s/\034/\\\n\t/g;
1964 my $newCount = ($new =~ tr/\n//) + 1;
1965 $MakefileData =~ s/\n$lookup/\n#>- $old\n#>\+ $newCount\n$new/;
1966 } else {
1967 print STDERR "Warning: substitution of \"$lookup\" in $printname failed\n";
1971 #-----------------------------------------------------------------------------
1973 # Slap new lines on the back of the file.
1974 sub appendLines ($)
1976 my ($new) = @_;
1977 $new =~ s/\034/\\\n\t/g; # Fix continuation lines
1978 my $newCount = ($new =~ tr/\n//) + 1;
1979 $MakefileData .= "\n#>\+ $newCount\n$new";
1982 #-----------------------------------------------------------------------------
1984 # Restore the Makefile.in to the state it was before we fiddled with it
1985 sub restoreMakefile ()
1987 $MakefileData =~ s/# $progId[^\n\034]*[\n\034]*//g;
1988 # Restore removed lines
1989 $MakefileData =~ s/([\n\034])#>\- /$1/g;
1990 # Remove added lines
1991 while ($MakefileData =~ /[\n\034]#>\+ ([^\n\034]*)/)
1993 my $newCount = $1;
1994 my $removeLines = "";
1995 while ($newCount--) {
1996 $removeLines .= "[^\n\034]*([\n\034]|)";
1998 $MakefileData =~ s/[\n\034]#>\+.*[\n\034]$removeLines/\n/;
2002 #-----------------------------------------------------------------------------