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 ...
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 from automake\n",
121 "(where dir can be a full or relative directory name)",
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";
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 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
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 $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
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) {
270 if ($source_dict{$source}) {
273 print STDERR
"Error: $source is listed in a _SOURCE line in $printname, but doesn't exist yet. Put it in DISTCLEANFILES!\n";
275 $target_adds{"\$(srcdir)/$source"} .= $important{$program};
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"});
292 appendLines
("$cleantarget-idl:\n\t-rm -f $idl_output\n");
293 $target_adds{"$cleantarget-am"} .= "$cleantarget-idl ";
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)'
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
318 my $tmp = "force-reedit:\n";
319 $tmp .= "\t$automkCall\n\tcd \$(top_srcdir) && perl $thisProg $printname\n\n";
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]*";
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)\" ";
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) {
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";
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/) {
391 $newdeps =~ s/\s*install-kde_moduleLTLIBRARIES\s*/ /g;
392 substituteLine
($lookup, "install-data-am: " . $newdeps);
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);
403 $lines .= "$add: " . $target_adds{$add} . "\n";
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);
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
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.
460 if (! -r
"Makefile.am") {
461 print STDOUT
"found Makefile.in without Makefile.am\n" if ($verbose);
465 # Checking for files to process...
466 open (FILEIN
, $makefile)
467 || die "Could not open $makefileDir/$makefile: $!\n";
469 # stat(FILEIN)[7] might look more elegant, but is slower as it
470 # requires stat'ing the file
472 my $fsize = tell(FILEIN
);
474 read FILEIN
, $MakefileData, $fsize;
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) {
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";
513 # Look for the tags that mean we should process this file.
515 $metasourceTags++ while ($MakefileData =~ /\n[^=\#]*METASOURCES\s*=/g);
518 $pofileTag++ while ($MakefileData =~ /\nPOFILES\s*=/g);
521 print STDERR
"Error: Only one POFILES tag allowed\n";
525 while ($MakefileData =~ /\n\.SUFFIXES:([^\n]+)\n/g) {
526 my @list=split(' ', $1);
527 foreach $ext (@list) {
528 if ($ext =~ /^\.$cppExt$/) {
530 $cxxsuffix =~ s/\.//g;
531 print STDOUT
"will use suffix $cxxsuffix\n" if ($verbose);
537 while ($MakefileData =~ /\n(\S*)_OBJECTS\s*=[ \t\034]*([^\n]*)\n/g) {
540 my $objs = $2; # safe them
544 my @objlist = split(/[\s\034]+/, $objs);
545 foreach $obj (@objlist) {
546 if ($obj =~ /\$\((\S+)\)/ ) {
548 if ($variable !~ 'OBJEXT') {
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;
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;
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)) {
597 push(@cleanfiles, $file);
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);
619 removeLine
($lookup, $1);
621 $headerStr =~ tr/\034/ /;
622 my @headerlist = split(' ', $headerStr);
624 foreach $dir (@headerlist)
626 $dir =~ s
#\$\(srcdir\)#.#;
629 print STDERR
"Warning: $dir can't be found. ",
630 "Must be a relative path to \$(srcdir)\n";
634 push (@headerdirs, $dir);
641 #-----------------------------------------------------------------------------
645 my @final_names = ();
647 foreach $program (@programs) {
649 if ($sources{$program} =~ /\(/) {
650 print STDOUT
"found ( in $program\_SOURCES. skipping\n" if ($verbose);
656 my @progsources = split(/[\s\034]+/, $sources{$program});
659 foreach $source (@progsources) {
660 my $suffix = $source;
661 $suffix =~ s/^.*\.([^\.]+)$/$1/;
663 if (defined($sourcelist{$suffix})) {
664 $sourcelist{$suffix} .= " " . $source;
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)$/) {
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$/ ) {
692 foreach $file (@sourcelist) {
694 $file =~ s/\Q$suffix\E$//;
696 $finalObjs{$program} .= $file;
697 if ($program =~ /_la$/) {
698 $finalObjs{$program} .= "lo ";
700 $finalObjs{$program} .= "o ";
706 my $source_deps = "";
707 foreach $source (@sourcelist) {
709 $source_deps .= "\$(srcdir)/$source ";
711 $source_deps .= "$source ";
715 $handling = "$program.all_$suffix.$suffix: \$(srcdir)/Makefile.in " . $source_deps . " ";
718 $handling .= $depedmocs{$program};
719 foreach $mocfile (split(' ', $depedmocs{$program})) {
721 if ($mocfile =~ m/\.$suffix$/) {
722 $mocsources .= " " . $mocfile;
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 ";
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);
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 = ();
775 foreach $source (@progsources) {
779 $sdeps = "\$(srcdir)/$source";
783 foreach $depend (@compilefirst) {
784 next if ($source eq $depend);
785 # avoid cyclic dependencies
786 next if defined($donesources{$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
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 = ();
815 if ($metasourceTags > 1) {
816 $lookup = $program . '_METASOURCES\s*=\s*(.*)';
817 return 1 if ($MakefileData !~ /\n($lookup)\n/);
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);
825 $metasourceTags = 0; # we can use the general target only once
830 print STDOUT
"METASOURCE processing <$found>)\n" if ($verbose);
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";
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
855 pruneMocCandidates
($postEqual);
858 checkMocCandidates
();
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
/);
869 $depedmocs{$program} .= " ";
870 $depedmocs{$program} .= join('.moc ', @deped) . ".moc";
871 $depedmocs{$program} .= " ";
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
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);
893 #-----------------------------------------------------------------------------
895 sub handle_TOPLEVEL
()
899 opendir (THISDIR
, ".");
900 foreach $entry (readdir(THISDIR
)) {
903 next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/ || $entry =~ /.gmo$/);
905 if ($entry =~ /\.po$/) {
908 push(@restfiles, $entry);
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";
930 #-----------------------------------------------------------------------------
934 if ($MakefileData !~ /\nSUBDIRS\s*=\s*\$\(AUTODIRS\)\s*\n/) {
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";
950 my $lines = "SUBDIRS =$subdirs\n";
951 substituteLine
('SUBDIRS\s*=.*', $lines);
957 my @psources = split(/[\034\s]+/, $sources{$program});
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)$//;
980 $sourcename = "$source\_skel";
982 $sourcename = "$source\_stub";
984 $sourcename = "$source\_signals";
988 if (-f
"$makefileDir/$source.h") {
989 $sourcedir = '$(srcdir)/';
991 if ($MakefileData =~ /\n$source\_DIR\s*=\s*(\S+)\n/) {
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 = "";
1010 $dep_lines .= "$sourcename.$cxxsuffix: $source.kidl\n";
1011 $dep_lines .= "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-signals --no-stub $source.kidl\n";
1013 $dep_lines_tmp = "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-signals --no-skel $source.kidl\n";
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";
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
/);
1045 appendLines
($dep_lines);
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 ";
1061 substituteLine
($lookup, $line);
1063 print STDERR
"no built dependency found $lookup\n";
1070 my @psources = split(/[\034\s]+/, $sources{$program});
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$//;
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";
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";
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
/ );
1130 appendLines
($dep_lines);
1136 my $lookup = '([^\s]*)_ICON\s*=\s*([^\n]*)';
1140 while ($MakefileData =~ /\n$lookup/og) {
1143 $destdir = "kde_icondir";
1145 $destdir = $1 . "dir";
1147 my $iconauto = ($2 =~ /AUTO\s*$/);
1149 if ( ! $iconauto ) {
1150 my @_appnames = split(" ", $2);
1151 print STDOUT
"KDE_ICON processing <@_appnames>\n" if ($verbose);
1152 foreach $appname (@_appnames) {
1153 push(@appnames, quotemeta($appname));
1156 print STDOUT
"KDE_ICON processing <AUTO>\n" if ($verbose);
1160 opendir (THISDIR
, ".");
1161 foreach $entry (readdir(THISDIR
)) {
1162 next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
1163 next if (! -f
$entry);
1166 push(@files, $entry)
1167 if ($entry =~ /\.xpm/ || $entry =~ /\.png/ || $entry =~ /\.mng/);
1169 foreach $appname (@appnames) {
1170 push(@files, $entry)
1171 if ($entry =~ /-$appname\.xpm/ || $entry =~ /-$appname\.png/ || $entry =~ /-$appname\.mng/);
1177 my %directories = ();
1179 foreach $file (@files) {
1180 my $newfile = $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$//;
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/^...$/);
1196 $type =~ s/^.*-([^-]+)$/$1/;
1197 $prefix =~ s/^(.*)-[^-]+$/$1/;
1201 'action' => 'actions',
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";
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";
1237 my $dir = $dir_hash{$prefix} . "/" . $type_hash{$type};
1238 if ($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(" ", $_[0]);
1268 # Build rules for creating the gmo files
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";
1282 my $lookup = 'POFILES\s*=([^\n]*)';
1283 if ($MakefileData !~ /\n$lookup/o) {
1284 appendLines
("$pofileLine\nGMOFILES =$allgmofiles");
1286 substituteLine
($lookup, "$pofileLine\nGMOFILES =$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";
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
1316 $tmp .= "; do \\\n";
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"
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";
1328 $target_adds{"uninstall"} .= "uninstall-nls ";
1330 $tmp = "uninstall-nls:\n";
1331 foreach $pofile (@pofiles)
1333 $pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1335 $tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/$1.mo\n";
1337 $tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$1/LC_MESSAGES/\$(PACKAGE).mo\n";
1342 $target_adds{"all"} .= "all-nls ";
1344 $tmp = "all-nls: \$(GMOFILES)\n";
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";
1354 $tmp .= "\tfor file in \$(GMOFILES); do \\\n";
1355 $tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n";
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
1372 my $lookup = 'POFILES\s*=([^\n]*)';
1373 return 1 if ($MakefileData !~ /\n$lookup/o);
1374 print STDOUT
"POFILES processing <$1>\n" if ($verbose);
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";
1385 # Either find the pofiles in the directory (AUTO) or use
1386 # only the specified po files.
1388 if ($tmp =~ /^\s*AUTO\s*$/)
1390 opendir (THISDIR
, ".");
1391 $pofiles = join(" ", grep(/\.po$/, readdir(THISDIR
)));
1393 print STDOUT
"pofiles found = $pofiles\n" if ($verbose);
1394 if (-f
"charset" && -f
"kdelibs.po") {
1403 return 1 if (!$pofiles); # Nothing to do
1405 handle_POFILES
($pofiles, $kdelang);
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//;
1419 while (! $emptyline) {
1420 if ($install =~ /([^\035]*)\035(.*)/) {
1423 if ($line !~ /^\s*$/ && $line !~ /^(\@.*\@)*\t/) {
1426 replaceDestDir
($line);
1436 sub tag_LOCALINSTALL
()
1438 helper_LOCALINSTALL
('install-exec-local');
1439 helper_LOCALINSTALL
('install-data-local');
1440 helper_LOCALINSTALL
('uninstall-local');
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);
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";
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";
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;
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)) {
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;
1525 foreach $file (keys %foundfiles) {
1526 if ($foundfiles{$file} == 1) {
1527 $KDE_DIST .= "$file ";
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
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");
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);
1563 # Either find the files in the directory (AUTO) or use
1564 # only the specified po files.
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";
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 ";
1585 print STDOUT
"docfiles found = $files\n" if ($verbose);
1590 $tmp =~ s/^\S*\s*-\s*//;
1593 goto nodocs
if (!$files); # Nothing to do
1595 if ($files =~ /(^| )index\.docbook($| )/) {
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";
1613 $lines .= "docs-am: index.cache.bz2\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";
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";
1625 $lines .= "uninstall-docs:\n";
1626 $lines .= "\t-rm -rf \$(kde_htmldir)/$kdelang/$appname\n";
1628 $lines .= "clean-docs:\n";
1629 $lines .= "\t-rm -f index.cache.bz2\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);
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";
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";
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";
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";
1679 appendLines
("docs-am:\n");
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)
1691 opendir (SRCDIR
, "$dir");
1692 @hFiles = grep { /.+\.$hExt$/o && !/^\./ } readdir(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";
1702 $hfsize = tell(HFIN
);
1704 read HFIN
, $hfData, $hfsize;
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
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
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
1733 sub pruneMocCandidates
($)
1736 local @mocList = split(' ', $_[0]);
1738 foreach $mocname (@mocList)
1740 $mocname =~ s/\.moc$//;
1741 if ($mocFiles{$mocname})
1743 $prunedMoc{$mocname} = $mocFiles{$mocname};
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";
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
()
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
);
1775 return unless (@cppFiles);
1776 my $files = join (" ", @cppFiles);
1779 foreach $cxxf (@cppFiles)
1781 open (CXXFIN
, $cxxf) || die "Could not open $cxxf: $!\n";
1783 my $cxxfsize = tell(CXXFIN
);
1785 read CXXFIN
, $cxxfData, $cxxfsize;
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
1803 "Warning: No c++ file that includes $mocFile.moc\n";
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???
1808 "Error: Multiple c++ files that include $mocFile.moc\n";
1809 print STDERR
"\t",join ("\t", @cppFiles),"\n";
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)
1828 foreach $mocFile (keys (%mocFiles))
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";
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"});
1853 my $moc_class_headers = "";
1854 foreach $program (@programs) {
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))
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};
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"};
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";
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";
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;
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.
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)/) {
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/;
1967 print STDERR
"Warning: substitution of \"$lookup\" in $printname failed\n";
1971 #-----------------------------------------------------------------------------
1973 # Slap new lines on the back of the file.
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]*)/)
1994 my $removeLines = "";
1995 while ($newCount--) {
1996 $removeLines .= "[^\n\034]*([\n\034]|)";
1998 $MakefileData =~ s/[\n\034]#>\+.*[\n\034]$removeLines/\n/;
2002 #-----------------------------------------------------------------------------