3 # Expands the specialised KDE tags in Makefile.in to (hopefully) valid
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.
17 # KDE_ICON = iconname iconname2 ...
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>
39 # Prototype the functions
41 sub processMakefile ($);
42 sub updateMakefile ();
43 sub restoreMakefile ();
47 sub substituteLine ($$);
49 sub findMocCandidates ();
50 sub pruneMocCandidates ($);
51 sub checkMocCandidates ();
55 sub tag_META_INCLUDES ();
56 sub tag_METASOURCES ();
59 sub tag_LOCALINSTALL();
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
73 $start = (times)[0]; # some stats for testing - comment out for release
76 $cppExt = "(cpp|cc|cxx|C|c\\+\\+)";
77 $hExt = "(h|H|hh|hxx|hpp|h\\+\\+)";
78 $progId = "KDE tags expanded automatically by " . basename($thisProg);
80 $printname = ""; # used to display the directory the Makefile is in
81 $use_final = 1; # create code for --enable-final
82 $cleantarget = "clean";
87 while (defined ($ARGV[0]))
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";
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));
116 elsif (/^--help$|^-h$/)
118 print STDOUT "Usage $thisProg [OPTION] ... [dir/Makefile.in]...\n",
120 "Patches dir/Makefile.in generated by automake\n",
121 "(where dir can be an absolute or relative directory name)\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 " called from is not the one to be used\n",
128 " --no-final don't patch for --enable-final\n";
132 elsif (/^--no-final$/)
135 $thisProg .= " --no-final";
137 elsif (/^--foreign-libtool$/)
139 $foreign_libtool = 1;
140 $thisProg .= " --foreign-libtool";
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";
164 # Only scan for files when the user hasn't entered data
167 print STDOUT "Scanning for Makefile.in\n" if ($verbose);
168 find (\&add_makefile, cwd());
171 print STDOUT "Using input files specified by user\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
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
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
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
230 local @cleanfiles = ();
231 local $cleanMoc = "";
232 local $closure_output = "";
234 local %varcontent = ();
236 $makefileDir = dirname($makefile);
237 chdir ($makefileDir);
238 $printname = $makefile;
239 $printname =~ s/^\Q$topdir\E\///;
240 $makefile = basename($makefile);
242 print STDOUT "Processing makefile $printname\n" if ($verbose);
244 # Setup and see if we need to do this.
245 return if (!initialise());
247 tag_AUTOMAKE (); # Allows a "make" to redo the Makefile.in
248 tag_META_INCLUDES (); # Supplies directories for src locations
250 foreach $program (@programs) {
251 $sources_changed{$program} = 0;
252 $depedmocs{$program} = "";
253 $important{$program} = "";
254 tag_IDLFILES(); # Sorts out idl rules
256 tag_UIFILES(); # Sorts out ui rules
257 tag_METASOURCES (); # Sorts out the moc rules
258 if ($sources_changed{$program}) {
259 my $lookup = "$program" . '_SOURCES\s*=\s*(.*)';
260 substituteLine($lookup, "$program\_SOURCES=" . $sources{$program});
262 if ($important{$program}) {
263 local %source_dict = ();
264 for $source (split(/[\034\s]+/, $sources{$program})) {
265 $source_dict{$source} = 1;
267 for $source (@cleanfiles) {
268 $source_dict{$source} = 0;
270 for $source (keys %source_dict) {
272 if ($source_dict{$source}) {
275 print STDERR "Error: $source is listed in a _SOURCE line in $printname, but doesn't exist yet. Put it in DISTCLEANFILES!\n";
277 $target_adds{"\$(srcdir)/$source"} .= $important{$program};
284 # Always add dist clean tag
285 # Add extra *.moc.cpp files created for USE_AUTOMOC because they
286 # aren't included in the normal *.moc clean rules.
287 appendLines ("$cleantarget-metasources:\n\t-rm -f $cleanMoc\n");
288 $target_adds{"$cleantarget-am"} .= "$cleantarget-metasources ";
291 tag_DIST() unless ($kdeopts{"noautodist"});
294 appendLines ("$cleantarget-idl:\n\t-rm -f $idl_output\n");
295 $target_adds{"$cleantarget-am"} .= "$cleantarget-idl ";
299 appendLines ("$cleantarget-ui:\n\t-rm -f $ui_output\n");
300 $target_adds{"$cleantarget-am"} .= "$cleantarget-ui ";
303 if ($closure_output) {
304 appendLines ("$cleantarget-closures:\n\t-rm -f $closure_output\n");
305 $target_adds{"$cleantarget-am"} .= "$cleantarget-closures ";
308 if ($MakefileData =~ /\nKDE_LANG\s*=\s*(\S*)\s*\n/) {
309 $kdelang = '$(KDE_LANG)'
314 tag_POFILES (); # language rules for po directory
315 tag_DOCFILES (); # language rules for doc directories
316 tag_LOCALINSTALL(); # add $(DESTDIR) before all kde_ dirs
320 my $tmp = "force-reedit:\n";
321 $tmp .= "\t$automkCall\n\tcd \$(top_srcdir) && perl $thisProg $printname\n\n";
326 tag_FINAL() if (!$kdeopts{"nofinal"});
328 my $final_lines = "final:\n\t\$(MAKE) ";
329 my $final_install_lines = "final-install:\n\t\$(MAKE) ";
330 my $nofinal_lines = "no-final:\n\t\$(MAKE) ";
331 my $nofinal_install_lines = "no-final-install:\n\t\$(MAKE) ";
333 foreach $program (@programs) {
335 my $lookup = "$program\_OBJECTS.*=[^\n]*";
339 my @list = split(/[\034\s]+/, $realObjs{$program});
341 if (!$kdeopts{"nofinal"} && @list > 1 && $finalObjs{$program}) {
343 $new .= "$program\_final\_OBJECTS = " . $finalObjs{$program};
344 $new .= "\n$program\_nofinal\_OBJECTS = " . $realObjs{$program};
345 $new .= "\n\@KDE_USE_FINAL_FALSE\@$program\_OBJECTS = \$($program\_nofinal\_OBJECTS)";
346 $new .= "\n\@KDE_USE_FINAL_TRUE\@$program\_OBJECTS = \$($program\_final\_OBJECTS)";
348 $final_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" ";
349 $final_install_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" ";
350 $nofinal_lines .= "$program\_OBJECTS=\"\$($program\_nofinal\_OBJECTS)\" ";
351 $nofinal_install_lines .= "$program\_OBJECTS=\"\$($program\_nofinal_OBJECTS)\" ";
353 $new = "$program\_OBJECTS = " . $realObjs{$program};
355 substituteLine ($lookup, $new);
357 appendLines($final_lines . "all-am");
358 appendLines($final_install_lines . "install-am");
359 appendLines($nofinal_lines . "all-am");
360 appendLines($nofinal_install_lines . "install-am");
362 my $lookup = '(\@\S+\@)?DEP_FILES\s*=([^\n]*)';
363 if ($MakefileData =~ /\n$lookup\n/o) {
369 # Add the conditions on every line, since
370 # there may be line continuations in the list.
371 $workfiles = "$dep_files $dep_finals $depfiles";
372 $workfiles =~ s/\034/\034$condition\@KDE_USE_FINAL_TRUE\@\t/g;
373 $lines = "$condition\@KDE_USE_FINAL_TRUE\@DEP_FILES = $workfiles\n";
374 $workfiles = "$dep_files $depfiles";
375 $workfiles =~ s/\034/\034$condition\@KDE_USE_FINAL_FALSE\@\t/g;
376 $lines .= "$condition\@KDE_USE_FINAL_FALSE\@DEP_FILES = $workfiles\n";
378 $workfiles = "$dep_files $depfiles";
379 $workfiles =~ s/\034/\034$condition\t/g;
380 $lines = $condition . "DEP_FILES = $workfiles\n";
382 substituteLine($lookup, $lines);
385 my $cvs_lines = "cvs-clean:\n";
386 $cvs_lines .= "\t\$(MAKE) admindir=\$(top_srcdir)/admin -f \$(top_srcdir)/admin/Makefile.common cvs-clean\n";
387 appendLines($cvs_lines);
389 $cvs_lines = "kde-rpo-clean:\n";
390 $cvs_lines .= "\t-rm -f *.rpo\n";
391 appendLines($cvs_lines);
392 $target_adds{"clean"} .= "kde-rpo-clean ";
394 my %target_dels = ("install-data-am" => "");
396 # some strange people like to do a install-exec, and expect that also
397 # all modules are installed. automake doesn't know this, so we need to move
398 # this here from install-data to install-exec.
399 if ($MakefileData =~ m/\nkde_module_LTLIBRARIES\s*=/) {
400 # $target_adds{"install-exec-am"} .= "install-kde_moduleLTLIBRARIES ";
401 # don't use $target_adds here because we need to append the dependency, not
402 # prepend it. Fixes #44342 , when a module depends on a lib in the same dir
403 # and libtool needs it during relinking upon install (Simon)
404 my $lookup = "install-exec-am:([^\n]*)";
405 if($MakefileData =~ /\n$lookup\n/) {
406 substituteLine("$lookup", "install-exec-am: $1 install-kde_moduleLTLIBRARIES");
408 $target_dels{"install-data-am"} .= "install-kde_moduleLTLIBRARIES ";
409 $target_adds{"install-data-am"} .= " ";
414 foreach $add (keys %target_adds) {
415 my $lookup = quotemeta($add) . ':([^\n]*)';
416 if ($MakefileData =~ /\n$lookup\n/) {
418 my $oldlines = $lookup;
419 if (defined $target_dels{$add}) {
420 foreach $del (split(' ', $target_dels{$add})) {
421 $newlines =~ s/\s*$del\s*/ /g;
424 substituteLine($oldlines, "$add: " . $target_adds{$add} . $newlines);
426 $lines .= "$add: " . $target_adds{$add} . "\n";
436 if ($MakefileData =~ m/\n(.*)\$\(CXXFLAGS\)(.*)\n/) {
437 my $vor = $1; # "vor" means before in German
438 my $nach = $2; # "nach" means after in German
439 my $lookup = quotemeta("$1\$(CXXFLAGS)$2");
440 my $replacement = "$1\$(KCXXFLAGS)$2";
441 $MakefileData =~ s/$lookup/$replacement/;
442 $lookup =~ s/\\\$\\\(CXXFLAGS\\\)/\\\$\\\(KCXXFLAGS\\\)/;
443 $replacement = "$vor\$(KCXXFLAGS) \$(KDE_CXXFLAGS)$nach";
444 substituteLine($lookup, $replacement);
450 if($foreign_libtool == 0) {
451 $lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=link) (\$\(CXXLD\).*\$\(KCXXFLAGS\))';
453 if ($MakefileData =~ m/$lookup/ ) {
454 $MakefileData =~ s/$lookup/$1 --tag=CXX $2/;
457 $lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=compile)\s+(\$\(CXX\)\s+)';
458 if ($MakefileData =~ m/$lookup/ ) {
459 $MakefileData =~ s/$lookup/$1 --tag=CXX $2/;
463 $MakefileData =~ s/\$\(KCXXFLAGS\)/\$\(CXXFLAGS\)/g;
465 $lookup = '(.*)cp -pr \$\$/\$\$file \$\(distdir\)/\$\$file(.*)';
466 if ($MakefileData =~ m/\n$lookup\n/) {
467 substituteLine($lookup, "$1cp -pr \$\$d/\$\$file \$(distdir)/\$\$file$2");
470 # Always update the Makefile.in
475 #-----------------------------------------------------------------------------
477 # Beware: This procedure is not complete. E.g. it also parses lines
478 # containing a '=' in rules (for instance setting shell vars). For our
479 # usage this us enough, though.
480 sub read_variables ()
482 while ($MakefileData =~ /\n\s*(\S+)\s*=([^\n]*)/g) {
483 $varcontent{$1} = $2;
487 # Check to see whether we should process this make file.
488 # This is where we look for tags that we need to process.
489 # A small amount of initialising on the tags is also done here.
490 # And of course we open and/or create the needed make files.
493 if (! -r "Makefile.am") {
494 print STDOUT "found Makefile.in without Makefile.am\n" if ($verbose);
498 # Checking for files to process...
499 open (FILEIN, $makefile)
500 || die "Could not open $makefileDir/$makefile: $!\n";
502 # stat(FILEIN)[7] might look more elegant, but is slower as it
503 # requires stat'ing the file
505 my $fsize = tell(FILEIN);
507 read FILEIN, $MakefileData, $fsize;
509 print "DOS CRLF within $makefileDir/$makefile!\n" if($MakefileData =~ y/\r//d);
511 # Remove the line continuations, but keep them marked
512 # Note: we lose the trailing spaces but that's ok.
513 # Don't mangle line-leading spaces (usually tabs)
514 # since they're important.
515 $MakefileData =~ s/\\\s*\n/\034/g;
517 # If we've processed the file before...
518 restoreMakefile () if ($MakefileData =~ /$progId/);
520 foreach $dir (@foreignfiles) {
521 if (substr($makefileDir,0,length($dir)) eq $dir) {
527 $kdeopts{"foreign"} = 0;
528 $kdeopts{"qtonly"} = 0;
529 $kdeopts{"noautodist"} = 0;
530 $kdeopts{"foreign-libtool"} = $foreign_libtool;
531 $kdeopts{"nofinal"} = !$use_final; # default
535 if ($MakefileData =~ /\nKDE_OPTIONS\s*=\s*([^\n]*)\n/) {
536 local @kde_options = split(/[\s\034]/, $1);
537 if (grep(/^foreign$/, @kde_options)) {
538 push(@foreignfiles, $makefileDir . "/");
539 return 0; # don't touch me
541 for $opt (@kde_options) {
542 if (!defined $kdeopts{$opt}) {
543 print STDERR "Warning: unknown option $opt in $printname\n";
550 # Look for the tags that mean we should process this file.
552 $metasourceTags++ while ($MakefileData =~ /\n[^=\#]*METASOURCES\s*=/g);
555 $pofileTag++ while ($MakefileData =~ /\nPOFILES\s*=/g);
558 print STDERR "Error: Only one POFILES tag allowed\n";
562 while ($MakefileData =~ /\n\.SUFFIXES:([^\n]+)\n/g) {
563 my @list=split(' ', $1);
564 foreach $ext (@list) {
565 if ($ext =~ /^\.$cppExt$/) {
567 $cxxsuffix =~ s/\.//g;
568 print STDOUT "will use suffix $cxxsuffix\n" if ($verbose);
574 while ($MakefileData =~ /\n(\S*)_OBJECTS\s*=[ \t\034]*([^\n]*)\n/g) {
577 my $objs = $2; # safe them
581 my @objlist = split(/[\s\034]+/, $objs);
582 foreach $obj (@objlist) {
583 if ($obj =~ /(\S*)\$\((\S+)\)/ ) {
586 if ($pre eq '' && exists($varcontent{$variable})) {
587 my @addlist = split(/[\s\034]+/, $varcontent{$variable});
588 push(@objlist, @addlist);
589 } elsif ($variable !~ 'OBJEXT') {
597 $program =~ s/^am_// if ($program =~ /^am_/);
599 my $sourceprogram = $program;
600 $sourceprogram =~ s/\@am_/\@/ if($sourceprogram =~ /^.*\@am_.+/);
602 print STDOUT "found program $program\n" if ($verbose);
603 push(@programs, $program);
605 $realObjs{$program} = $objs;
607 if ($MakefileData =~ /\n$sourceprogram\_SOURCES\s*=\s*(.*)\n/) {
608 $sources{$program} = $1;
611 $sources{$program} = "";
612 print STDERR "found program with no _SOURCES: $program\n";
615 my $realprogram = $program;
616 $realprogram =~ s/_/./g; # unmask to regexp
617 if ($MakefileData =~ /\n($realprogram)(\$\(EXEEXT\)?)?:.*\$\($program\_OBJECTS\)/) {
618 $realname{$program} = $1;
620 # not standard Makefile - nothing to worry about
621 $realname{$program} = "";
625 my $lookup = '\nDEPDIR\s*=.*';
626 if ($MakefileData !~ /($lookup)\n/o) {
627 $lookup = '\nbindir\s*=.*';
628 if ($MakefileData =~ /($lookup)\n/) {
629 substituteLine ($lookup, "DEPDIR = .deps\n$1");
633 my @marks = ('MAINTAINERCLEANFILES', 'CLEANFILES', 'DISTCLEANFILES');
634 foreach $mark (@marks) {
635 while ($MakefileData =~ /\n($mark)\s*=\s*([^\n]*)/g) {
636 foreach $file (split('[\034\s]', $2)) {
638 push(@cleanfiles, $file);
644 $localTag++ if ($MakefileData =~ /\ninstall-\S+-local:/);
646 return (!$errorflag);
649 #-----------------------------------------------------------------------------
651 # Gets the list of user defined directories - relative to $srcdir - where
652 # header files could be located.
653 sub tag_META_INCLUDES ()
655 my $lookup = '[^=\n]*META_INCLUDES\s*=\s*(.*)';
656 return 1 if ($MakefileData !~ /($lookup)\n/o);
657 print STDOUT "META_INCLUDE processing <$1>\n" if ($verbose);
660 removeLine ($lookup, $1);
662 $headerStr =~ tr/\034/ /;
663 my @headerlist = split(' ', $headerStr);
665 foreach $dir (@headerlist)
667 $dir =~ s#\$\(srcdir\)#.#;
670 print STDERR "Warning: $dir can't be found. ",
671 "Must be a relative path to \$(srcdir)\n";
675 push (@headerdirs, $dir);
682 #-----------------------------------------------------------------------------
686 my @final_names = ();
688 foreach $program (@programs) {
690 if ($sources{$program} =~ /\(/) {
691 print STDOUT "found ( in $program\_SOURCES. skipping\n" if ($verbose);
695 my $mocs = ""; # Moc files (in this program)
696 my $moc_cpp_added = 0; # If we added some .moc.cpp files, due to
697 # no other .cpp file including the .moc one.
699 my @progsources = split(/[\s\034]+/, $sources{$program});
701 @shash{@progsources} = 1; # we are only interested in the existence
704 foreach $source (@progsources) {
705 my $suffix = $source;
706 $suffix =~ s/^.*\.([^\.]+)$/$1/;
708 $sourcelist{$suffix} .= "$source ";
710 foreach my $mocFile (keys (%globalmocs))
712 my ($dir, $hFile, $cppFile) = split ("\035", $globalmocs{$mocFile}, 3);
713 if (defined ($cppFile)) {
714 $mocs .= " $mocFile.moc" if exists $shash{$cppFile};
716 $sourcelist{$cxxsuffix} .= "$mocFile.moc.$cxxsuffix ";
720 foreach $suffix (keys %sourcelist) {
722 # See if this file contains c++ code. (i.e., just check the file's suffix against c++ extensions)
723 my $suffix_is_cxx = 0;
724 if($suffix =~ /($cppExt)$/) {
729 my $mocfiles_in = ($suffix eq $cxxsuffix) && $moc_cpp_added;
731 my @sourcelist = split(/[\s\034]+/, $sourcelist{$suffix});
733 if ((@sourcelist == 1 && !$mocfiles_in) || $suffix_is_cxx != 1 ) {
735 # we support IDL on our own
736 if ($suffix eq "skel" || $suffix =~ /^stub/ || $suffix =~ /^signals/
737 || $suffix eq "h" || $suffix eq "ui" ) {
741 foreach $file (@sourcelist) {
742 $file =~ s/\Q$suffix\E$//;
744 $finalObjs{$program} .= $file;
745 if ($program =~ /_la$/) {
746 $finalObjs{$program} .= "lo ";
748 $finalObjs{$program} .= "o ";
754 my $source_deps = "";
755 foreach $source (@sourcelist) {
757 $source_deps .= " \$(srcdir)/$source";
759 $source_deps .= " $source";
763 $handling = "$program.all_$suffix.$suffix: \$(srcdir)/Makefile.in" . $source_deps . " " . join(' ', $mocs) . "\n";
764 $handling .= "\t\@echo 'creating $program.all_$suffix.$suffix ...'; \\\n";
765 $handling .= "\trm -f $program.all_$suffix.files $program.all_$suffix.final; \\\n";
766 $handling .= "\techo \"#define KDE_USE_FINAL 1\" >> $program.all_$suffix.final; \\\n";
767 $handling .= "\tfor file in " . $sourcelist{$suffix} . "; do \\\n";
768 $handling .= "\t echo \"#include \\\"\$\$file\\\"\" >> $program.all_$suffix.files; \\\n";
769 $handling .= "\t test ! -f \$\(srcdir\)/\$\$file || egrep '^#pragma +implementation' \$\(srcdir\)/\$\$file >> $program.all_$suffix.final; \\\n";
770 $handling .= "\tdone; \\\n";
771 $handling .= "\tcat $program.all_$suffix.final $program.all_$suffix.files > $program.all_$suffix.$suffix; \\\n";
772 $handling .= "\trm -f $program.all_$suffix.final $program.all_$suffix.files\n";
774 appendLines($handling);
776 push(@final_names, "$program.all_$suffix.$suffix");
777 my $finalObj = "$program.all_$suffix.";
778 if ($program =~ /_la$/) {
783 $finalObjs{$program} .= $finalObj . " ";
787 if (!$kdeopts{"nofinal"} && @final_names >= 1) {
788 # add clean-final target
789 my $lines = "$cleantarget-final:\n";
790 $lines .= "\t-rm -f " . join(' ', @final_names) . "\n" if (@final_names);
792 $target_adds{"$cleantarget-am"} .= "$cleantarget-final ";
794 foreach $finalfile (@final_names) {
795 $finalfile =~ s/\.[^.]*$/.P/;
796 $dep_finals .= " \$(DEPDIR)/$finalfile";
801 #-----------------------------------------------------------------------------
803 sub tag_COMPILE_FIRST()
805 foreach $program (@programs) {
806 my $lookup = "$program" . '_COMPILE_FIRST\s*=\s*(.*)';
807 if ($MakefileData =~ m/\n$lookup\n/) {
808 my @compilefirst = split(/[\s\034]+/, $1);
809 my @progsources = split(/[\s\034]+/, $sources{$program});
810 my %donesources = ();
812 foreach $source (@progsources) {
816 $sdeps = "\$(srcdir)/$source";
820 foreach $depend (@compilefirst) {
821 next if ($source eq $depend);
822 # avoid cyclic dependencies
823 next if defined($donesources{$depend});
826 $handling .= "$sdeps: " . join(' ', @deps) . "\n" if (@deps);
827 $donesources{$source} = 1;
829 appendLines($handling) if (length($handling));
834 #-----------------------------------------------------------------------------
837 # Organises the list of headers that we'll use to produce moc files
839 sub tag_METASOURCES ()
841 local @newObs = (); # here we add to create object files
842 local @deped = (); # here we add to create moc files
843 local $mocExt = ".moc";
844 local %mocFiles = ();
851 #print "$program: tag_METASOURCES\n";
852 if ($metasourceTags > 1) {
853 $lookup = $program . '_METASOURCES\s*=\s*(.*)';
854 return 1 if ($MakefileData !~ /\n($lookup)\n/);
857 $lookup = $program . '_METASOURCES\s*=\s*(.*)';
858 if ($MakefileData !~ /\n($lookup)\n/) {
859 $lookup = 'METASOURCES\s*=\s*(.*)';
860 return 1 if ($MakefileData !~ /\n($lookup)\n/o);
862 $metasourceTags = 0; # we can use the general target only once
867 print STDOUT "METASOURCE processing <$found>)\n" if ($verbose);
870 $postEqual =~ s/[^=]*=//;
872 removeLine ($lookup, $found);
874 # Always find the header files that could be used to "moc"
875 return 1 if (findMocCandidates ());
877 if ($postEqual =~ /AUTO\s*(\S*)|USE_AUTOMOC\s*(\S*)/)
879 print STDERR "$printname: the argument for AUTO|USE_AUTOMOC is obsolete" if ($+);
880 $mocExt = ".moc.$cxxsuffix";
885 # Not automoc so read the list of files supplied which
886 # should be .moc files.
888 $postEqual =~ tr/\034/ /;
890 # prune out extra headers - This also checks to make sure that
892 pruneMocCandidates ($postEqual);
895 checkMocCandidates ();
898 my $ext = ($program =~ /_la$/) ? ".moc.lo " : ".moc.o ";
899 $realObjs{$program} .= "\034" . join ($ext, @newObs) . $ext;
900 $depedmocs{$program} = join (".moc.$cxxsuffix " , @newObs) . ".moc.$cxxsuffix";
901 foreach $file (@newObs) {
902 $dep_files .= " \$(DEPDIR)/$file.moc.P" if($dep_files !~/$file.moc.P/);
906 $depedmocs{$program} .= " ";
907 $depedmocs{$program} .= join('.moc ', @deped) . ".moc";
908 $depedmocs{$program} .= " ";
911 @globalmocs{keys %mocFiles}=values %mocFiles;
914 #-----------------------------------------------------------------------------
916 # Returns 0 if the line was processed - 1 otherwise.
917 # Errors are logged in the global $errorflags
920 my $lookup = '.*cd \$\(top_srcdir\)\s+&&[\s\034]+\$\(AUTOMAKE\)(.*)';
921 return 1 if ($MakefileData !~ /\n($lookup)\n/);
922 print STDOUT "AUTOMAKE processing <$1>\n" if ($verbose);
924 my $newLine = $1."\n\tcd \$(top_srcdir) && perl $thisProg $printname";
925 substituteLine ($lookup, $newLine);
930 #-----------------------------------------------------------------------------
932 sub handle_TOPLEVEL()
936 opendir (THISDIR, ".");
937 foreach $entry (readdir(THISDIR)) {
940 next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/ || $entry =~ /.gmo$/);
942 if ($entry =~ /\.po$/) {
945 push(@restfiles, $entry);
950 $target_adds{"install-data-am"} .= "install-nls-files ";
951 $lines = "install-nls-files:\n";
952 $lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$kdelang\n";
953 for $file (@restfiles) {
954 $lines .= "\t\$(INSTALL_DATA) \$\(srcdir\)/$file \$(DESTDIR)\$(kde_locale)/$kdelang/$file\n";
956 $target_adds{"uninstall"} .= "uninstall-nls-files ";
957 $lines .= "uninstall-nls-files:\n";
958 for $file (@restfiles) {
959 $lines .= "\t-rm -f \$(DESTDIR)\$(kde_locale)/$kdelang/$file\n";
967 #-----------------------------------------------------------------------------
971 if ($MakefileData !~ /\nSUBDIRS\s*=\s*\$\(AUTODIRS\)\s*\n/) {
977 opendir (THISDIR, ".");
978 foreach $entry (readdir(THISDIR)) {
979 next if ($entry eq "CVS" || $entry =~ /^\./);
980 if (-d $entry && -f $entry . "/Makefile.am") {
981 $subdirs .= " $entry";
987 my $lines = "SUBDIRS =$subdirs\n";
988 substituteLine('SUBDIRS\s*=.*', $lines);
994 my @psources = split(/[\034\s]+/, $sources{$program});
998 foreach $source (@psources) {
1000 my $skel = ($source =~ m/\.skel$/);
1001 my $stub = ($source =~ m/\.stub$/);
1002 my $signals = ($source =~ m/\.signals$/);
1004 if ($stub || $skel || $signals) {
1006 my $qs = quotemeta($source);
1007 $sources{$program} =~ s/$qs//;
1008 $sources_changed{$program} = 1;
1010 print STDOUT "adding IDL file $source\n" if ($verbose);
1012 $source =~ s/\.(stub|skel|signals)$//;
1017 $sourcename = "$source\_skel";
1019 $sourcename = "$source\_stub";
1021 $sourcename = "$source\_signals";
1025 if (-f "$makefileDir/$source.h") {
1026 $sourcedir = '$(srcdir)/';
1028 if ($MakefileData =~ /\n$source\_DIR\s*=\s*(\S+)\n/) {
1030 $sourcedir .= "/" if ($sourcedir !~ /\/$/);
1034 if ($allidls !~ /$source\_kidl/) {
1036 $dep_lines .= "$source.kidl: $sourcedir$source.h \$(DCOP_DEPENDENCIES)\n";
1037 $dep_lines .= "\t\$(DCOPIDL) $sourcedir$source.h > $source.kidl || ( rm -f $source.kidl ; /bin/false )\n";
1039 $allidls .= $source . "_kidl ";
1042 if ($allidls !~ /$sourcename/) {
1044 $dep_lines_tmp = "";
1047 $dep_lines .= "$sourcename.$cxxsuffix: $source.kidl\n";
1048 $dep_lines .= "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-signals --no-stub $source.kidl\n";
1050 $dep_lines_tmp = "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-signals --no-skel $source.kidl\n";
1052 $dep_lines_tmp = "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-stub --no-skel $source.kidl\n";
1055 if ($stub || $signals) {
1056 $target_adds{"$sourcename.$cxxsuffix"} .= "$sourcename.h ";
1057 $dep_lines .= "$sourcename.h: $source.kidl\n";
1058 $dep_lines .= $dep_lines_tmp;
1061 $allidls .= $sourcename . " ";
1064 $idlfiles{$program} .= $sourcename . " ";
1066 if ($program =~ /_la$/) {
1067 $realObjs{$program} .= " $sourcename.lo";
1069 $realObjs{$program} .= " $sourcename.\$(OBJEXT)";
1071 $sources{$program} .= " $sourcename.$cxxsuffix";
1072 $sources_changed{$program} = 1;
1073 $important{$program} .= "$sourcename.h " if (!$skel);
1074 $idl_output .= "\\\n\t$sourcename.$cxxsuffix $sourcename.h $source.kidl ";
1075 push(@cleanfiles, "$sourcename.$cxxsuffix");
1076 push(@cleanfiles, "$sourcename.h");
1077 push(@cleanfiles, "$sourcename.kidl");
1078 $dep_files .= " \$(DEPDIR)/$sourcename.P" if ($dep_files !~/$sourcename.P/);
1082 appendLines($dep_lines);
1086 my $lookup = "($program)";
1087 $lookup .= '(|\$\(EXEEXT\))';
1088 $lookup =~ s/\_/./g;
1089 $lookup .= ":(.*..$program\_OBJECTS..*)";
1090 # $lookup = quotemeta($lookup);
1091 if ($MakefileData =~ /\n$lookup\n/) {
1093 my $line = "$1$2: ";
1094 foreach $file (split(' ', $idlfiles{$program})) {
1095 $line .= "$file.$cxxsuffix ";
1098 substituteLine($lookup, $line);
1100 print STDERR "no built dependency found $lookup\n";
1107 my @psources = split(/[\034\s]+/, $sources{$program});
1111 foreach $source (@psources) {
1113 if ($source =~ m/\.ui$/) {
1115 print STDERR "adding UI file $source\n" if ($verbose);
1117 my $qs = quotemeta($source);
1118 $sources{$program} =~ s/$qs//;
1119 $sources_changed{$program} = 1;
1121 $source =~ s/\.ui$//;
1124 if (-f "$makefileDir/$source.ui") {
1125 $sourcedir = '$(srcdir)/';
1128 if (!$uiFiles{$source}) {
1130 $dep_lines .= "$source.$cxxsuffix: $sourcedir$source.ui $source.h $source.moc\n";
1131 $dep_lines .= "\trm -f $source.$cxxsuffix\n";
1132 if (!$kdeopts{"qtonly"}) {
1133 $dep_lines .= "\techo '#include <klocale.h>' > $source.$cxxsuffix\n";
1134 my ($mangled_source) = $source;
1135 $mangled_source =~ s/[^A-Za-z0-9]/_/g; # get rid of garbage
1136 $dep_lines .= "\t\$(UIC) -tr \${UIC_TR} -i $source.h $sourcedir$source.ui > $source.$cxxsuffix.temp ; ret=\$\$?; \\\n";
1137 $dep_lines .= "\tsed -e \"s,\${UIC_TR}( \\\"\\\" ),QString::null,g\" $source.$cxxsuffix.temp | sed -e \"s,\${UIC_TR}( \\\"\\\"\\, \\\"\\\" ),QString::null,g\" | sed -e \"s,image\\([0-9][0-9]*\\)_data,img\\1_" . $mangled_source . ",g\" >> $source.$cxxsuffix ;\\\n";
1138 $dep_lines .= "\trm -f $source.$cxxsuffix.temp ;\\\n";
1140 $dep_lines .= "\t\$(UIC) -i $source.h $sourcedir$source.ui > $source.$cxxsuffix; ret=\$\$?; \\\n";
1142 $dep_lines .= "\tif test \"\$\$ret\" = 0; then echo '#include \"$source.moc\"' >> $source.$cxxsuffix; else rm -f $source.$cxxsuffix ; exit \$\$ret ; fi\n\n";
1143 $dep_lines .= "$source.h: $sourcedir$source.ui\n";
1144 $dep_lines .= "\t\$(UIC) -o $source.h $sourcedir$source.ui\n\n";
1145 $dep_lines .= "$source.moc: $source.h\n";
1146 $dep_lines .= "\t\$(MOC) $source.h -o $source.moc\n";
1148 $uiFiles{$source} = 1;
1149 $depedmocs{$program} .= " $source.moc";
1150 $globalmocs{$source} = "\035$source.h\035$source.cpp";
1153 if ($program =~ /_la$/) {
1154 $realObjs{$program} .= " $source.lo";
1156 $realObjs{$program} .= " $source.\$(OBJEXT)";
1158 $sources{$program} .= " $source.$cxxsuffix";
1159 $sources_changed{$program} = 1;
1160 $important{$program} .= "$source.h ";
1161 $ui_output .= "\\\n\t$source.$cxxsuffix $source.h $source.moc ";
1162 push(@cleanfiles, "$source.$cxxsuffix");
1163 push(@cleanfiles, "source.h");
1164 push(@cleanfiles, "$source.moc");
1165 $dep_files .= " \$(DEPDIR)/$source.P" if($dep_files !~/$source.P/ );
1169 appendLines($dep_lines);
1175 my $lookup = '([^\s]*)_ICON\s*=\s*([^\n]*)';
1179 while ($MakefileData =~ /\n$lookup/og) {
1182 $destdir = "kde_icondir";
1184 $destdir = $1 . "dir";
1186 my $iconauto = ($2 =~ /AUTO\s*$/);
1188 if ( ! $iconauto ) {
1189 my @_appnames = split(" ", $2);
1190 print STDOUT "KDE_ICON processing <@_appnames>\n" if ($verbose);
1191 foreach $appname (@_appnames) {
1192 push(@appnames, quotemeta($appname));
1195 print STDOUT "KDE_ICON processing <AUTO>\n" if ($verbose);
1199 opendir (THISDIR, ".");
1200 foreach $entry (readdir(THISDIR)) {
1201 next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
1202 next if (! -f $entry);
1205 push(@files, $entry)
1206 if ($entry =~ /\.xpm/ || $entry =~ /\.png/ || $entry =~ /\.mng/ || $entry =~ /\.svg/);
1208 foreach $appname (@appnames) {
1209 push(@files, $entry)
1210 if ($entry =~ /-$appname\.xpm/ || $entry =~ /-$appname\.png/ || $entry =~ /-$appname\.mng/ || $entry =~ /-$appname\.svg/);
1216 my %directories = ();
1218 foreach $file (@files) {
1219 my $newfile = $file;
1221 $prefix =~ s/\.(png|xpm|mng|svg|svgz)$//;
1222 my $appname = $prefix;
1223 $appname =~ s/^[^-]+-// if ($appname =~ /-/) ;
1224 $appname =~ s/^[^-]+-// if ($appname =~ /-/) ;
1225 $appname = quotemeta($appname);
1226 $prefix =~ s/$appname$//;
1229 $prefix = 'lo16-app' if ($prefix eq 'mini');
1230 $prefix = 'lo32-app' if ($prefix eq 'lo');
1231 $prefix = 'hi48-app' if ($prefix eq 'large');
1232 $prefix .= '-app' if ($prefix =~ m/^...$/);
1235 $type =~ s/^.*-([^-]+)$/$1/;
1236 $prefix =~ s/^(.*)-[^-]+$/$1/;
1240 'action' => 'actions',
1242 'device' => 'devices',
1243 'filesys' => 'filesystems',
1244 'mime' => 'mimetypes'
1247 if (! defined $type_hash{$type} ) {
1248 print STDERR "unknown icon type $type in $printname ($file)\n";
1254 'los' => 'locolor/16x16',
1255 'lom' => 'locolor/32x32',
1256 'him' => 'hicolor/32x32',
1257 'hil' => 'hicolor/48x48',
1258 'lo16' => 'locolor/16x16',
1259 'lo22' => 'locolor/22x22',
1260 'lo32' => 'locolor/32x32',
1261 'hi16' => 'hicolor/16x16',
1262 'hi22' => 'hicolor/22x22',
1263 'hi32' => 'hicolor/32x32',
1264 'hi48' => 'hicolor/48x48',
1265 'hi64' => 'hicolor/64x64',
1266 'hi128' => 'hicolor/128x128',
1267 'hisc' => 'hicolor/scalable',
1268 'cr16' => 'crystalsvg/16x16',
1269 'cr22' => 'crystalsvg/22x22',
1270 'cr32' => 'crystalsvg/32x32',
1271 'cr48' => 'crystalsvg/48x48',
1272 'cr64' => 'crystalsvg/64x64',
1273 'cr128' => 'crystalsvg/128x128',
1274 'crsc' => 'crystalsvg/scalable'
1277 $newfile =~ s@.*-($appname\.(png|xpm|mng|svgz|svg?))@$1@;
1279 if (! defined $dir_hash{$prefix}) {
1280 print STDERR "unknown icon prefix $prefix in $printname\n";
1284 my $dir = $dir_hash{$prefix} . "/" . $type_hash{$type};
1285 if ($newfile =~ /-[^\.]/) {
1287 $tmp =~ s/^([^-]+)-.*$/$1/;
1288 $dir = $dir . "/" . $tmp;
1289 $newfile =~ s/^[^-]+-//;
1292 if (!defined $directories{$dir}) {
1293 $install .= "\t\$(mkinstalldirs) \$(DESTDIR)\$($destdir)/$dir\n";
1294 $directories{$dir} = 1;
1297 $install .= "\t\$(INSTALL_DATA) \$(srcdir)/$file \$(DESTDIR)\$($destdir)/$dir/$newfile\n";
1298 $uninstall .= "\t-rm -f \$(DESTDIR)\$($destdir)/$dir/$newfile\n";
1303 if (length($install)) {
1304 $target_adds{"install-data-am"} .= "install-kde-icons ";
1305 $target_adds{"uninstall-am"} .= "uninstall-kde-icons ";
1306 appendLines("install-kde-icons:\n" . $install . "\nuninstall-kde-icons:\n" . $uninstall);
1310 sub handle_POFILES($$)
1312 my @pofiles = split(" ", $_[0]);
1315 # Build rules for creating the gmo files
1317 my $allgmofiles = "";
1318 my $pofileLine = "POFILES =";
1319 foreach $pofile (@pofiles)
1321 $pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1322 $tmp .= "$1.gmo: $pofile\n";
1323 $tmp .= "\trm -f $1.gmo; \$(GMSGFMT) -o $1.gmo \$(srcdir)/$pofile\n";
1324 $tmp .= "\ttest ! -f $1.gmo || touch $1.gmo\n";
1325 $allgmofiles .= " $1.gmo";
1326 $pofileLine .= " $1.po";
1329 my $lookup = 'POFILES\s*=([^\n]*)';
1330 if ($MakefileData !~ /\n$lookup/o) {
1331 appendLines("$pofileLine\nGMOFILES =$allgmofiles");
1333 substituteLine ($lookup, "$pofileLine\nGMOFILES =$allgmofiles");
1338 # Add the "clean" rule so that the maintainer-clean does something
1339 appendLines ("clean-nls:\n\t-rm -f $allgmofiles\n");
1341 $target_adds{"maintainer-clean"} .= "clean-nls ";
1343 $lookup = 'DISTFILES\s*=\s*(.*)';
1344 if ($MakefileData =~ /\n$lookup\n/o) {
1345 $tmp = "DISTFILES = \$(GMOFILES) \$(POFILES) $1";
1346 substituteLine ($lookup, $tmp);
1350 $target_adds{"install-data-am"} .= "install-nls ";
1352 $tmp = "install-nls:\n";
1354 $tmp .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES\n";
1356 $tmp .= "\t\@for base in ";
1357 foreach $pofile (@pofiles)
1359 $pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1363 $tmp .= "; do \\\n";
1365 $tmp .= "\t echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n";
1366 $tmp .= "\t if test -f \$\$base.gmo; then \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n";
1367 $tmp .= "\t elif test -f \$(srcdir)/\$\$base.gmo; then \$(INSTALL_DATA) \$(srcdir)/\$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n";
1368 $tmp .= "\t fi ;\\\n";
1370 $tmp .= "\t echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
1371 $tmp .= "\t \$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES ; \\\n";
1372 $tmp .= "\t if test -f \$\$base.gmo; then \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
1373 $tmp .= "\t elif test -f \$(srcdir)/\$\$base.gmo; then \$(INSTALL_DATA) \$(srcdir)/\$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
1374 $tmp .= "\t fi ;\\\n";
1376 $tmp .= "\tdone\n\n";
1379 $target_adds{"uninstall"} .= "uninstall-nls ";
1381 $tmp = "uninstall-nls:\n";
1382 foreach $pofile (@pofiles)
1384 $pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1386 $tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/$1.mo\n";
1388 $tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$1/LC_MESSAGES/\$(PACKAGE).mo\n";
1393 $target_adds{"all"} .= "all-nls ";
1395 $tmp = "all-nls: \$(GMOFILES)\n";
1399 $target_adds{"distdir"} .= "distdir-nls ";
1401 $tmp = "distdir-nls:\$(GMOFILES)\n";
1402 $tmp .= "\tfor file in \$(POFILES); do \\\n";
1403 $tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n";
1405 $tmp .= "\tfor file in \$(GMOFILES); do \\\n";
1406 $tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n";
1412 appendLines("merge:\n\t\$(MAKE) -f \$(top_srcdir)/admin/Makefile.common package-merge POFILES=\"\${POFILES}\" PACKAGE=\${PACKAGE}\n\n");
1417 #-----------------------------------------------------------------------------
1419 # Returns 0 if the line was processed - 1 otherwise.
1420 # Errors are logged in the global $errorflags
1423 my $lookup = 'POFILES\s*=([^\n]*)';
1424 return 1 if ($MakefileData !~ /\n$lookup/o);
1425 print STDOUT "POFILES processing <$1>\n" if ($verbose);
1429 # make sure these are all gone.
1430 if ($MakefileData =~ /\n\.po\.gmo:\n/)
1432 print STDERR "Warning: Found old .po.gmo rules in $printname. New po rules not added\n";
1436 # Either find the pofiles in the directory (AUTO) or use
1437 # only the specified po files.
1439 if ($tmp =~ /^\s*AUTO\s*$/)
1441 opendir (THISDIR, ".");
1442 $pofiles = join(" ", grep(/\.po$/, readdir(THISDIR)));
1444 print STDOUT "pofiles found = $pofiles\n" if ($verbose);
1445 if (-f "charset" && -f "kdelibs.po") {
1454 return 1 if (!$pofiles); # Nothing to do
1456 handle_POFILES($pofiles, $kdelang);
1461 sub helper_LOCALINSTALL($)
1463 my $lookup = "\035" . $_[0] . " *:[^\035]*\035\t";
1464 my $copy = $MakefileData;
1465 $copy =~ s/\n/\035/g;
1466 if ($copy =~ /($lookup.*)$/) {
1469 $install =~ s/\035$_[0] *:[^\035]*\035//;
1471 while (! $emptyline ) {
1472 if ($install =~ /([^\035]*)\035(.*)/) {
1475 if ($line !~ /^\s*$/ && $line !~ /^(\@.*\@)*\t/) {
1478 replaceDestDir($line);
1488 sub tag_LOCALINSTALL ()
1490 helper_LOCALINSTALL('install-exec-local');
1491 helper_LOCALINSTALL('install-data-local');
1492 helper_LOCALINSTALL('uninstall-local');
1497 sub replaceDestDir($) {
1498 local $line = $_[0];
1500 if ( $line =~ /^\s*(\@.*\@)*\s*\$\(mkinstalldirs\)/
1501 || $line =~ /^\s*(\@.*\@)*\s*\$\(INSTALL\S*\)/
1502 || $line =~ /^\s*(\@.*\@)*\s*(-?rm.*) \S*$/)
1504 $line =~ s/^(.*) ([^\s]+)\s*$/$1 \$(DESTDIR)$2/ if ($line !~ /\$\(DESTDIR\)/);
1507 if ($line ne $_[0]) {
1508 $_[0] = quotemeta $_[0];
1509 substituteLine($_[0], $line);
1513 #---------------------------------------------------------------------------
1514 sub tag_CLOSURE () {
1515 return if ($program !~ /_la$/);
1517 my $lookup = quotemeta($realname{$program}) . ":.*?\n\t.*?\\((.*?)\\) .*\n";
1518 $MakefileData =~ m/$lookup/;
1519 return if ($1 !~ /CXXLINK/);
1521 if ($MakefileData !~ /\n$program\_LDFLAGS\s*=.*-no-undefined/ &&
1522 $MakefileData !~ /\n$program\_LDFLAGS\s*=.*KDE_PLUGIN/ ) {
1523 print STDERR "Report: $program contains undefined in $printname\n" if ($program =~ /^lib/ && $dryrun);
1527 my $closure = $realname{$program} . ".closure";
1528 my $lines = "$closure: \$($program\_OBJECTS) \$($program\_DEPENDENCIES)\n";
1529 $lines .= "\t\@echo \"int main() {return 0;}\" > $program\_closure.$cxxsuffix\n";
1530 $lines .= "\t\@\$\(LTCXXCOMPILE\) -c $program\_closure.$cxxsuffix\n";
1531 $lines .= "\t\$\(CXXLINK\) $program\_closure.lo \$($program\_LDFLAGS) \$($program\_OBJECTS) \$($program\_LIBADD) \$(LIBS)\n";
1532 $lines .= "\t\@rm -f $program\_closure.* $closure\n";
1533 $lines .= "\t\@echo \"timestamp\" > $closure\n";
1535 appendLines($lines);
1536 $lookup = $realname{$program} . ": (.*)";
1537 if ($MakefileData =~ /\n$lookup\n/) {
1538 $lines = "\@KDE_USE_CLOSURE_TRUE@". $realname{$program} . ": $closure $1";
1539 $lines .= "\n\@KDE_USE_CLOSURE_FALSE@" . $realname{$program} . ": $1";
1540 substituteLine($lookup, $lines);
1542 $closure_output .= " $closure";
1546 my %foundfiles = ();
1547 opendir (THISDIR, ".");
1548 foreach $entry (readdir(THISDIR)) {
1549 next if ($entry eq "CVS" || $entry =~ /^\./ || $entry eq "Makefile" || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
1550 next if (! -f $entry);
1551 next if ($entry =~ /\.moc/ || $entry =~ /\.moc.$cppExt$/ || $entry =~ /\.lo$/ || $entry =~ /\.la$/ || $entry =~ /\.o/);
1552 next if ($entry =~ /\.all_$cppExt\.$cppExt$/);
1553 $foundfiles{$entry} = 1;
1557 # doing this for MAINTAINERCLEANFILES would be wrong
1558 my @marks = ("EXTRA_DIST", "DIST_COMMON", '\S*_SOURCES', '\S*_HEADERS', 'CLEANFILES', 'DISTCLEANFILES', '\S*_OBJECTS');
1559 foreach $mark (@marks) {
1560 while ($MakefileData =~ /\n($mark)\s*=\s*([^\n]*)/g) {
1561 foreach $file (split('[\034\s]', $2)) {
1563 $foundfiles{$file} = 0 if (defined $foundfiles{$file});
1567 my @files = ("Makefile", "config.cache", "config.log", "stamp-h",
1568 "stamp-h1", "stamp-h1", "config.h", "Makefile",
1569 "config.status", "config.h", "libtool", "core" );
1570 foreach $file (@files) {
1571 $foundfiles{$file} = 0 if (defined $foundfiles{$file});
1575 foreach $file (keys %foundfiles) {
1576 if ($foundfiles{$file} == 1) {
1577 $KDE_DIST .= "$file ";
1581 print "KDE_DIST $printname $KDE_DIST\n" if ($verbose);
1583 my $lookup = "DISTFILES *=(.*)";
1584 if ($MakefileData =~ /\n$lookup\n/o) {
1585 substituteLine($lookup, "KDE_DIST=$KDE_DIST\n\nDISTFILES=$1 \$(KDE_DIST)\n");
1590 #-----------------------------------------------------------------------------
1591 # Returns 0 if the line was processed - 1 otherwise.
1592 # Errors are logged in the global $errorflags
1595 $target_adds{"all"} .= "docs-am ";
1597 my $lookup = 'KDE_DOCS\s*=\s*([^\n]*)';
1598 goto nodocs if ($MakefileData !~ /\n$lookup/o);
1599 print STDOUT "KDE_DOCS processing <$1>\n" if ($verbose);
1603 # Either find the files in the directory (AUTO) or use
1604 # only the specified po files.
1607 $appname =~ s/^(\S*)\s*.*$/$1/;
1608 if ($appname =~ /AUTO/) {
1609 $appname = basename($makefileDir);
1610 if ("$appname" eq "en") {
1611 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";
1618 opendir (THISDIR, ".");
1619 foreach $entry (readdir(THISDIR)) {
1620 next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/ || $entry eq "core" || $entry eq "index.cache.bz2");
1621 next if (! -f $entry);
1622 $files .= "$entry ";
1625 print STDOUT "docfiles found = $files\n" if ($verbose);
1630 $tmp =~ s/^\S*\s*-\s*//;
1633 goto nodocs if (!$files); # Nothing to do
1635 if ($files =~ /(^| )index\.docbook($| )/) {
1638 my $lookup = 'MEINPROC\s*=';
1639 if ($MakefileData !~ /\n($lookup)/) {
1640 $lines = "MEINPROC=/\$(kde_bindir)/meinproc\n";
1642 $lookup = 'KDE_XSL_STYLESHEET\s*=';
1643 if ($MakefileData !~ /\n($lookup)/) {
1644 $lines .= "KDE_XSL_STYLESHEET=/\$(kde_datadir)/ksgmltools2/customization/kde-chunk.xsl\n";
1646 $lookup = '\nindex.cache.bz2:';
1647 if ($MakefileData !~ /\n($lookup)/) {
1648 $lines .= "index.cache.bz2: \$(srcdir)/index.docbook \$(KDE_XSL_STYLESHEET) $files\n";
1649 $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";
1653 $lines .= "docs-am: index.cache.bz2\n";
1655 $lines .= "install-docs: docs-am install-nls\n";
1656 $lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n";
1657 $lines .= "\t\@if test -f index.cache.bz2; then \\\n";
1658 $lines .= "\techo \$(INSTALL_DATA) index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n";
1659 $lines .= "\t\$(INSTALL_DATA) index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n";
1660 $lines .= "\telif test -f \$(srcdir)/index.cache.bz2; then \\\n";
1661 $lines .= "\techo \$(INSTALL_DATA) \$(srcdir)/index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n";
1662 $lines .= "\t\$(INSTALL_DATA) \$(srcdir)/index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n";
1664 $lines .= "\t-rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n";
1665 $lines .= "\t\$(LN_S) \$(kde_libs_htmldir)/$kdelang/common \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n";
1668 $lines .= "uninstall-docs:\n";
1669 $lines .= "\t-rm -rf \$(kde_htmldir)/$kdelang/$appname\n";
1671 $lines .= "clean-docs:\n";
1672 $lines .= "\t-rm -f index.cache.bz2\n";
1674 $target_adds{"install-data-am"} .= "install-docs ";
1675 $target_adds{"uninstall"} .= "uninstall-docs ";
1676 $target_adds{"clean-am"} .= "clean-docs ";
1677 appendLines ($lines);
1679 appendLines("docs-am: $files\n");
1682 $target_adds{"install-data-am"} .= "install-nls ";
1683 $target_adds{"uninstall"} .= "uninstall-nls ";
1685 $tmp = "install-nls:\n";
1686 $tmp .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n";
1687 $tmp .= "\t\@for base in $files; do \\\n";
1688 $tmp .= "\t echo \$(INSTALL_DATA) \$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1689 $tmp .= "\t \$(INSTALL_DATA) \$(srcdir)/\$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1691 if ($appname eq 'common') {
1692 $tmp .= "\t\@echo \"merging common and language specific dir\" ;\\\n";
1693 $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";
1694 $tmp .= "\t\@com_files=`cd \$(kde_htmldir)/en/common && echo *` ;\\\n";
1695 $tmp .= "\tcd \$(DESTDIR)\$(kde_htmldir)/$kdelang/common ;\\\n";
1696 $tmp .= "\tif test -n \"\$\$com_files\"; then for p in \$\$com_files ; do \\\n";
1697 $tmp .= "\t case \" $files \" in \\\n";
1698 $tmp .= "\t *\" \$\$p \"*) ;; \\\n";
1699 $tmp .= "\t *) test ! -f \$\$p && echo \$(LN_S) ../../en/common/\$\$p \$(DESTDIR)\$(kde_htmldir)/$kdelang/common/\$\$p && \$(LN_S) ../../en/common/\$\$p \$\$p ;; \\\n";
1700 $tmp .= "\t esac ; \\\n";
1701 $tmp .= "\tdone ; fi ; true\n";
1704 $tmp .= "uninstall-nls:\n";
1705 $tmp .= "\tfor base in $files; do \\\n";
1706 $tmp .= "\t rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1707 $tmp .= "\tdone\n\n";
1710 $target_adds{"distdir"} .= "distdir-nls ";
1712 $tmp = "distdir-nls:\n";
1713 $tmp .= "\tfor file in $files; do \\\n";
1714 $tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n";
1722 appendLines("docs-am:\n");
1726 #-----------------------------------------------------------------------------
1727 # Find headers in any of the source directories specified previously, that
1728 # are candidates for "moc-ing".
1729 sub findMocCandidates ()
1731 foreach $dir (@headerdirs)
1734 opendir (SRCDIR, "$dir");
1735 @hFiles = grep { /.+\.$hExt$/o && !/^\./ } readdir(SRCDIR);
1737 foreach $hf (@hFiles)
1739 next if ($hf =~ /^\.\#/);
1740 $hf =~ /(.*)\.[^\.]*$/; # Find name minus extension
1741 next if ($uiFiles{$1});
1742 open (HFIN, "$dir/$hf") || die "Could not open $dir/$hf: $!\n";
1745 $hfsize = tell(HFIN);
1747 read HFIN, $hfData, $hfsize;
1749 # push (@list, $hf) if(index($hfData, "Q_OBJECT") >= 0); ### fast but doesn't handle //Q_OBJECT
1750 if ( $hfData =~ /{([^}]*)Q_OBJECT/s ) { ## handle " { friend class blah; Q_OBJECT "
1751 push (@list, $hf) unless $1 =~ m://[^\n]*Q_OBJECT[^\n]*$:s; ## handle "// Q_OBJECT"
1754 # The assoc array of root of headerfile and header filename
1755 foreach $hFile (@list)
1757 $hFile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1760 print STDERR "Warning: Multiple header files found for $1\n";
1761 next; # Use the first one
1763 $mocFiles{$1} = "$dir\035$hFile"; # Add relative dir
1770 #-----------------------------------------------------------------------------
1772 # The programmer has specified a moc list. Prune out the moc candidates
1773 # list that we found based on looking at the header files. This generates
1774 # a warning if the programmer gets the list wrong, but this doesn't have
1776 sub pruneMocCandidates ($)
1779 local @mocList = split(' ', $_[0]);
1781 foreach $mocname (@mocList)
1783 $mocname =~ s/\.moc$//;
1784 if ($mocFiles{$mocname})
1786 $prunedMoc{$mocname} = $mocFiles{$mocname};
1790 my $print = $makefileDir;
1791 $print =~ s/^\Q$topdir\E\\//;
1792 # They specified a moc file but we can't find a header that
1793 # will generate this moc file. That's possible fatal!
1794 print STDERR "Warning: No moc-able header file for $print/$mocname\n";
1799 %mocFiles = %prunedMoc;
1802 #-----------------------------------------------------------------------------
1804 # Finds the cpp files (If they exist).
1805 # The cpp files get appended to the header file separated by \035
1806 sub checkMocCandidates ()
1809 my $cpp2moc; # which c++ file includes which .moc files
1810 my $moc2cpp; # which moc file is included by which c++ files
1812 return unless (keys %mocFiles);
1813 opendir(THISDIR, ".") || return;
1814 @cppFiles = grep { /.+\.$cppExt$/o && !/.+\.moc\.$cppExt$/o
1815 && !/.+\.all_$cppExt\.$cppExt$/o
1816 && !/^\./ } readdir(THISDIR);
1818 return unless (@cppFiles);
1819 my $files = join (" ", @cppFiles);
1822 foreach $cxxf (@cppFiles)
1824 open (CXXFIN, $cxxf) || die "Could not open $cxxf: $!\n";
1826 my $cxxfsize = tell(CXXFIN);
1828 read CXXFIN, $cxxfData, $cxxfsize;
1830 while(($cxxfData =~ m/^[ \t]*\#include\s*[<\"](.*\.moc)[>\"]/gm)) {
1831 $cpp2moc->{$cxxf}->{$1} = 1;
1832 $moc2cpp->{$1}->{$cxxf} = 1;
1835 foreach my $mocFile (keys (%mocFiles))
1837 @cppFiles = keys %{$moc2cpp->{"$mocFile.moc"}};
1838 if (@cppFiles == 1) {
1839 $mocFiles{$mocFile} .= "\035" . $cppFiles[0];
1840 push(@deped, $mocFile);
1841 } elsif (@cppFiles == 0) {
1842 push (@newObs, $mocFile); # Produce new object file
1843 next if ($haveAutomocTag); # This is expected...
1844 # But this is an error we can deal with - let them know
1846 "Warning: No c++ file that includes $mocFile.moc\n";
1848 # We can't decide which file to use, so it's fatal. Although as a
1849 # guess we could use the mocFile.cpp file if it's in the list???
1851 "Error: Multiple c++ files that include $mocFile.moc\n";
1852 print STDERR "\t",join ("\t", @cppFiles),"\n";
1854 delete $mocFiles{$mocFile};
1855 # Let's continue and see what happens - They have been told!
1860 #-----------------------------------------------------------------------------
1862 # Add the rules for generating moc source from header files
1863 # For Automoc output *.moc.cpp but normally we'll output *.moc
1864 # (We must compile *.moc.cpp separately. *.moc files are included
1865 # in the appropriate *.cpp file by the programmer)
1871 foreach $mocFile (keys (%mocFiles))
1874 ($dir, $hFile, $cppFile) = split ("\035", $mocFiles{$mocFile}, 3);
1875 $dir =~ s#^\.#\$(srcdir)#;
1876 if (defined ($cppFile))
1878 $cppFile =~ s,\.[^.]*$,,;
1879 $target_adds{"$cppFile.o"} .= "$mocFile.moc ";
1880 $target_adds{"$cppFile.lo"} .= "$mocFile.moc ";
1881 appendLines ("$mocFile.moc: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile.moc\n");
1882 $cleanMoc .= " $mocFile.moc";
1886 appendLines ("$mocFile$mocExt: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile$mocExt\n");
1887 $cleanMoc .= " $mocFile$mocExt";
1892 sub make_meta_classes ()
1894 return if ($kdeopts{"qtonly"});
1898 my $moc_class_headers = "";
1899 foreach $program (@programs) {
1901 my @progsources = split(/[\s\034]+/, $sources{$program});
1902 my @depmocs = split(' ', $depedmocs{$program});
1903 my %shash = (), %mhash = ();
1904 @shash{@progsources} = 1; # we are only interested in the existence
1905 @mhash{@depmocs} = 1;
1907 print STDOUT "program=$program\n" if ($verbose);
1908 print STDOUT "psources=[".join(' ', keys %shash)."]\n" if ($verbose);
1909 print STDOUT "depmocs=[".join(' ', keys %mhash)."]\n" if ($verbose);
1910 print STDOUT "globalmocs=[".join(' ', keys(%globalmocs))."]\n" if ($verbose);
1911 foreach my $mocFile (keys (%globalmocs))
1913 my ($dir, $hFile, $cppFile) = split ("\035", $globalmocs{$mocFile}, 3);
1914 if (defined ($cppFile))
1916 $mocs .= " $mocFile.moc" if exists $shash{$cppFile};
1920 # Bah. This is the case, if no C++ file includes the .moc
1921 # file. We make a .moc.cpp file for that. Unfortunately this
1922 # is not included in the %sources hash, but rather is mentioned
1923 # in %depedmocs. If the user wants to use AUTO he can't just
1924 # use an unspecific METAINCLUDES. Instead he must use
1925 # program_METAINCLUDES. Anyway, it's not working real nicely.
1926 # E.g. Its not clear what happens if user specifies two
1927 # METAINCLUDES=AUTO in the same Makefile.am.
1928 $mocs .= " $mocFile.moc.$cxxsuffix"
1929 if exists $mhash{$mocFile.".moc.$cxxsuffix"};
1933 print STDOUT "==> mocs=[".$mocs."]\n" if ($verbose);
1935 print STDOUT "\n" if $verbose;
1937 if ($moc_class_headers) {
1938 appendLines ("$cleantarget-moc-classes:\n\t-rm -f $moc_class_headers\n");
1939 $target_adds{"$cleantarget-am"} .= "$cleantarget-moc-classes ";
1943 #-----------------------------------------------------------------------------
1945 sub updateMakefile ()
1947 return if ($dryrun);
1949 open (FILEOUT, "> $makefile")
1950 || die "Could not create $makefile: $!\n";
1952 $MakefileData =~ s/\034/\\\n/g; # Restore continuation lines
1953 # Append our $progId line, _below_ the "generated by automake" line
1954 # because automake-1.6 relies on the first line to be his own.
1955 my $progIdLine = "\# $progId - " . '$Revision$ '."\n";
1956 if ( !( $MakefileData =~ s/^(.*generated .*by automake.*\n)/$1$progIdLine/ ) ) {
1957 warn "automake line not found in $makefile\n";
1958 # Fallback: first line
1959 print FILEOUT $progIdLine;
1961 print FILEOUT $MakefileData;
1965 #-----------------------------------------------------------------------------
1967 # The given line needs to be removed from the makefile
1968 # Do this by adding the special "removed line" comment at the line start.
1971 my ($lookup, $old) = @_;
1973 $old =~ s/\034/\\\n#>- /g; # Fix continuation lines
1974 $MakefileData =~ s/\n$lookup/\n#>\- $old/;
1977 #-----------------------------------------------------------------------------
1979 # Replaces the old line with the new line
1980 # old line(s) are retained but tagged as removed. The new line(s) have the
1981 # "added" tag placed before it.
1982 sub substituteLine ($$)
1984 my ($lookup, $new) = @_;
1986 if ($MakefileData =~ /\n($lookup)/) {
1988 $old =~ s/\034/\\\n#>\- /g; # Fix continuation lines
1989 $new =~ s/\034/\\\n/g;
1990 my $newCount = ($new =~ tr/\n//) + 1;
1991 $MakefileData =~ s/\n$lookup/\n#>- $old\n#>\+ $newCount\n$new/;
1993 print STDERR "Warning: substitution of \"$lookup\" in $printname failed\n";
1997 #-----------------------------------------------------------------------------
1999 # Slap new lines on the back of the file.
2003 $new =~ s/\034/\\\n/g; # Fix continuation lines
2004 my $newCount = ($new =~ tr/\n//) + 1;
2005 $MakefileData .= "\n#>\+ $newCount\n$new";
2008 #-----------------------------------------------------------------------------
2010 # Restore the Makefile.in to the state it was before we fiddled with it
2011 sub restoreMakefile ()
2013 $MakefileData =~ s/# $progId[^\n\034]*[\n\034]*//g;
2014 # Restore removed lines
2015 $MakefileData =~ s/([\n\034])#>\- /$1/g;
2016 # Remove added lines
2017 while ($MakefileData =~ /[\n\034]#>\+ ([^\n\034]*)/)
2020 my $removeLines = "";
2021 while ($newCount--) {
2022 $removeLines .= "[^\n\034]*([\n\034]|)";
2024 $MakefileData =~ s/[\n\034]#>\+.*[\n\034]$removeLines/\n/;
2028 #-----------------------------------------------------------------------------