Latest updates from Keith for xsldbg 3.0.5.
[kdbg.git] / admin / am_edit
blobf1f0026e2d94d9cc856fb1f53224e6c62e69dab1
1 #!/usr/bin/perl
3 # Expands the specilised KDE tags in Makefile.in to (hopefully) valid
4 # make syntax.
5 # When called without file parameters, we work recursively on all Makefile.in
6 # in and below the current subdirectory. When called with file parameters,
7 # only those Makefile.in are changed.
8 # The currently supported tags are
10 # {program}_METASOURCES
11 # where you have a choice of two styles
12 # {program}_METASOURCES = name1.moc name2.moc ... [\]
13 # {program}_METASOURCES = AUTO
14 # The second style requires other tags as well.
16 # To install icons :
17 # KDE_ICON = iconname iconname2 ...
18 # KDE_ICON = AUTO
20 # For documentation :
21 # ...
23 # and more new tags TBD!
25 # The concept (and base code) for this program came from automoc,
26 # supplied by the following
28 # Matthias Ettrich <ettrich\@kde.org> (The originator)
29 # Kalle Dalheimer <kalle\@kde.org> (The original implementator)
30 # Harri Porten <porten@tu-harburg.de>
31 # Alex Zepeda <garbanzo@hooked.net>
32 # David Faure <faure@kde.org>
33 # Stephan Kulow <coolo@kde.org>
35 # I've puddled around with automoc and produced something different
36 # 1999-02-01 John Birch <jb.nz@writeme.com>
37 # * Rewritten automoc to cater for more than just moc file expansion
38 # Version 0.01 does the same as automoc at this stage.
39 # 1999-02-18 jb
40 # * We must always write a Makefile.in file out even if we fail
41 # because we need the "perl autokmake" in the AUTOMAKE so that a
42 # "make" will regenerate the Makefile.in correctly.
43 # Reworked moc file checking so that missing includes in cpp
44 # will work and includes in cpp when using use_automoc will also
45 # work.
46 # 1999-02-23 jb
47 # * Added POFILE processing and changed the USE_AUTOMOC tag to
48 # AUTO instead.
49 # ... See ChangeLog for more logs
51 use Cwd;
52 use File::Find;
53 use File::Basename;
55 # Prototype the functions
56 sub initialise ();
57 sub processMakefile ($);
58 sub updateMakefile ();
59 sub restoreMakefile ();
61 sub removeLine ($$);
62 sub appendLines ($);
63 sub substituteLine ($$);
65 sub findMocCandidates ();
66 sub pruneMocCandidates ($);
67 sub checkMocCandidates ();
68 sub addMocRules ();
70 sub tag_AUTOMAKE ();
71 sub tag_META_INCLUDES ();
72 sub tag_METASOURCES ();
73 sub tag_POFILES ();
74 sub tag_DOCFILES ();
75 sub tag_LOCALINSTALL();
76 sub tag_IDLFILES();
77 sub tag_UIFILES();
78 sub tag_TOPLEVEL();
79 sub tag_SUBDIRS();
80 sub tag_ICON();
81 sub tag_CLOSURE();
82 sub tag_DIST();
84 # Some global globals...
85 $verbose = 0; # a debug flag
86 $thisProg = "$0"; # This programs name
87 $topdir = cwd(); # The current directory
88 @makefiles = (); # Contains all the files we'll process
89 @foreignfiles = ();
90 $start = (times)[0]; # some stats for testing - comment out for release
91 $version = "v0.2";
92 $errorflag = 0;
93 $cppExt = "*.cpp *.cc *.cxx *.C *.c++"; # used by grep
94 $hExt = "*.h *.H *.hh *.hxx *.h++"; # used by grep
95 $progId = "KDE tags expanded automatically by " . basename($thisProg);
96 $automkCall = "\n";
97 $printname = ""; # used to display the directory the Makefile is in
98 $use_final = 1; # create code for --enable-final
99 $cleantarget = "clean";
100 $dryrun = 0;
101 $pathoption = 0;
103 while (defined ($ARGV[0]))
105 $_ = shift;
106 if (/^--version$/)
108 print STDOUT "\n";
109 print STDOUT basename($thisProg), " $version\n",
110 "This is really free software, unencumbered by the GPL.\n",
111 "You can do anything you like with it except sueing me.\n",
112 "Copyright 1998 Kalle Dalheimer <kalle\@kde.org>\n",
113 "Concept, design and unnecessary questions about perl\n",
114 " by Matthias Ettrich <ettrich\@kde.org>\n\n",
115 "Making it useful by Stephan Kulow <coolo\@kde.org> and\n",
116 "Harri Porten <porten\@kde.org>\n",
117 "Updated (Feb-1999), John Birch <jb.nz\@writeme.com>\n",
118 "Current Maintainer Stephan Kulow\n\n";
119 exit 0;
121 elsif (/^--verbose$|^-v$/)
123 $verbose = 1; # Oh is there a problem...?
125 elsif (/^-p(.+)$|^--path=(.+)$/)
127 $thisProg = "$1/".basename($thisProg) if($1);
128 $thisProg = "$2/".basename($thisProg) if($2);
129 warn ("$thisProg doesn't exist\n") if (!(-f $thisProg));
130 $pathoption=1;
132 elsif (/^--help$|^-h$/)
134 print STDOUT "Usage $thisProg [OPTION] ... [dir/Makefile.in]...\n",
135 "\n",
136 "Patches dir/Makefile.in generated from automake\n",
137 "(where dir can be a full or relative directory name)",
138 "\n",
139 " -v, --verbose verbosely list files processed\n",
140 " -h, --help print this help, then exit\n",
141 " --version print version number, then exit\n",
142 " -p, --path= use the path to am_edit if the path\n",
143 " --no-final don't patch for --enable-final\n",
144 " called from is not the one to be used\n";
146 exit 0;
148 elsif (/^--no-final$/)
150 $use_final = 0;
151 $thisProg .= " --no-final";
153 elsif (/^-n$/)
155 $dryrun = 1;
157 else
159 # user selects what input files to check
160 # add full path if relative path is given
161 $_ = cwd()."/".$_ if (! /^\//);
162 print "User wants $_\n" if ($verbose);
163 push (@makefiles, $_);
167 if ($thisProg =~ /^\// && !$pathoption )
169 print STDERR "Illegal full pathname call performed...\n",
170 "The call to \"$thisProg\"\nwould be inserted in some Makefile.in.\n",
171 "Please use option --path.\n";
172 exit 1;
175 # Only scan for files when the user hasn't entered data
176 if (!@makefiles)
178 print STDOUT "Scanning for Makefile.in\n" if ($verbose);
179 find (\&add_makefile, cwd());
180 #chdir('$topdir');
181 } else {
182 print STDOUT "Using user enter input files\n" if ($verbose);
185 foreach $makefile (sort(@makefiles))
187 processMakefile ($makefile);
188 last if ($errorflag);
191 # Just some debug statistics - comment out for release as it uses printf.
192 printf STDOUT "Time %.2f CPU sec\n", (times)[0] - $start if ($verbose);
194 exit $errorflag; # causes make to fail if erroflag is set
196 #-----------------------------------------------------------------------------
198 # In conjunction with the "find" call, this builds the list of input files
199 sub add_makefile ()
201 push (@makefiles, $File::Find::name) if (/Makefile.in$/);
204 #-----------------------------------------------------------------------------
206 # Processes a single make file
207 # The parameter contains the full path name of the Makefile.in to use
208 sub processMakefile ($)
210 # some useful globals for the subroutines called here
211 local ($makefile) = @_;
212 local @headerdirs = ('.');
213 local $haveAutomocTag = 0;
214 local $MakefileData = "";
216 local $cxxsuffix = "KKK";
218 local @programs = (); # lists the names of programs and libraries
219 local $program = "";
221 local %realObjs = (); # lists the objects compiled into $program
222 local %sources = (); # lists the sources used for $program
223 local %finalObjs = (); # lists the objects compiled when final
224 local %realname = (); # the binary name of program variable
225 local %idlfiles = (); # lists the idl files used for $program
226 local %globalmocs = ();# list of all mocfiles (in %mocFiles format)
227 local %important = (); # list of files to be generated asap
229 local $allidls = "";
230 local $alluis = "";
231 local $idl_output = "";# lists all idl generated files for cleantarget
232 local $ui_output = "";# lists all uic generated files for cleantarget
233 local $ui_mocs = "";# lists all moc files associated with generated uic files
235 local %depedmocs = ();
237 local $metasourceTags = 0;
238 local $dep_files = "";
239 local $dep_finals = "";
240 local %target_adds = (); # the targets to add
241 local $kdelang = "";
242 local @cleanfiles = ();
243 local $cleanMoc = "";
244 local $closure_output = "";
246 $makefileDir = dirname($makefile);
247 chdir ($makefileDir);
248 $printname = $makefile;
249 $printname =~ s/^\Q$topdir\E\///;
250 $makefile = basename($makefile);
252 print STDOUT "Processing makefile $printname\n" if ($verbose);
254 # Setup and see if we need to do this.
255 return if (!initialise());
257 tag_AUTOMAKE (); # Allows a "make" to redo the Makefile.in
258 tag_META_INCLUDES (); # Supplies directories for src locations
260 foreach $program (@programs) {
261 $sources_changed{$program} = 0;
262 $depedmocs{$program} = "";
263 $important{$program} = "";
264 tag_IDLFILES(); # Sorts out idl rules
265 tag_UIFILES(); # Sorts out ui rules
266 tag_CLOSURE();
267 tag_METASOURCES (); # Sorts out the moc rules
268 if ($sources_changed{$program}) {
269 my $lookup = "$program" . '_SOURCES\s*=\s*(.*)';
270 substituteLine($lookup, "$program\_SOURCES=" . $sources{$program});
272 if ($important{$program}) {
273 local %source_dict = ();
274 for $source (split(/[\034\s]+/, $sources{$program})) {
275 $source_dict{$source} = 1;
277 for $source (@cleanfiles) {
278 $source_dict{$source} = 0;
280 for $source (keys %source_dict) {
281 next if (!$source);
282 if ($source_dict{$source}) {
283 # sanity check
284 if (! -f $source) {
285 print STDERR "Error: $source is listed in a _SOURCE line in $printname, but doesn't exist yet. Put it in DISTCLEANFILES!\n";
286 } else {
287 $target_adds{"\$(srcdir)/$source"} .= $important{$program};
293 if ($cleanMoc) {
294 # Always add dist clean tag
295 # Add extra *.moc.cpp files created for USE_AUTOMOC because they
296 # aren't included in the normal *.moc clean rules.
297 appendLines ("$cleantarget-metasources:\n\t-rm -f $cleanMoc\n");
298 $target_adds{"$cleantarget-am"} .= "$cleantarget-metasources ";
300 tag_DIST();
302 if ($idl_output) {
303 appendLines ("$cleantarget-idl:\n\t-rm -f $idl_output\n");
304 $target_adds{"$cleantarget-am"} .= "$cleantarget-idl ";
307 if ($ui_output) {
308 appendLines ("$cleantarget-ui:\n\t-rm -f $ui_output\n");
309 $target_adds{"$cleantarget-am"} .= "$cleantarget-ui ";
312 if ($closure_output) {
313 appendLines ("$cleantarget-closures:\n\t-rm -f $closure_output\n");
314 $target_adds{"$cleantarget-am"} .= "$cleantarget-closures ";
317 if ($MakefileData =~ /\nKDE_LANG\s*=\s*(\S*)\s*\n/) {
318 $kdelang = '$(KDE_LANG)'
319 } else {
320 $kdelang = '';
323 tag_POFILES (); # language rules for po directory
324 tag_DOCFILES (); # language rules for doc directories
325 tag_TOPLEVEL (); # language rules for po toplevel
326 tag_LOCALINSTALL(); # add $(DESTDIR) before all kde_ dirs
327 tag_ICON();
329 my $tmp = "force-reedit:\n";
330 $tmp .= "\t$automkCall\n\tcd \$(top_srcdir) && perl $thisProg $printname\n\n";
331 appendLines($tmp);
333 make_meta_classes();
334 tag_FINAL() if (!$kdeopts{"nofinal"});
336 my $final_lines = "final:\n\t\$(MAKE) ";
337 my $nofinal_lines = "no-final:\n\t\$(MAKE) ";
339 foreach $program (@programs) {
341 my $lookup = "$program\_OBJECTS.*=[^\n]*";
343 my $new = "";
345 my @list = split(/[\034\s]+/, $realObjs{$program});
347 if (!$kdeopts{"nofinal"} && @list > 1 && $finalObjs{$program}) {
349 $new .= "$program\_final\_OBJECTS = " . $finalObjs{$program};
350 $new .= "\n$program\_nofinal\_OBJECTS = " . $realObjs{$program};
351 $new .= "\n\@KDE_USE_FINAL_FALSE\@$program\_OBJECTS = \$($program\_nofinal\_OBJECTS)";
352 $new .= "\n\@KDE_USE_FINAL_TRUE\@$program\_OBJECTS = \$($program\_final\_OBJECTS)";
354 $final_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" ";
355 $nofinal_lines .= "$program\_OBJECTS=\"\$($program\_nofinal\_OBJECTS)\" ";
356 } else {
357 $new = "$program\_OBJECTS = " . $realObjs{$program};
359 substituteLine ($lookup, $new);
361 appendLines($final_lines . "all-am");
362 appendLines($nofinal_lines . "all-am");
364 my $lookup = 'DEP_FILES\s*=([^\n]*)';
365 if ($MakefileData =~ /\n$lookup\n/) {
366 $depfiles = $1;
368 if ($dep_finals) {
369 $lines = "\@KDE_USE_FINAL_TRUE\@DEP_FILES = $dep_files $dep_finals \034\t$depfiles\n";
370 $lines .= "\@KDE_USE_FINAL_FALSE\@DEP_FILES = $dep_files $depfiles\n";
371 } else {
372 $lines = "DEP_FILES = $dep_files $depfiles\n";
375 substituteLine($lookup, $lines);
378 my $cvs_lines = "cvs-clean:\n";
379 $cvs_lines .= "\t\$(MAKE) -f \$(top_srcdir)/admin/Makefile.common cvs-clean\n";
380 appendLines($cvs_lines);
382 $cvs_lines = "kde-rpo-clean:\n";
383 $cvs_lines .= "\t-rm -f *.rpo\n";
384 appendLines($cvs_lines);
385 $target_adds{"clean"} .= "kde-rpo-clean ";
387 my $lines = "";
389 foreach $add (keys %target_adds) {
390 my $lookup = quotemeta($add) . ":\s*(.*)";
391 if ($MakefileData =~ /\n$lookup\n/) {
392 substituteLine($lookup, "$add: " . $target_adds{$add} . $1);
393 } else {
394 $lines .= "$add: " . $target_adds{$add} . "\n";
397 if ($lines) {
398 appendLines($lines);
401 my $found = 1;
403 while ($found) {
404 if ($MakefileData =~ m/\n(.*)\$\(CXXFLAGS\)(.*)\n/) {
405 my $vor = $1;
406 my $nach = $2;
407 my $lookup = quotemeta("$1\$(CXXFLAGS)$2");
408 my $replacement = "$1\$(KCXXFLAGS)$2";
409 $MakefileData =~ s/$lookup/$replacement/;
410 $lookup =~ s/\\\$\\\(CXXFLAGS\\\)/\\\$\\\(KCXXFLAGS\\\)/;
411 $replacement = "$vor\$(KCXXFLAGS) \$(KDE_CXXFLAGS)$nach";
412 substituteLine($lookup, $replacement);
413 } else {
414 $found = 0;
418 $lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=link) (\$\(CXXLD\).*\$\(KCXXFLAGS\))';
420 if ($MakefileData =~ m/$lookup/ ) {
421 $MakefileData =~ s/$lookup/$1 --tag=CXX $2/;
424 $lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=compile) (\$\(CXX\).*\$\(KCXXFLAGS\))';
425 if ($MakefileData =~ m/$lookup/ ) {
426 $MakefileData =~ s/$lookup/$1 --tag=CXX $2/;
429 $MakefileData =~ s/\$\(KCXXFLAGS\)/\$\(CXXFLAGS\)/g;
431 $lookup = '(.*)cp -pr \$\$/\$\$file \$\(distdir\)/\$\$file(.*)';
432 if ($MakefileData =~ m/$lookup/) {
433 substituteLine($lookup, "$1cp -pr \$\$d/\$\$file \$(distdir)/\$\$file$2");
436 # Always update the Makefile.in
437 updateMakefile ();
438 return;
441 #-----------------------------------------------------------------------------
443 # Check to see whether we should process this make file.
444 # This is where we look for tags that we need to process.
445 # A small amount of initialising on the tags is also done here.
446 # And of course we open and/or create the needed make files.
447 sub initialise ()
449 if (! -r "Makefile.am") {
450 print STDOUT "found Makefile.in without Makefile.am\n" if ($verbose);
451 return 0;
454 # Checking for files to process...
455 open (FILEIN, $makefile)
456 || die "Could not open $makefileDir/$makefile: $!\n";
457 # Read the file
458 while ( <FILEIN> )
460 $MakefileData .= $_;
461 if ($_ =~ /\r\n$/) {
462 die "DOS-Linefeeds within $makefileDir/$makefile!\n";
465 close FILEIN;
467 # Remove the line continuations, but keep them marked
468 # Note: we lose the trailing spaces but that's ok.
469 $MakefileData =~ s/\\\s*\n/\034/g;
471 # If we've processed the file before...
472 restoreMakefile () if ($MakefileData =~ /$progId/);
474 foreach $dir (@foreignfiles) {
475 if (substr($makefileDir,0,length($dir)) eq $dir) {
476 return 0;
480 %kdeopts = ();
481 $kdeopts{"foreign"} = 0;
482 $kdeopts{"qtonly"} = 0;
483 $kdeopts{"nofinal"} = !$use_final; # default
485 if ($MakefileData =~ /\nKDE_OPTIONS\s*=\s*([^\n]*)\n/) {
486 local @kde_options = split(/[\s\034]/, $1);
487 if (grep(/^foreign$/, @kde_options)) {
488 push(@foreignfiles, $makefileDir . "/");
489 return 0; # don't touch me
491 for $opt (@kde_options) {
492 if (!defined $kdeopts{$opt}) {
493 print STDERR "Warning: unknown option $opt in $printname\n";
494 } else {
495 $kdeopts{$opt} = 1;
500 # Look for the tags that mean we should process this file.
501 $metasourceTags = 0;
502 $metasourceTags++ while ($MakefileData =~ /\n[^=\#]*METASOURCES\s*=/g);
504 my $pofileTag = 0;
505 $pofileTag++ while ($MakefileData =~ /\nPOFILES\s*=/g);
506 if ($pofileTag > 1)
508 print STDERR "Error: Only one POFILES tag allowed\n";
509 $errorflag = 1;
512 while ($MakefileData =~ /\n\.SUFFIXES:([^\n]+)\n/g) {
513 my @list=split(' ', $1);
514 my $extions = " " . $cppExt . " ";
515 foreach $ext (@list) {
516 if ($extions =~ / \*\Q$ext\E /) {
517 $cxxsuffix = $ext;
518 $cxxsuffix =~ s/\.//g;
519 print STDOUT "will use suffix $cxxsuffix\n" if ($verbose);
520 last;
525 while ($MakefileData =~ /\n(\S*)_OBJECTS\s*=[ \t\034]*([^\n]*)\n/g) {
527 my $program = $1;
528 my $objs = $2; # safe them
530 my $ocv = 0;
532 my @objlist = split(/[\s\034]+/, $objs);
533 foreach $obj (@objlist) {
534 if ($obj =~ /\$\((\S+)\)/ ) {
535 my $variable = $1;
536 if ($variable !~ 'OBJEXT') {
537 $ocv = 1;
542 next if ($ocv);
544 $program =~ s/^am_// if ($program =~ /^am_/);
546 print STDOUT "found program $program\n" if ($verbose);
547 push(@programs, $program);
549 $realObjs{$program} = $objs;
551 if ($MakefileData =~ /\n$program\_SOURCES\s*=\s*(.*)\n/) {
552 $sources{$program} = $1;
553 } else {
554 $sources{$program} = "";
555 print STDERR "found program with no _SOURCES: $program\n";
558 my $realprogram = $program;
559 $realprogram =~ s/_/./g; # unmask to regexp
560 if ($MakefileData =~ /\n($realprogram)(\$\(EXEEXT\)?)?:.*\$\($program\_OBJECTS\)/) {
561 $realname{$program} = $1;
562 } else {
563 # not standard Makefile - nothing to worry about
564 $realname{$program} = "";
568 my $lookup = '\nDEPDIR\s*=.*';
569 if ($MakefileData !~ /($lookup)\n/) {
570 $lookup = '\nbindir\s*=.*';
571 if ($MakefileData =~ /($lookup)\n/) {
572 substituteLine ($lookup, "DEPDIR = .deps\n$1");
574 } else {
575 print STDERR "$printname defines DEPDIR. This means you're using automake > 1.4 - this is not supported!\n";
578 my @marks = ('MAINTAINERCLEANFILES', 'CLEANFILES', 'DISTCLEANFILES');
579 foreach $mark (@marks) {
580 while ($MakefileData =~ /\n($mark)\s*=\s*([^\n]*)/g) {
581 foreach $file (split('[\034\s]', $2)) {
582 $file =~ s/\.\///;
583 push(@cleanfiles, $file);
588 my $localTag = 0;
589 $localTag++ if ($MakefileData =~ /\ninstall-\S+-local:/);
591 return (!$errorflag);
594 #-----------------------------------------------------------------------------
596 # Gets the list of user defined directories - relative to $srcdir - where
597 # header files could be located.
598 sub tag_META_INCLUDES ()
600 my $lookup = '[^=\n]*META_INCLUDES\s*=\s*(.*)';
601 return 1 if ($MakefileData !~ /($lookup)\n/);
602 print STDOUT "META_INCLUDE processing <$1>\n" if ($verbose);
604 my $headerStr = $2;
605 removeLine ($lookup, $1);
607 $headerStr =~ tr/\034/ /;
608 my @headerlist = split(' ', $headerStr);
610 foreach $dir (@headerlist)
612 $dir =~ s#\$\(srcdir\)#.#;
613 if (! -d $dir)
615 print STDERR "Warning: $dir can't be found. ",
616 "Must be a relative path to \$(srcdir)\n";
618 else
620 push (@headerdirs, $dir);
624 return 0;
627 #-----------------------------------------------------------------------------
629 sub tag_FINAL()
631 my @final_names = ();
633 foreach $program (@programs) {
635 if ($sources{$program} =~ /\(/) {
636 print STDOUT "found ( in $program\_SOURCES. skipping\n" if ($verbose);
637 next;
640 my $mocsources = "";
642 my @progsources = split(/[\s\034]+/, $sources{$program});
643 my %sourcelist = ();
645 foreach $source (@progsources) {
646 my $suffix = $source;
647 $suffix =~ s/^.*\.([^\.]+)$/$1/;
649 if (defined($sourcelist{$suffix})) {
650 $sourcelist{$suffix} .= " " . $source;
651 } else {
652 $sourcelist{$suffix} .= $source;
656 foreach $suffix (keys %sourcelist) {
658 # See if this file contains c++ code. (ie Just check the files suffix against
659 my $suffix_is_cxx = 0;
660 foreach $cxx_suffix (split(' ', $cppExt)) {
661 $cxx_suffix =~ s/^\*\.//;
662 $cxx_suffix = quotemeta($cxx_suffix);
663 if ($suffix =~ $cxx_suffix) {
664 $suffix_is_cxx = 1;
665 last; # $cxx_suffix
669 my $mocfiles_in = ($suffix eq $cxxsuffix) &&
670 defined($depedmocs{$program});
672 my @sourcelist = split(/[\s\034]+/, $sourcelist{$suffix});
674 if ((@sourcelist == 1 && !$mocfiles_in) || $suffix_is_cxx != 1 ) {
676 # we support IDL on our own
677 if ($suffix =~ /^skel$/ || $suffix =~ /^stub/ || $suffix =~ /^h$/
678 || $suffix =~ /^ui$/ ) {
679 next;
682 foreach $file (@sourcelist) {
684 $file =~ s/\Q$suffix\E$//;
686 $finalObjs{$program} .= $file;
687 if ($program =~ /_la$/) {
688 $finalObjs{$program} .= "lo ";
689 } else {
690 $finalObjs{$program} .= "o ";
693 next; # suffix
696 my $source_deps = "";
697 foreach $source (@sourcelist) {
698 if (-f $source) {
699 $source_deps .= "\$(srcdir)/$source ";
700 } else {
701 $source_deps .= "$source ";
705 $handling = "$program.all_$suffix.$suffix: \$(srcdir)/Makefile.in " . $source_deps . " ";
707 if ($mocfiles_in) {
708 $handling .= $depedmocs{$program};
709 foreach $mocfile (split(' ', $depedmocs{$program})) {
710 if ($mocfile =~ m/\.$suffix$/) {
711 $mocsources .= " " . $mocfile;
716 $handling .= "\n";
717 $handling .= "\t\@echo 'creating $program.all_$suffix.$suffix ...'; \\\n";
718 $handling .= "\trm -f $program.all_$suffix.files $program.all_$suffix.final; \\\n";
719 $handling .= "\techo \"#define KDE_USE_FINAL 1\" >> $program.all_$suffix.final; \\\n";
720 $handling .= "\tfor file in " . $sourcelist{$suffix} . " $mocsources; do \\\n";
721 $handling .= "\t echo \"#include \\\"\$\$file\\\"\" >> $program.all_$suffix.files; \\\n";
722 $handling .= "\t test ! -f \$\(srcdir\)/\$\$file || egrep '^#pragma +implementation' \$\(srcdir\)/\$\$file >> $program.all_$suffix.final; \\\n";
723 $handling .= "\tdone; \\\n";
724 $handling .= "\tcat $program.all_$suffix.final $program.all_$suffix.files > $program.all_$suffix.$suffix; \\\n";
725 $handling .= "\trm -f $program.all_$suffix.final $program.all_$suffix.files\n";
727 appendLines($handling);
729 push(@final_names, "$program.all_$suffix.$suffix");
730 $finalObjs{$program} .= "$program.all_$suffix.";
731 if ($program =~ /_la$/) {
732 $finalObjs{$program} .= "lo ";
733 } else {
734 $finalObjs{$program} .= "o ";
739 if (!$kdeopts{"nofinal"} && @final_names >= 1) {
740 # add clean-final target
741 my $lines = "$cleantarget-final:\n";
742 $lines .= "\t-rm -f " . join(' ', @final_names) . "\n" if (@final_names);
743 appendLines($lines);
744 $target_adds{"$cleantarget-am"} .= "$cleantarget-final ";
746 foreach $finalfile (@final_names) {
747 $finalfile =~ s/\.[^.]*$/.P/;
748 $dep_finals .= " \$(DEPDIR)/$finalfile";
753 # Organises the list of headers that we'll use to produce moc files
754 # from.
755 sub tag_METASOURCES ()
757 local @newObs = (); # here we add to create object files
758 local @deped = (); # here we add to create moc files
759 local $mocExt = ".moc";
760 local %mocFiles = ();
762 my $line = "";
763 my $postEqual = "";
765 my $lookup;
766 my $found = "";
768 if ($metasourceTags > 1) {
769 $lookup = $program . '_METASOURCES\s*=\s*(.*)';
770 return 1 if ($MakefileData !~ /\n($lookup)\n/);
771 $found = $1;
772 } else {
773 $lookup = $program . '_METASOURCES\s*=\s*(.*)';
774 if ($MakefileData !~ /\n($lookup)\n/) {
775 $lookup = 'METASOURCES\s*=\s*(.*)';
776 return 1 if ($MakefileData !~ /\n($lookup)\n/);
777 $found = $1;
778 $metasourceTags = 0; # we can use the general target only once
779 } else {
780 $found = $1;
783 print STDOUT "METASOURCE processing <$found>)\n" if ($verbose);
785 $postEqual = $found;
786 $postEqual =~ s/[^=]*=//;
788 removeLine ($lookup, $found);
790 # Always find the header files that could be used to "moc"
791 return 1 if (findMocCandidates ());
793 if ($postEqual =~ /AUTO\s*(\S*)|USE_AUTOMOC\s*(\S*)/)
795 print STDERR "$printname: the argument for AUTO|USE_AUTOMOC is obsolete" if ($+);
796 $mocExt = ".moc.$cxxsuffix";
797 $haveAutomocTag = 1;
799 else
801 # Not automoc so read the list of files supplied which
802 # should be .moc files.
804 $postEqual =~ tr/\034/ /;
806 # prune out extra headers - This also checks to make sure that
807 # the list is valid.
808 pruneMocCandidates ($postEqual);
811 checkMocCandidates ();
813 if (@newObs) {
814 my $ext = ($program =~ /_la$/) ? ".moc.lo " : ".moc.o ";
815 $realObjs{$program} .= "\034" . join ($ext, @newObs) . $ext;
816 $depedmocs{$program} = join (".moc.$cxxsuffix " , @newObs) . ".moc.$cxxsuffix";
817 foreach $file (@newObs) {
818 $dep_files .= " \$(DEPDIR)/$file.moc.P";
821 if (@deped) {
822 $depedmocs{$program} .= " ";
823 $depedmocs{$program} .= join('.moc ', @deped) . ".moc";
824 $depedmocs{$program} .= " ";
826 addMocRules ();
827 @globalmocs{keys %mocFiles}=values %mocFiles;
830 #-----------------------------------------------------------------------------
832 # Returns 0 if the line was processed - 1 otherwise.
833 # Errors are logged in the global $errorflags
834 sub tag_AUTOMAKE ()
836 my $lookup = '.*cd \$\(top_srcdir\)\s+&&\s+\$\(AUTOMAKE\)(.*)';
837 return 1 if ($MakefileData !~ /($lookup)/);
838 print STDOUT "AUTOMAKE processing <$1>\n" if ($verbose);
840 my $newLine = $1."\n\tcd \$(top_srcdir) && perl $thisProg $printname";
841 substituteLine ($lookup, $newLine);
842 $automkCall = $1;
843 return 0;
846 #-----------------------------------------------------------------------------
848 sub tag_TOPLEVEL()
850 my $lookup = 'TOPLEVEL_LANG\s*=\s*(\S+)';
851 return 1 if ($MakefileData !~ /\n$lookup\n/);
852 my $lang = $1;
854 if (tag_SUBDIRS()) {
855 print STDERR "Error: TOPLEVEL_LANG without SUBDIRS = \$(AUTODIRS) in $printname\n";
856 $errorflag = 1;
857 return 1;
860 my $pofiles = "";
861 my @restfiles = ();
862 opendir (THISDIR, ".");
863 foreach $entry (readdir(THISDIR)) {
864 next if (-d $entry);
866 next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/ || $entry =~ /.gmo$/);
868 if ($entry =~ /\.po$/) {
869 $pofiles .= "$entry ";
870 next;
872 push(@restfiles, $entry);
874 closedir (THISDIR);
876 print STDOUT "pofiles found = $pofiles\n" if ($verbose);
877 handle_POFILES($pofiles, '$(TOPLEVEL_LANG)') if ($pofiles);
879 if (@restfiles) {
880 $target_adds{"install-data-am"} .= "install-nls-files ";
881 $lines = "install-nls-files:\n";
882 $lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$lang\n";
883 for $file (@restfiles) {
884 $lines .= "\t\$(INSTALL_DATA) \$\(srcdir\)/$file \$(DESTDIR)\$(kde_locale)/$lang/$file\n";
886 appendLines($lines);
889 return 0;
892 #-----------------------------------------------------------------------------
894 sub tag_SUBDIRS ()
896 if ($MakefileData !~ /\nSUBDIRS\s*=\s*\$\(AUTODIRS\)\s*\n/) {
897 return 1;
900 my $subdirs;
902 opendir (THISDIR, ".");
903 foreach $entry (readdir(THISDIR)) {
904 next if ($entry eq "CVS" || $entry =~ /^\./);
905 if (-d $entry && -f $entry . "/Makefile.am") {
906 $subdirs .= " $entry";
907 next;
910 closedir (THISDIR);
912 my $lines = "SUBDIRS =$subdirs\n";
913 substituteLine('SUBDIRS\s*=.*', $lines);
914 return 0;
917 sub tag_IDLFILES ()
919 my @psources = split(/[\034\s]+/, $sources{$program});
920 my $dep_lines = "";
921 my @cppFiles = ();
923 foreach $source (@psources) {
925 my $skel = ($source =~ m/\.skel$/);
927 if ($source =~ m/\.stub$/ || $skel) {
929 my $qs = quotemeta($source);
930 $sources{$program} =~ s/$qs//;
931 $sources_changed{$program} = 1;
933 print STDOUT "adding IDL file $source\n" if ($verbose);
935 $source =~ s/\.(stub|skel)$//;
937 my $sourcename;
939 if ($skel) {
940 $sourcename = "$source\_skel";
941 } else {
942 $sourcename = "$source\_stub";
945 my $sourcedir = '';
946 if (-f "$makefileDir/$source.h") {
947 $sourcedir = '$(srcdir)/';
948 } else {
949 if ($MakefileData =~ /\n$source\_DIR\s*=\s*(\S+)\n/) {
950 $sourcedir = $1;
951 $sourcedir .= "/" if ($sourcedir !~ /\/$/);
955 if ($allidls !~ /$source\_kidl/) {
957 $dep_lines .= "$source.kidl: $sourcedir$source.h \$(DCOPIDL_DEPENDENCIES)\n";
958 $dep_lines .= "\t\$(DCOPIDL) $sourcedir$source.h > $source.kidl || ( rm -f $source.kidl ; /bin/false )\n";
960 $allidls .= $source . "_kidl ";
963 if ($allidls !~ /$sourcename/) {
965 if ($skel) {
966 $dep_lines .= "$sourcename.$cxxsuffix: $source.kidl\n";
967 $dep_lines .= "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-stub $source.kidl\n";
968 } else {
969 $target_adds{"$sourcename.$cxxsuffix"} .= "$sourcename.h ";
970 $dep_lines .= "$sourcename.h: $source.kidl\n";
971 $dep_lines .= "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-skel $source.kidl\n";
974 $allidls .= $sourcename . " ";
977 $idlfiles{$program} .= $sourcename . " ";
979 if ($program =~ /_la$/) {
980 $realObjs{$program} .= " $sourcename.lo";
981 } else {
982 $realObjs{$program} .= " $sourcename.\$(OBJEXT)";
984 $sources{$program} .= " $sourcename.$cxxsuffix";
985 $sources_changed{$program} = 1;
986 $important{$program} .= "$sourcename.h " if (!$skel);
987 $idl_output .= "\\\n\t$sourcename.$cxxsuffix $sourcename.h $source.kidl ";
988 push(@cleanfiles, "$sourcename.$cxxsuffix");
989 push(@cleanfiles, "$sourcename.h");
990 push(@cleanfiles, "$sourcename.kidl");
991 $dep_files .= " \$(DEPDIR)/$sourcename.P";
994 if ($dep_lines) {
995 appendLines($dep_lines);
998 if (0) {
999 my $lookup = "($program)";
1000 $lookup .= '(|\$\(EXEEXT\))';
1001 $lookup =~ s/\_/./g;
1002 $lookup .= ":(.*..$program\_OBJECTS..*)";
1003 # $lookup = quotemeta($lookup);
1004 if ($MakefileData =~ /\n$lookup\n/) {
1006 my $line = "$1$2: ";
1007 foreach $file (split(' ', $idlfiles{$program})) {
1008 $line .= "$file.$cxxsuffix ";
1010 $line .= $3;
1011 substituteLine($lookup, $line);
1012 } else {
1013 print STDERR "no built dependency found $lookup\n";
1018 sub tag_UIFILES ()
1020 my @psources = split(/[\034\s]+/, $sources{$program});
1021 my $dep_lines = "";
1022 my @depFiles = ();
1024 foreach $source (@psources) {
1026 if ($source =~ m/\.ui$/) {
1028 print STDERR "adding UI file $source\n" if ($verbose);
1030 my $qs = quotemeta($source);
1031 $sources{$program} =~ s/$qs//;
1032 $sources_changed{$program} = 1;
1034 $source =~ s/\.ui$//;
1036 my $sourcedir = '';
1037 if (-f "$makefileDir/$source.ui") {
1038 $sourcedir = '$(srcdir)/';
1041 if ($alluis !~ /$source/) {
1043 $dep_lines .= "$source.$cxxsuffix: $sourcedir$source.ui $source.h $source.moc\n";
1044 $dep_lines .= "\trm -f $source.$cxxsuffix\n";
1045 if (!$kdeopts{"qtonly"}) {
1046 $dep_lines .= "\techo '#include <klocale.h>' > $source.$cxxsuffix\n";
1047 $dep_lines .= "\t\$(UIC) -tr i18n -i $source.h $sourcedir$source.ui | sed -e \"s,i18n( \\\"\\\" ),QString::null,g\" >> $source.$cxxsuffix || rm -f $source.$cxxsuffix\n";
1048 } else {
1049 $dep_lines .= "\t\$(UIC) -i $source.h $sourcedir$source.ui > $source.$cxxsuffix || rm -f $source.$cxxsuffix\n";
1051 $dep_lines .= "\techo '#include \"$source.moc\"' >> $source.$cxxsuffix\n\n";
1052 $dep_lines .= "$source.h: $sourcedir$source.ui\n";
1053 $dep_lines .= "\t\$(UIC) -o $source.h $sourcedir$source.ui\n\n";
1054 $dep_lines .= "$source.moc: $source.h\n";
1055 $dep_lines .= "\t\$(MOC) $source.h -o $source.moc\n";
1057 $alluis .= "$source ";
1058 $ui_mocs .= " $source.moc";
1059 $depedmocs{$program} .= " $source.moc";
1062 if ($program =~ /_la$/) {
1063 $realObjs{$program} .= " $source.lo";
1064 } else {
1065 $realObjs{$program} .= " $source.\$(OBJEXT)";
1067 $sources{$program} .= " $source.$cxxsuffix";
1068 $sources_changed{$program} = 1;
1069 $important{$program} .= "$source.h ";
1070 $ui_output .= "\\\n\t$source.$cxxsuffix $source.h $source.moc ";
1071 push(@cleanfiles, "$source.$cxxsuffix");
1072 push(@cleanfiles, "source.h");
1073 push(@cleanfiles, "$source.moc");
1075 $dep_files .= " \$(DEPDIR)/$source.P";
1078 if ($dep_lines) {
1079 appendLines($dep_lines);
1083 sub tag_ICON()
1085 my $lookup = '([^\s]*)_ICON\s*=\s*([^\n]*)';
1086 my $install = "";
1087 my $uninstall = "";
1089 while ($MakefileData =~ /\n$lookup/g) {
1090 my $destdir;
1091 if ($1 eq "KDE") {
1092 $destdir = "kde_icondir";
1093 } else {
1094 $destdir = $1 . "dir";
1096 my $iconauto = ($2 =~ /AUTO\s*$/);
1097 my @appnames = ();
1098 if ( ! $iconauto ) {
1099 my @_appnames = split(" ", $2);
1100 print STDOUT "KDE_ICON processing <@_appnames>\n" if ($verbose);
1101 foreach $appname (@_appnames) {
1102 push(@appnames, quotemeta($appname));
1104 } else {
1105 print STDOUT "KDE_ICON processing <AUTO>\n" if ($verbose);
1108 my @files = ();
1109 opendir (THISDIR, ".");
1110 foreach $entry (readdir(THISDIR)) {
1111 next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
1112 next if (! -f $entry);
1113 if ( $iconauto )
1115 push(@files, $entry)
1116 if ($entry =~ /\.xpm/ || $entry =~ /\.png/);
1117 } else {
1118 foreach $appname (@appnames) {
1119 push(@files, $entry)
1120 if ($entry =~ /-$appname\.xpm/ || $entry =~ /-$appname\.png/);
1124 closedir (THISDIR);
1126 my %directories = ();
1128 foreach $file (@files) {
1129 my $newfile = $file;
1130 my $prefix = $file;
1131 $prefix =~ s/\.(png|xpm)$//;
1132 my $appname = $prefix;
1133 $appname =~ s/^[^-]+-// if ($appname =~ /-/) ;
1134 $appname =~ s/^[^-]+-// if ($appname =~ /-/) ;
1135 $appname = quotemeta($appname);
1136 $prefix =~ s/$appname$//;
1137 $prefix =~ s/-$//;
1139 $prefix = 'lo16-app' if ($prefix eq 'mini');
1140 $prefix = 'lo32-app' if ($prefix eq 'lo');
1141 $prefix = 'hi48-app' if ($prefix eq 'large');
1142 $prefix .= '-app' if ($prefix =~ m/^...$/);
1144 my $type = $prefix;
1145 $type =~ s/^.*-([^-]+)$/$1/;
1146 $prefix =~ s/^(.*)-[^-]+$/$1/;
1148 my %type_hash =
1150 'action' => 'actions',
1151 'app' => 'apps',
1152 'device' => 'devices',
1153 'filesys' => 'filesystems',
1154 'mime' => 'mimetypes'
1157 if (! defined $type_hash{$type} ) {
1158 print STDERR "unknown icon type $type in $printname ($file)\n";
1159 next;
1162 my %dir_hash =
1164 'los' => 'locolor/16x16',
1165 'lom' => 'locolor/32x32',
1166 'him' => 'hicolor/32x32',
1167 'hil' => 'hicolor/48x48',
1168 'lo16' => 'locolor/16x16',
1169 'lo22' => 'locolor/22x22',
1170 'lo32' => 'locolor/32x32',
1171 'hi16' => 'hicolor/16x16',
1172 'hi22' => 'hicolor/22x22',
1173 'hi32' => 'hicolor/32x32',
1174 'hi48' => 'hicolor/48x48',
1175 'hisc' => 'hicolor/scalable'
1178 $newfile =~ s@.*-($appname\.(png|xpm?))@$1@;
1180 if (! defined $dir_hash{$prefix}) {
1181 print STDERR "unknown icon prefix $prefix in $printname\n";
1182 next;
1185 my $dir = $dir_hash{$prefix} . "/" . $type_hash{$type};
1186 if ($newfile =~ /-[^\.]/) {
1187 my $tmp = $newfile;
1188 $tmp =~ s/^([^-]+)-.*$/$1/;
1189 $dir = $dir . "/" . $tmp;
1190 $newfile =~ s/^[^-]+-//;
1193 if (!defined $directories{$dir}) {
1194 $install .= "\t\$(mkinstalldirs) \$(DESTDIR)\$($destdir)/$dir\n";
1195 $directories{$dir} = 1;
1198 $install .= "\t\$(INSTALL_DATA) \$(srcdir)/$file \$(DESTDIR)\$($destdir)/$dir/$newfile\n";
1199 $uninstall .= "\t-rm -f \$(DESTDIR)\$($destdir)/$dir/$newfile\n";
1204 if (length($install)) {
1205 $target_adds{"install-data-am"} .= "install-kde-icons ";
1206 $target_adds{"uninstall-am"} .= "uninstall-kde-icons ";
1207 appendLines("install-kde-icons:\n" . $install . "\nuninstall-kde-icons:\n" . $uninstall);
1211 sub handle_POFILES($$)
1213 my @pofiles = split(" ", $_[0]);
1214 my $lang = $_[1];
1216 # Build rules for creating the gmo files
1217 my $tmp = "";
1218 my $allgmofiles = "";
1219 my $pofileLine = "POFILES =";
1220 foreach $pofile (@pofiles)
1222 $pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1223 $tmp .= "$1.gmo: $pofile\n";
1224 $tmp .= "\trm -f $1.gmo; \$(GMSGFMT) -o $1.gmo \$(srcdir)/$pofile\n";
1225 $tmp .= "\ttest ! -f $1.gmo || touch $1.gmo\n";
1226 $allgmofiles .= " $1.gmo";
1227 $pofileLine .= " $1.po";
1229 appendLines ($tmp);
1230 my $lookup = 'POFILES\s*=([^\n]*)';
1231 if ($MakefileData !~ /\n$lookup/) {
1232 appendLines("$pofileLine\nGMOFILES =$allgmofiles");
1233 } else {
1234 substituteLine ($lookup, "$pofileLine\nGMOFILES =$allgmofiles");
1237 if ($allgmofiles) {
1239 # Add the "clean" rule so that the maintainer-clean does something
1240 appendLines ("clean-nls:\n\t-rm -f $allgmofiles\n");
1242 $target_adds{"maintainer-clean"} .= "clean-nls ";
1244 $lookup = 'DISTFILES\s*=\s*(.*)';
1245 if ($MakefileData =~ /\n$lookup\n/) {
1246 $tmp = "DISTFILES = \$(GMOFILES) \$(POFILES) $1";
1247 substituteLine ($lookup, $tmp);
1251 $target_adds{"install-data-am"} .= "install-nls ";
1253 $tmp = "install-nls:\n";
1254 $tmp .= "install-nls:\n";
1255 if ($lang) {
1256 $tmp .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES\n";
1258 $tmp .= "\t\@for base in ";
1259 foreach $pofile (@pofiles)
1261 $pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1262 $tmp .= "$1 ";
1265 $tmp .= "; do \\\n";
1266 if ($lang) {
1267 $tmp .= "\t echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n";
1268 $tmp .= "\t test ! -f \$\$base.gmo || \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n"
1269 } else {
1270 $tmp .= "\t echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
1271 $tmp .= "\t \$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES ; \\\n";
1272 $tmp .= "\t test ! -f \$\$base.gmo || \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
1274 $tmp .= "\tdone\n\n";
1275 appendLines ($tmp);
1277 $target_adds{"uninstall"} .= "uninstall-nls ";
1279 $tmp = "uninstall-nls:\n";
1280 foreach $pofile (@pofiles)
1282 $pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1283 if ($lang) {
1284 $tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/$1.mo\n";
1285 } else {
1286 $tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$1/LC_MESSAGES/\$(PACKAGE).mo\n";
1289 appendLines($tmp);
1291 $target_adds{"all"} .= "all-nls ";
1293 $tmp = "all-nls: \$(GMOFILES)\n";
1295 appendLines($tmp);
1297 $target_adds{"distdir"} .= "distdir-nls ";
1299 $tmp = "distdir-nls:\$(GMOFILES)\n";
1300 $tmp .= "\tfor file in \$(POFILES); do \\\n";
1301 $tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n";
1302 $tmp .= "\tdone\n";
1303 $tmp .= "\ttest -z \"\$(GMOFILES)\" || cp \$(GMOFILES) \$(distdir)\n";
1305 appendLines ($tmp);
1307 if (!$lang) {
1308 appendLines("merge:\n\t\$(MAKE) -f \$(top_srcdir)/admin/Makefile.common package-merge POFILES=\"\${POFILES}\" PACKAGE=\${PACKAGE}\n\n");
1313 #-----------------------------------------------------------------------------
1315 # Returns 0 if the line was processed - 1 otherwise.
1316 # Errors are logged in the global $errorflags
1317 sub tag_POFILES ()
1319 my $lookup = 'POFILES\s*=([^\n]*)';
1320 return 1 if ($MakefileData !~ /\n$lookup/);
1321 print STDOUT "POFILES processing <$1>\n" if ($verbose);
1323 my $tmp = $1;
1325 # make sure these are all gone.
1326 if ($MakefileData =~ /\n\.po\.gmo:\n/)
1328 print STDERR "Warning: Found old .po.gmo rules in $printname. New po rules not added\n";
1329 return 1;
1332 # Either find the pofiles in the directory (AUTO) or use
1333 # only the specified po files.
1334 my $pofiles = "";
1335 if ($tmp =~ /^\s*AUTO\s*$/)
1337 opendir (THISDIR, ".");
1338 next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^#.*#$/);
1339 $pofiles = join(" ", grep(/\.po$/, readdir(THISDIR)));
1340 closedir (THISDIR);
1341 print STDOUT "pofiles found = $pofiles\n" if ($verbose);
1343 else
1345 $tmp =~ s/\034/ /g;
1346 $pofiles = $tmp;
1348 return 1 if (!$pofiles); # Nothing to do
1350 handle_POFILES($pofiles, $kdelang);
1352 return 0;
1355 sub helper_LOCALINSTALL($)
1357 my $lookup = "\n" . $_[0] . ":";
1358 if ($MakefileData =~ /($lookup)/) {
1360 my $install = $MakefileData;
1361 $install =~ s/\n/\035/g;
1362 $install =~ s/.*\035$_[0]:[^\035]*\035//;
1363 my $emptyline = 0;
1364 while (! $emptyline) {
1365 if ($install =~ /([^\035]*)\035(.*)/) {
1366 local $line = $1;
1367 $install = $2;
1368 if ($line !~ /^\s*$/ && $line !~ /^(\@.*\@)*\t/) {
1369 $emptyline = 1;
1370 } else {
1371 replaceDestDir($line);
1373 } else {
1374 $emptyline = 1;
1381 sub tag_LOCALINSTALL ()
1383 helper_LOCALINSTALL('install-exec-local');
1384 helper_LOCALINSTALL('install-data-local');
1385 helper_LOCALINSTALL('uninstall-local');
1387 return 0;
1390 sub replaceDestDir($) {
1391 local $line = $_[0];
1393 if ( $line =~ /^\s*(\@.*\@)*\s*\$\(mkinstalldirs\)/
1394 || $line =~ /^\s*(\@.*\@)*\s*\$\(INSTALL\S*\)/
1395 || $line =~ /^\s*(\@.*\@)*\s*(-?rm.*) \S*$/)
1397 $line =~ s/^(.*) ([^\s]*)\s*$/$1 \$(DESTDIR)$2/ if ($line !~ /\$\(DESTDIR\)/);
1400 if ($line ne $_[0]) {
1401 $_[0] = quotemeta $_[0];
1402 substituteLine($_[0], $line);
1406 #---------------------------------------------------------------------------
1407 sub tag_CLOSURE () {
1408 return if ($program !~ /_la$/);
1410 my $lookup = quotemeta($realname{$program}) . ":.*?\n\t.*?\\((.*?)\\) .*\n";
1411 $MakefileData =~ m/$lookup/;
1412 return if ($1 !~ /CXXLINK/);
1414 if ($MakefileData !~ /\n$program\_LDFLAGS\s*=.*-no-undefined/ &&
1415 $MakefileData !~ /\n$program\_LDFLAGS\s*=.*KDE_PLUGIN/ ) {
1416 print STDERR "Report: $program contains undefined in $printname\n" if ($program =~ /^lib/ && $dryrun);
1417 return;
1419 my $closure = $realname{$program} . ".closure";
1420 my $lines = "$closure: \$($program\_OBJECTS) \$($program\_DEPENDENCIES)\n";
1421 $lines .= "\t\@echo \"int main() {return 0;}\" > $program\_closure.$cxxsuffix\n";
1422 $lines .= "\t\@\$\(LTCXXCOMPILE\) -c $program\_closure.$cxxsuffix\n";
1423 $lines .= "\t\@\$\(CXXLINK\) $program\_closure.lo \$($program\_LDFLAGS) \$($program\_OBJECTS) \$($program\_LIBADD) \$(LIBS)\n";
1424 $lines .= "\t\@rm -f $program\_closure.* $closure\n";
1425 $lines .= "\t\@echo \"timestamp\" > $closure\n";
1426 $lines .= "\n";
1427 appendLines($lines);
1428 $lookup = $realname{$program} . ": (.*)";
1429 if ($MakefileData =~ /\n$lookup\n/) {
1430 $lines = "\@KDE_USE_CLOSURE_TRUE@". $realname{$program} . ": $closure $1";
1431 $lines .= "\n\@KDE_USE_CLOSURE_FALSE@" . $realname{$program} . ": $1";
1432 substituteLine($lookup, $lines);
1434 $closure_output .= " $closure";
1437 sub tag_DIST () {
1438 my %foundfiles = ();
1439 opendir (THISDIR, ".");
1440 foreach $entry (readdir(THISDIR)) {
1441 next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile$$/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
1442 next if (! -f $entry);
1443 next if ($entry =~ /\.moc/ || $entry =~ /\.lo$/ || $entry =~ /\.la$/ || $entry =~ /\.o/);
1444 $foundfiles{$entry} = 1;
1446 closedir (THISDIR);
1448 my @marks = ("EXTRA_DIST", "DIST_COMMON", '\S*_SOURCES', '\S*_HEADERS', 'CLEANFILES', 'DISTCLEANFILES', '\S*_OBJECTS');
1449 foreach $mark (@marks) {
1450 while ($MakefileData =~ /\n($mark)\s*=\s*([^\n]*)/g) {
1451 foreach $file (split('[\034\s]', $2)) {
1452 $file =~ s/\.\///;
1453 $foundfiles{$file} = 0 if (defined $foundfiles{$file});
1457 my @files = ("Makefile", "config.cache", "config.log", "stamp-h",
1458 "stamp-h1", "stamp-h1", "config.h", "Makefile", "config.status", "config.h", "libtool");
1459 foreach $file (@files) {
1460 $foundfiles{$file} = 0 if (defined $foundfiles{$file});
1463 # don't distribute programs and libraries
1464 $foundfiles{$realname{$_}} = 0 foreach @programs;
1466 my $KDE_DIST = "";
1467 foreach $file (keys %foundfiles) {
1468 if ($foundfiles{$file} == 1) {
1469 $KDE_DIST .= "$file ";
1472 if ($KDE_DIST) {
1473 print "KDE_DIST $printname $KDE_DIST\n" if ($verbose);
1475 my $lookup = "DISTFILES *=(.*)";
1476 if ($MakefileData =~ /\n$lookup\n/) {
1477 substituteLine($lookup, "KDE_DIST=$KDE_DIST\n\nDISTFILES=$1 \$(KDE_DIST)\n");
1482 #-----------------------------------------------------------------------------
1483 # Returns 0 if the line was processed - 1 otherwise.
1484 # Errors are logged in the global $errorflags
1485 sub tag_DOCFILES ()
1487 # if ($MakefileData =~ /\nSUBDIRS\s*=/) { # subdirs
1488 # $MakefileData =~ /\n(.*-recursive:\s*)\n/;
1489 # my $orig_rules = $1;
1490 # my $rules = $orig_rules;
1491 # $rules =~ s/:\s*$//;
1492 # substituteLine($orig_rules, "$rules docs-recursive:");
1493 # appendLines("docs: docs-recursive docs-am\n");
1494 # } else {
1495 # appendLines("docs: docs-am\n");
1497 $target_adds{"all"} .= "docs-am ";
1499 my $lookup = 'KDE_DOCS\s*=\s*([^\n]*)';
1500 goto nodocs if ($MakefileData !~ /\n$lookup/);
1501 print STDOUT "KDE_DOCS processing <$1>\n" if ($verbose);
1503 tag_SUBDIRS();
1505 my $tmp = $1;
1507 # Either find the files in the directory (AUTO) or use
1508 # only the specified po files.
1509 my $files = "";
1510 my $appname = $tmp;
1511 $appname =~ s/^(\S*)\s*.*$/$1/;
1512 if ($appname =~ /AUTO/) {
1513 $appname = basename($makefileDir);
1514 if ("$appname" eq "en") {
1515 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";
1516 exit(1);
1520 if ($tmp !~ / - /)
1522 opendir (THISDIR, ".");
1523 foreach $entry (readdir(THISDIR)) {
1524 next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
1525 next if (! -f $entry);
1526 $files .= "$entry ";
1528 closedir (THISDIR);
1529 print STDOUT "docfiles found = $files\n" if ($verbose);
1531 else
1533 $tmp =~ s/\034/ /g;
1534 $tmp =~ s/^\S*\s*-\s*//;
1535 $files = $tmp;
1537 goto nodocs if (!$files); # Nothing to do
1539 if ($files =~ /(^| )index\.docbook($| )/) {
1541 my $lines = "";
1542 my $lookup = 'KDB2HTML\s*=';
1543 #if ($MakefileData !~ /\n($lookup)/) {
1544 # $lines = "KDB2HTML = \$(SHELL) /\$(kde_bindir)/kdb2html\n";
1546 $lines .= "docs-am: HTML HTML/index.html\n";
1547 $lines .= "\n";
1548 $lines .= "HTML:\n";
1549 $lines .= "\ttest -d HTML || mkdir HTML\n";
1550 $lines .= "\n";
1551 $lines .= "HTML/index.html: HTML index.docbook\n";
1552 $lines .= "\t\@test -d HTML && rm -r HTML\n";
1553 $lines .= "\t\$(KDB2HTML) \$(srcdir)/index.docbook\n";
1554 $lines .= "\n";
1555 $lines .= "install-docs:\n";
1556 $lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n";
1557 $lines .= "\t-\@filelist=\"\" ;\\\n";
1558 $lines .= "\tif test -d HTML; then \\\n";
1559 $lines .= "\t filelist=`(cd HTML && ls -1 * .anchors 2> /dev/null)`; \\\n";
1560 $lines .= "\t dir=HTML; \\\n";
1561 $lines .= "\telse if test -d \$(srcdir)/HTML; then \\\n";
1562 $lines .= "\t filelist=`(cd \$(srcdir)/HTML && ls -1 * .anchors 2> /dev/null)`; \\\n";
1563 $lines .= "\t dir=\"\$(srcdir)/HTML\" ;\\\n";
1564 $lines .= "\tfi ; fi ;\\\n";
1565 $lines .= "\tfor file in \$\$filelist; do if test -f \$\$dir/\$\$file; then \\\n";
1566 $lines .= "\techo \$(INSTALL_DATA) \$\$dir/\$\$file \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$file ;\\\n";
1567 $lines .= "\t\$(INSTALL_DATA) \$\$dir/\$\$file \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$file; \\\n";
1568 $lines .= "\tfi; done\n";
1569 $lines .= "\t-rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n";
1570 $lines .= "\t\$(LN_S) \$(kde_libs_htmldir)/$kdelang/common \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n";
1572 $lines .= "\n";
1573 $lines .= "uninstall-docs:\n";
1574 $lines .= "\t-rm -rf \$(kde_htmldir)/$kdelang/$appname\n";
1575 $lines .= "\n";
1576 $target_adds{"install-data-am"} .= "install-docs ";
1577 $target_adds{"uninstall"} .= "uninstall-docs ";
1578 appendLines ($lines);
1579 } else {
1580 appendLines("docs-am:\n");
1583 $target_adds{"install-data-am"} .= "install-nls";
1584 $target_adds{"uninstall"} .= "uninstall-nls ";
1586 $tmp = "install-nls:\n";
1587 $tmp .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n";
1588 $tmp .= "\t\@for base in $files; do \\\n";
1589 $tmp .= "\t echo \$(INSTALL_DATA) \$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1590 $tmp .= "\t \$(INSTALL_DATA) \$(srcdir)/\$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1591 $tmp .= "\tdone\n";
1592 if ($appname eq 'common') {
1593 $tmp .= "\t\@echo \"merging common and language specific dir\" ;\\\n";
1594 $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";
1595 $tmp .= "\t\@com_files=`cd \$(kde_htmldir)/en/common && echo *` ;\\\n";
1596 $tmp .= "\tcd \$(DESTDIR)\$(kde_htmldir)/$kdelang/common ;\\\n";
1597 $tmp .= "\tif test -n \"\$\$com_files\"; then for p in \$\$com_files ; do \\\n";
1598 $tmp .= "\t case \" $files \" in \\\n";
1599 $tmp .= "\t *\" \$\$p \"*) ;; \\\n";
1600 $tmp .= "\t *) test ! -e \$\$p && echo \$(LN_S) ../../en/common/\$\$p \$(DESTDIR)\$(kde_htmldir)/$kdelang/common/\$\$p && \$(LN_S) ../../en/common/\$\$p \$\$p ;; \\\n";
1601 $tmp .= "\t esac ; \\\n";
1602 $tmp .= "\tdone ; fi ; true\n";
1604 $tmp .= "\n";
1605 $tmp .= "uninstall-nls:\n";
1606 $tmp .= "\tfor base in $files; do \\\n";
1607 $tmp .= "\t rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1608 $tmp .= "\tdone\n\n";
1609 appendLines ($tmp);
1611 $target_adds{"distdir"} .= "distdir-nls ";
1613 $tmp = "distdir-nls:\n";
1614 $tmp .= "\tfor file in $files; do \\\n";
1615 $tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n";
1616 $tmp .= "\tdone\n";
1618 appendLines ($tmp);
1620 return 0;
1622 nodocs:
1623 appendLines("docs-am:\n");
1624 return 1;
1627 #-----------------------------------------------------------------------------
1628 # Find headers in any of the source directories specified previously, that
1629 # are candidates for "moc-ing".
1630 sub findMocCandidates ()
1632 my @list = ();
1633 foreach $dir (@headerdirs)
1635 chdir ($dir);
1636 @list = `grep -l '^.*Q_OBJECT' $hExt 2> /dev/null`;
1637 chdir ($makefileDir);
1639 # The assoc array of root of headerfile and header filename
1640 foreach $hFile (@list)
1642 chomp ($hFile);
1643 $hFile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1644 if ($mocFiles{$1})
1646 print STDERR "Warning: Multiple header files found for $1\n";
1647 next; # Use the first one
1649 $mocFiles{$1} = "$dir\035$hFile"; # Add relative dir
1653 return 0;
1656 #-----------------------------------------------------------------------------
1658 # The programmer has specified a moc list. Prune out the moc candidates
1659 # list that we found based on looking at the header files. This generates
1660 # a warning if the programmer gets the list wrong, but this doesn't have
1661 # to be fatal here.
1662 sub pruneMocCandidates ($)
1664 my %prunedMoc = ();
1665 local @mocList = split(' ', $_[0]);
1667 foreach $mocname (@mocList)
1669 $mocname =~ s/\.moc$//;
1670 if ($mocFiles{$mocname})
1672 $prunedMoc{$mocname} = $mocFiles{$mocname};
1674 else
1676 my $print = $makefileDir;
1677 $print =~ s/^\Q$topdir\E\\//;
1678 # They specified a moc file but we can't find a header that
1679 # will generate this moc file. That's possible fatal!
1680 print STDERR "Warning: No moc-able header file for $print/$mocname\n";
1684 undef %mocFiles;
1685 %mocFiles = %prunedMoc;
1688 #-----------------------------------------------------------------------------
1690 # Finds the cpp files (If they exist).
1691 # The cpp files get appended to the header file separated by \035
1692 sub checkMocCandidates ()
1694 my @cppFiles = ();
1696 foreach $mocFile (keys (%mocFiles))
1698 # Find corresponding c++ files that includes the moc file
1699 @cppFiles = `echo \`ls -1d $cppExt 2> /dev/null | egrep -v "\.moc\.$cxxsuffix\$" | egrep -v "all_$cxxsuffix\.$cxxsuffix\$"\``;
1701 if (@cppFiles) {
1702 my $files = join(" ", @cppFiles);
1703 @cppFiles =
1704 `egrep -l "^[ ]*#include[ ]*.$mocFile\.moc." $files 2>/dev/null`;
1707 if (@cppFiles == 1)
1709 chomp $cppFiles[0];
1710 $mocFiles{$mocFile} .= "\035" . $cppFiles[0];
1711 push(@deped, $mocFile);
1712 next;
1715 if (@cppFiles == 0)
1717 push (@newObs, $mocFile); # Produce new object file
1718 next if ($haveAutomocTag); # This is expected...
1719 # But this is an error we can deal with - let them know
1720 print STDERR
1721 "Warning: No c++ file that includes $mocFile.moc\n";
1722 next;
1724 else
1726 # We can't decide which file to use, so it's fatal. Although as a
1727 # guess we could use the mocFile.cpp file if it's in the list???
1728 print STDERR
1729 "Error: Multiple c++ files that include $mocFile.moc\n";
1730 print STDERR "\t",join ("\t", @cppFiles),"\n";
1731 $errorflag = 1;
1732 delete $mocFiles{$mocFile};
1733 # Let's continue and see what happens - They have been told!
1738 #-----------------------------------------------------------------------------
1740 # Add the rules for generating moc source from header files
1741 # For Automoc output *.moc.cpp but normally we'll output *.moc
1742 # (We must compile *.moc.cpp separately. *.moc files are included
1743 # in the appropriate *.cpp file by the programmer)
1744 sub addMocRules ()
1746 my $cppFile;
1747 my $hFile;
1749 foreach $mocFile (keys (%mocFiles))
1751 undef $cppFile;
1752 ($dir, $hFile, $cppFile) = split ("\035", $mocFiles{$mocFile}, 3);
1753 $dir =~ s#^\.#\$(srcdir)#;
1754 if (defined ($cppFile))
1756 $target_adds{"\$(srcdir)/$cppFile"} .= "$mocFile.moc ";
1757 appendLines ("$mocFile.moc: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile.moc\n");
1758 $cleanMoc .= " $mocFile.moc";
1760 else
1762 appendLines ("$mocFile$mocExt: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile$mocExt\n");
1763 $cleanMoc .= " $mocFile$mocExt";
1768 sub make_meta_classes ()
1770 return if ($kdeopts{"qtonly"});
1772 my $cppFile;
1773 my $hFile;
1774 my $moc_class_headers = "";
1775 my @cppFiles =
1776 `grep -l "setMocClasses[ ]*(.*)[ ]*;" $cppExt 2> /dev/null`;
1777 chomp(@cppFiles);
1778 print STDOUT "C++ files with setMocClasses() = [".join(' ', @cppFiles)."]\n"
1779 if $verbose;
1780 foreach $program (@programs) {
1781 my $mocs = "";
1782 my @progsources = split(/[\s\034]+/, $sources{$program});
1783 my @depmocs = split(' ', $depedmocs{$program});
1784 my %shash = (), %mhash = ();
1785 @shash{@progsources} = 1; # we are only interested in the existence
1786 @mhash{@depmocs} = 1;
1788 print STDOUT "program=$program\n" if ($verbose);
1789 print STDOUT "psources=[".join(' ', keys %shash)."]\n" if ($verbose);
1790 print STDOUT "depmocs=[".join(' ', keys %mhash)."]\n" if ($verbose);
1791 print STDOUT "globalmocs=[".join(' ', keys(%globalmocs))."]\n" if ($verbose);
1792 foreach my $mocFile (keys (%globalmocs))
1794 undef $cppFile;
1795 ($dir, $hFile, $cppFile) = split ("\035", $globalmocs{$mocFile}, 3);
1796 $dir =~ s#^\.#\$(srcdir)#;
1797 if (defined ($cppFile))
1799 #print STDOUT "cpp=$cppFile\n";
1800 $mocs .= " $mocFile.moc" if exists $shash{$cppFile};
1802 else
1804 # Bah. This is the case, if no C++ file includes the .moc
1805 # file. We make a .moc.cpp file for that. Unfortunately this
1806 # is not included in the %sources hash, but rather is mentioned
1807 # in %depedmocs. If the user wants to use AUTO he can't just
1808 # use an unspecific METAINCLUDES. Instead he must use
1809 # program_METAINCLUDES. Anyway, it's not working real nicely.
1810 # E.g. Its not clear what happens if user specifies two
1811 # METAINCLUDES=AUTO in the same Makefile.am.
1812 $mocs .= " $mocFile.moc.$cxxsuffix"
1813 if exists $mhash{$mocFile.".moc.$cxxsuffix"};
1816 $mocs .= $ui_mocs;
1817 if ($mocs) {
1818 print STDOUT "==> mocs=[".$mocs."]\n" if ($verbose);
1819 my $sourcename = $program."_meta_unload";
1820 my $ext = ($program =~ /_la$/) ? ".lo" : ".o";
1821 my $srcfile = $sourcename.".$cxxsuffix";
1822 my $objfile = $sourcename.$ext;
1823 $moc_class_headers .= " $srcfile";
1824 my $appl;
1825 $appl = "$srcfile: $mocs\n";
1826 $appl .= "\t\@echo 'creating $srcfile'\n";
1827 $appl .= "\t-rm -f $srcfile\n";
1828 $appl .= "\t\@echo 'static const char * _metalist_$program\[\] = {' > $srcfile\n";
1829 $appl .= "\tcat $mocs | grep 'char.*className' | ";
1830 $appl .= "sed -e 's/.*[^A-Za-z0-9_:]\\([A-Za-z0-9_:]*\\)::className.*\$\$/\\\"\\1\\\",/' | sort | uniq >> $srcfile\n";
1831 $appl .= "\t\@echo '0};' >> $srcfile\n";
1832 $appl .= "\t\@echo '#include <kunload.h>' >> $srcfile\n";
1833 $appl .= "\t\@echo '_UNLOAD($program)' >> $srcfile\n";
1834 $appl .= "\n";
1836 $realObjs{$program} .= " \034" . $objfile . " ";
1837 $sources{$program} .= " $srcfile";
1838 $sources_changed{$program} = 1;
1839 $dep_files .= " \$(DEPDIR)/$sourcename.P";
1841 # now also add a dependency for the C++ file which includes a
1842 # setMocClasses() call, and is part of this program (if any)
1843 #foreach $cppFile (@cppFiles) {
1844 #print STDOUT "testing $cppFile\n" if $verbose;
1845 #if (exists $shash{$cppFile}) {
1846 # $appl .= "\$(srcdir)/$cppFile: $header\n";
1849 appendLines ($appl);
1851 print STDOUT "\n" if $verbose;
1853 if ($moc_class_headers) {
1854 appendLines ("$cleantarget-moc-classes:\n\t-rm -f $moc_class_headers\n");
1855 $target_adds{"$cleantarget-am"} .= "$cleantarget-moc-classes ";
1859 #-----------------------------------------------------------------------------
1861 sub updateMakefile ()
1863 return if ($dryrun);
1865 open (FILEOUT, "> $makefile")
1866 || die "Could not create $makefile: $!\n";
1868 print FILEOUT "\# $progId - " . '$Revision$ ' . "\n";
1869 $MakefileData =~ s/\034/\\\n/g; # Restore continuation lines
1870 print FILEOUT $MakefileData;
1871 close FILEOUT;
1874 #-----------------------------------------------------------------------------
1876 # The given line needs to be removed from the makefile
1877 # Do this by adding the special "removed line" comment at the line start.
1878 sub removeLine ($$)
1880 my ($lookup, $old) = @_;
1882 $old =~ s/\034/\\\n#>- /g; # Fix continuation lines
1883 $MakefileData =~ s/\n$lookup/\n#>\- $old/;
1886 #-----------------------------------------------------------------------------
1888 # Replaces the old line with the new line
1889 # old line(s) are retained but tagged as removed. The new line(s) have the
1890 # "added" tag placed before it.
1891 sub substituteLine ($$)
1893 my ($lookup, $new) = @_;
1895 if ($MakefileData =~ /\n($lookup)/) {
1896 $old = $1;
1897 $old =~ s/\034/\\\n#>\- /g; # Fix continuation lines
1898 $new =~ s/\034/\\\n/g;
1899 my $newCount = 1;
1900 $newCount++ while ($new =~ /\n/g);
1902 $MakefileData =~ s/\n$lookup/\n#>- $old\n#>\+ $newCount\n$new/;
1903 } else {
1904 print STDERR "Warning: substitution of \"$lookup\" in $printname failed\n";
1908 #-----------------------------------------------------------------------------
1910 # Slap new lines on the back of the file.
1911 sub appendLines ($)
1913 my ($new) = @_;
1915 $new =~ s/\034/\\\n/g; # Fix continuation lines
1916 my $newCount = 1;
1917 $newCount++ while ($new =~ /\n/g);
1919 $MakefileData .= "\n#>\+ $newCount\n$new";
1922 #-----------------------------------------------------------------------------
1924 # Restore the Makefile.in to the state it was before we fiddled with it
1925 sub restoreMakefile ()
1927 $MakefileData =~ s/# $progId[^\n\034]*[\n\034]*//g;
1928 # Restore removed lines
1929 $MakefileData =~ s/([\n\034])#>\- /$1/g;
1930 # Remove added lines
1931 while ($MakefileData =~ /[\n\034]#>\+ ([^\n\034]*)/)
1933 my $newCount = $1;
1934 my $removeLines = "";
1935 while ($newCount--) {
1936 $removeLines .= "[^\n\034]*([\n\034]|)";
1938 $MakefileData =~ s/[\n\034]#>\+.*[\n\034]$removeLines/\n/;
1942 #-----------------------------------------------------------------------------