source: trunk/Taper/admin/am_edit@ 9384

Last change on this file since 9384 was 4307, checked in by merck, 21 years ago
new project
File size: 82.2 KB
Line 
1#!/usr/bin/perl -w
2
3# Expands the specialised KDE tags in Makefile.in to (hopefully) valid
4# make syntax.
5# When called without file parameters, we work recursively on all Makefile.in
6# in and below the current subdirectory. When called with file parameters,
7# only those Makefile.in are changed.
8# The currently supported tags are
9#
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.
15#
16# To install icons :
17# KDE_ICON = iconname iconname2 ...
18# KDE_ICON = AUTO
19#
20# For documentation :
21# http://developer.kde.org/documentation/other/developer-faq.html
22#
23# and more new tags TBD!
24#
25# The concept (and base code) for this program came from automoc,
26# supplied by the following
27#
28# Matthias Ettrich <ettrich@kde.org> (The originator)
29# Kalle Dalheimer <kalle@kde.org> (The original implementator)
30# Harri Porten <porten@tu-harburg.de>
31# Alex Zepeda <jazepeda@pacbell.net>
32# David Faure <faure@kde.org>
33# Stephan Kulow <coolo@kde.org>
34# Dirk Mueller <mueller@kde.org>
35
36use Cwd;
37use File::Find;
38use File::Basename;
39
40# Prototype the functions
41sub initialise ();
42sub processMakefile ($);
43sub updateMakefile ();
44sub restoreMakefile ();
45
46sub removeLine ($$);
47sub appendLines ($);
48sub substituteLine ($$);
49
50sub findMocCandidates ();
51sub pruneMocCandidates ($);
52sub checkMocCandidates ();
53sub addMocRules ();
54
55sub tag_AUTOMAKE ();
56sub tag_META_INCLUDES ();
57sub tag_METASOURCES ();
58sub tag_POFILES ();
59sub tag_DOCFILES ();
60sub tag_LOCALINSTALL();
61sub tag_IDLFILES();
62sub tag_UIFILES();
63sub tag_SUBDIRS();
64sub tag_ICON();
65sub tag_CLOSURE();
66sub tag_NO_UNDEFINED();
67sub tag_NMCHECK();
68sub tag_DIST();
69sub tag_KDEINIT();
70
71# Some global globals...
72$verbose = 0; # a debug flag
73$thisProg = "$0"; # This programs name
74$topdir = cwd(); # The current directory
75@makefiles = (); # Contains all the files we'll process
76@foreignfiles = ();
77$start = (times)[0]; # some stats for testing - comment out for release
78$version = "v0.2";
79$errorflag = 0;
80$cppExt = "(cpp|cc|cxx|C|c\\+\\+)";
81$hExt = "(h|H|hh|hxx|hpp|h\\+\\+)";
82$progId = "KDE tags expanded automatically by " . basename($thisProg);
83$automkCall = "\n";
84$printname = ""; # used to display the directory the Makefile is in
85$use_final = 1; # create code for --enable-final
86$cleantarget = "clean";
87$dryrun = 0;
88$pathoption = 0;
89$foreign_libtool = 0;
90
91while (defined ($ARGV[0]))
92{
93 $_ = shift;
94 if (/^--version$/)
95 {
96 print STDOUT "\n";
97 print STDOUT basename($thisProg), " $version\n",
98 "This is really free software, unencumbered by the GPL.\n",
99 "You can do anything you like with it except sueing me.\n",
100 "Copyright 1998 Kalle Dalheimer <kalle\@kde.org>\n",
101 "Concept, design and unnecessary questions about perl\n",
102 " by Matthias Ettrich <ettrich\@kde.org>\n\n",
103 "Making it useful by Stephan Kulow <coolo\@kde.org> and\n",
104 "Harri Porten <porten\@kde.org>\n",
105 "Updated (Feb-1999), John Birch <jb.nz\@writeme.com>\n",
106 "Fixes and Improvements by Dirk Mueller <mueller\@kde.org>\n",
107 "Current Maintainer Stephan Kulow\n\n";
108 exit 0;
109 }
110 elsif (/^--verbose$|^-v$/)
111 {
112 $verbose = 1; # Oh is there a problem...?
113 }
114 elsif (/^-p(.+)$|^--path=(.+)$/)
115 {
116 $thisProg = "$1/".basename($thisProg) if($1);
117 $thisProg = "$2/".basename($thisProg) if($2);
118 warn ("$thisProg doesn't exist\n") if (!(-f $thisProg));
119 $pathoption=1;
120 }
121 elsif (/^--help$|^-h$/)
122 {
123 print STDOUT "Usage $thisProg [OPTION] ... [dir/Makefile.in]...\n",
124 "\n",
125 "Patches dir/Makefile.in generated by automake\n",
126 "(where dir can be an absolute or relative directory name)\n",
127 "\n",
128 " -v, --verbose verbosely list files processed\n",
129 " -h, --help print this help, then exit\n",
130 " --version print version number, then exit\n",
131 " -p, --path= use the path to am_edit if the path\n",
132 " called from is not the one to be used\n",
133 " --no-final don't patch for --enable-final\n";
134
135 exit 0;
136 }
137 elsif (/^--no-final$/)
138 {
139 $use_final = 0;
140 $thisProg .= " --no-final";
141 }
142 elsif (/^--foreign-libtool$/)
143 {
144 $foreign_libtool = 1;
145 $thisProg .= " --foreign-libtool";
146 }
147 elsif (/^-n$/)
148 {
149 $dryrun = 1;
150 }
151 else
152 {
153 # user selects what input files to check
154 # add full path if relative path is given
155 $_ = cwd()."/".$_ if (! /^\//);
156 print "User wants $_\n" if ($verbose);
157 push (@makefiles, $_);
158 }
159}
160
161if ($thisProg =~ /^\// && !$pathoption )
162{
163 print STDERR "Illegal full pathname call performed...\n",
164 "The call to \"$thisProg\"\nwould be inserted in some Makefile.in.\n",
165 "Please use option --path.\n";
166 exit 1;
167}
168
169# Only scan for files when the user hasn't entered data
170if (!@makefiles)
171{
172 print STDOUT "Scanning for Makefile.in\n" if ($verbose);
173 find (\&add_makefile, cwd());
174 #chdir('$topdir');
175} else {
176 print STDOUT "Using input files specified by user\n" if ($verbose);
177}
178
179foreach $makefile (sort(@makefiles))
180{
181 processMakefile ($makefile);
182 last if ($errorflag);
183}
184
185# Just some debug statistics - comment out for release as it uses printf.
186printf STDOUT "Time %.2f CPU sec\n", (times)[0] - $start if ($verbose);
187
188exit $errorflag; # causes make to fail if erroflag is set
189
190#-----------------------------------------------------------------------------
191
192# In conjunction with the "find" call, this builds the list of input files
193sub add_makefile ()
194{
195 push (@makefiles, $File::Find::name) if (/Makefile.in$/);
196}
197
198#-----------------------------------------------------------------------------
199
200# Processes a single make file
201# The parameter contains the full path name of the Makefile.in to use
202sub processMakefile ($)
203{
204 # some useful globals for the subroutines called here
205 local ($makefile) = @_;
206 local @headerdirs = ('.');
207 local $haveAutomocTag = 0;
208 local $MakefileData = "";
209
210 local $cxxsuffix = "KKK";
211
212 local @programs = (); # lists the names of programs and libraries
213 local $program = "";
214
215 local @kdeinits = (); # lists the kdeinit targets
216
217 local %realObjs = (); # lists the objects compiled into $program
218 local %sources = (); # lists the sources used for $program
219 local %finalObjs = (); # lists the objects compiled when final
220 local %realname = (); # the binary name of program variable
221 local %idlfiles = (); # lists the idl files used for $program
222 local %globalmocs = ();# list of all mocfiles (in %mocFiles format)
223 local %important = (); # list of files to be generated asap
224 local %uiFiles = ();
225
226 local $allidls = "";
227 local $idl_output = "";# lists all idl generated files for cleantarget
228 local $ui_output = "";# lists all uic generated files for cleantarget
229
230 local %dependmocs = ();
231
232 local $metasourceTags = 0;
233 local $dep_files = "";
234 local $dep_finals = "";
235 local %target_adds = (); # the targets to add
236 local %rule_adds = ();
237 local $kdelang = "";
238 local @cleanfiles = ();
239 local $cleanMoc = "";
240 local $closure_output = "";
241
242 local %varcontent = ();
243
244 $makefileDir = dirname($makefile);
245 chdir ($makefileDir);
246 $printname = $makefile;
247 $printname =~ s/^\Q$topdir\E\///;
248 $makefile = basename($makefile);
249
250 print STDOUT "Processing makefile $printname\n" if ($verbose);
251
252 # Setup and see if we need to do this.
253 return if (!initialise());
254
255 tag_AUTOMAKE (); # Allows a "make" to redo the Makefile.in
256 tag_META_INCLUDES (); # Supplies directories for src locations
257
258 foreach $program (@programs) {
259 $sources_changed{$program} = 0;
260 $dependmocs{$program} = "";
261 $important{$program} = "";
262 tag_IDLFILES(); # Sorts out idl rules
263 tag_NO_UNDEFINED();
264 tag_CLOSURE();
265 tag_NMCHECK();
266 tag_UIFILES(); # Sorts out ui rules
267 tag_METASOURCES (); # Sorts out the moc rules
268 if ($sources_changed{$program}) {
269 my $lookup = $program . '_SOURCES\s*=[ \t]*(.*)';
270
271 if($program =~ /libkdeinit_(.*)/) {
272 my $prog = $1;
273 substituteLine($prog . '_SOURCES\s*=[ \t]*.*',
274 "${prog}_SOURCES = ${prog}_dummy.$cxxsuffix\n" .
275 "libkdeinit_${prog}_SOURCES = " . $sources{$program});
276 $sources{$prog} = "${prog}_dummy.$cxxsuffix";
277 }
278 else {
279 substituteLine($lookup, "$program\_SOURCES=" . $sources{$program});
280 }
281 }
282 if ($important{$program}) {
283 local %source_dict = ();
284 for $source (split(/[\034\s]+/, $sources{$program})) {
285 $source_dict{$source} = 1;
286 }
287 for $source (@cleanfiles) {
288 $source_dict{$source} = 0;
289 }
290 for $source (keys %source_dict) {
291 next if (!$source);
292 if ($source_dict{$source}) {
293 # sanity check
294 if (! -f $source) {
295 print STDERR "Error: $source is listed in a _SOURCE line in $printname, but doesn't exist yet. Put it in DISTCLEANFILES!\n";
296 } else {
297 $target_adds{"\$(srcdir)/$source"} .= $important{$program};
298 }
299 }
300 }
301 }
302 }
303 if ($cleanMoc) {
304 # Always add dist clean tag
305 # Add extra *.moc.cpp files created for USE_AUTOMOC because they
306 # aren't included in the normal *.moc clean rules.
307 appendLines ("$cleantarget-metasources:\n\t-rm -f $cleanMoc\n");
308 $target_adds{"$cleantarget-am"} .= "$cleantarget-metasources ";
309 }
310
311 tag_DIST() unless ($kdeopts{"noautodist"});
312
313 if ($idl_output) {
314 appendLines ("$cleantarget-idl:\n\t-rm -f $idl_output\n");
315 $target_adds{"$cleantarget-am"} .= "$cleantarget-idl ";
316 }
317
318 if ($ui_output) {
319 appendLines ("$cleantarget-ui:\n\t-rm -f $ui_output\n");
320 $target_adds{"$cleantarget-am"} .= "$cleantarget-ui ";
321 }
322
323 if ($closure_output) {
324 appendLines ("$cleantarget-closures:\n\t-rm -f $closure_output\n");
325 $target_adds{"$cleantarget-am"} .= "$cleantarget-closures ";
326 }
327
328 if ($MakefileData =~ /\nKDE_LANG\s*=\s*(\S*)\s*\n/) {
329 $kdelang = '$(KDE_LANG)'
330 } else {
331 $kdelang = '';
332 }
333
334 tag_POFILES (); # language rules for po directory
335 tag_DOCFILES (); # language rules for doc directories
336 tag_LOCALINSTALL(); # add $(DESTDIR) before all kde_ dirs
337 tag_ICON();
338 tag_SUBDIRS();
339
340 my $tmp = "force-reedit:\n";
341 $tmp .= "\t$automkCall\n\tcd \$(top_srcdir) && perl $thisProg $printname\n\n";
342 appendLines($tmp);
343
344 make_bcheck_target();
345 make_meta_classes();
346 tag_COMPILE_FIRST();
347 tag_FINAL() if (!$kdeopts{"nofinal"});
348
349 my $final_lines = "final:\n\t\$(MAKE) ";
350 my $final_install_lines = "final-install:\n\t\$(MAKE) ";
351 my $nofinal_lines = "no-final:\n\t\$(MAKE) ";
352 my $nofinal_install_lines = "no-final-install:\n\t\$(MAKE) ";
353
354 foreach $program (@programs) {
355 my $lookup = $program . '_OBJECTS\s*=[ \t]*.*';
356 my $new = "";
357 my @list = split(/[\034\s]+/, $realObjs{$program});
358 if (!$kdeopts{"nofinal"} && @list > 1 && $finalObjs{$program}) {
359 $new .= "$program\_final\_OBJECTS = " . $finalObjs{$program};
360 $new .= "\n$program\_nofinal\_OBJECTS = " . $realObjs{$program};
361 $new .= "\n\@KDE_USE_FINAL_FALSE\@$program\_OBJECTS = \$($program\_nofinal\_OBJECTS)";
362 $new .= "\n\@KDE_USE_FINAL_TRUE\@$program\_OBJECTS = \$($program\_final\_OBJECTS)";
363
364 $final_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" ";
365 $final_install_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" ";
366 $nofinal_lines .= "$program\_OBJECTS=\"\$($program\_nofinal\_OBJECTS)\" ";
367 $nofinal_install_lines .= "$program\_OBJECTS=\"\$($program\_nofinal_OBJECTS)\" ";
368 } else {
369 $new = "$program\_OBJECTS = " . $realObjs{$program};
370 }
371 if($MakefileData =~ m/\n$lookup/) {
372 substituteLine ($lookup, $new);
373 }
374 else {
375 appendLines("$new\n");
376 }
377 }
378 appendLines($final_lines . "all-am\n");
379 appendLines($final_install_lines . "install-am\n");
380 appendLines($nofinal_lines . "all-am\n");
381 appendLines($nofinal_install_lines . "install-am\n");
382
383 my $lookup = '(\@\S+\@)?DEP_FILES\s*=[ \t]*(.*)';
384 if ($MakefileData =~ /\n$lookup/) {
385 my $condition = $1;
386 my $depfiles = $2;
387 my $workfiles;
388
389 if ($dep_finals) {
390 # Add the conditions on every line, since
391 # there may be line continuations in the list.
392 $workfiles = "$dep_files $dep_finals $depfiles";
393 $workfiles =~ s/\034/\034$condition\@KDE_USE_FINAL_TRUE\@\t/g;
394 $lines = "$condition\@KDE_USE_FINAL_TRUE\@DEP_FILES = $workfiles\n";
395 $workfiles = "$dep_files $depfiles";
396 $workfiles =~ s/\034/\034$condition\@KDE_USE_FINAL_FALSE\@\t/g;
397 $lines .= "$condition\@KDE_USE_FINAL_FALSE\@DEP_FILES = $workfiles";
398 } else {
399 $workfiles = "$dep_files $depfiles";
400 $workfiles =~ s/\034/\034$condition\t/g;
401 $lines = $condition . "DEP_FILES = $workfiles";
402 }
403 substituteLine($lookup, $lines);
404 }
405
406 # new recursive targets
407 $target_adds{ "nmcheck" } .= ""; # always create nmcheck target
408 $target_adds{ "nmcheck-am" } .= "nmcheck";
409 $lookup = 'RECURSIVE_TARGETS\s*=[ \t]*(.*)';
410 if ($MakefileData =~ /\n$lookup/) {
411 substituteLine($lookup, "RECURSIVE_TARGETS = $1 nmcheck-recursive bcheck-recursive");
412 }
413
414 my $cvs_lines = "cvs-clean:\n";
415 $cvs_lines .= "\t\$(MAKE) admindir=\$(top_srcdir)/admin -f \$(top_srcdir)/admin/Makefile.common cvs-clean\n";
416 appendLines($cvs_lines);
417
418 $cvs_lines = "kde-rpo-clean:\n";
419 $cvs_lines .= "\t-rm -f *.rpo\n";
420 appendLines($cvs_lines);
421 $target_adds{"clean"} .= "kde-rpo-clean ";
422
423 my %target_dels = ("install-data-am" => "");
424
425 # some strange people like to do a install-exec, and expect that also
426 # all modules are installed. automake doesn't know this, so we need to move
427 # this here from install-data to install-exec.
428 if ($MakefileData =~ m/\nkde_module_LTLIBRARIES\s*=/) {
429# $target_adds{"install-exec-am"} .= "install-kde_moduleLTLIBRARIES ";
430# don't use $target_adds here because we need to append the dependency, not
431# prepend it. Fixes #44342 , when a module depends on a lib in the same dir
432# and libtool needs it during relinking upon install (Simon)
433 my $lookup = "install-exec-am:([^\n]*)";
434 if($MakefileData =~ /\n$lookup\n/) {
435 substituteLine("$lookup", "install-exec-am: $1 install-kde_moduleLTLIBRARIES");
436 }
437 $target_dels{"install-data-am"} .= "install-kde_moduleLTLIBRARIES ";
438 $target_adds{"install-data-am"} .= " ";
439 }
440
441 my $lines = "";
442
443 foreach $add (keys %target_adds) {
444 my $lookup = quotemeta($add) . ':([^\n]*)';
445 if ($MakefileData =~ /\n$lookup\n/) {
446 my $newlines = $1;
447 my $oldlines = $lookup;
448 if (defined $target_dels{$add}) {
449 foreach $del (split(' ', $target_dels{$add})) {
450 $newlines =~ s/\s*$del\s*/ /g;
451 }
452 }
453 substituteLine($oldlines, "$add: " . $target_adds{$add} . $newlines);
454 } else {
455 $lines .= "$add: " . $target_adds{$add} . "\n";
456 }
457 }
458
459 appendLines($lines) if ($lines);
460
461 $lines = join("\n", values %rule_adds);
462 appendLines($lines) if ($lines);
463
464 my $found = 1;
465
466 while ($found) {
467 if ($MakefileData =~ m/\n(.*)\$\(CXXFLAGS\)(.*)\n/) {
468 my $stuff_before = $1;
469 my $stuff_after = $2;
470 my $lookup = quotemeta("$1\$(CXXFLAGS)$2");
471 my $replacement = "$1\$(KCXXFLAGS)$2";
472 $MakefileData =~ s/$lookup/$replacement/;
473 $lookup =~ s/\\\$\\\(CXXFLAGS\\\)/\\\$\\\(KCXXFLAGS\\\)/;
474 $replacement = "$stuff_before\$(KCXXFLAGS) \$(KDE_CXXFLAGS)$stuff_after";
475 substituteLine($lookup, $replacement);
476 } else {
477 $found = 0;
478 }
479 }
480
481 if($foreign_libtool == 0) {
482 $lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=link) (\$\(CXXLD\).*\$\(KCXXFLAGS\))';
483
484 if ($MakefileData =~ m/$lookup/ ) {
485 $MakefileData =~ s/$lookup/$1 --tag=CXX $2/;
486 }
487
488 $lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=compile)\s+(\$\(CXX\)\s+)';
489 if ($MakefileData =~ m/$lookup/ ) {
490 $MakefileData =~ s/$lookup/$1 --tag=CXX $2/;
491 }
492 }
493
494 $MakefileData =~ s/\$\(KCXXFLAGS\)/\$\(CXXFLAGS\)/g;
495
496 $lookup = '(.*)cp -pr \$\$/\$\$file \$\(distdir\)/\$\$file(.*)';
497 if ($MakefileData =~ m/\n$lookup\n/) {
498 substituteLine($lookup, "$1cp -pr \$\$d/\$\$file \$(distdir)/\$\$file$2");
499 }
500
501 # Always update the Makefile.in
502 updateMakefile ();
503 return;
504}
505
506#-----------------------------------------------------------------------------
507
508# Beware: This procedure is not complete. E.g. it also parses lines
509# containing a '=' in rules (for instance setting shell vars). For our
510# usage this us enough, though.
511sub read_variables ()
512{
513 while ($MakefileData =~ /\n\s*(\S+)\s*=([^\n]*)/g) {
514 $varcontent{$1} = $2;
515 }
516}
517
518# Check to see whether we should process this make file.
519# This is where we look for tags that we need to process.
520# A small amount of initialising on the tags is also done here.
521# And of course we open and/or create the needed make files.
522sub initialise ()
523{
524 if (! -r "Makefile.am") {
525 print STDOUT "found Makefile.in without Makefile.am\n" if ($verbose);
526 return 0;
527 }
528
529 # Checking for files to process...
530 open (FILEIN, $makefile)
531 || die "Could not open $makefileDir/$makefile: $!\n";
532 # Read the file
533 # stat(FILEIN)[7] might look more elegant, but is slower as it
534 # requires stat'ing the file
535 seek(FILEIN, 0, 2);
536 my $fsize = tell(FILEIN);
537 seek(FILEIN, 0, 0);
538 read FILEIN, $MakefileData, $fsize;
539 close FILEIN;
540 print "DOS CRLF within $makefileDir/$makefile!\n" if($MakefileData =~ y/\r//d);
541
542 # Remove the line continuations, but keep them marked
543 # Note: we lose the trailing spaces but that's ok.
544 # Don't mangle line-leading spaces (usually tabs)
545 # since they're important.
546 $MakefileData =~ s/\\\s*\n/\034/g;
547
548 # If we've processed the file before...
549 restoreMakefile () if ($MakefileData =~ /$progId/);
550
551 foreach $dir (@foreignfiles) {
552 if (substr($makefileDir,0,length($dir)) eq $dir) {
553 return 0;
554 }
555 }
556
557 %kdeopts = ();
558 $kdeopts{"foreign"} = 0;
559 $kdeopts{"qtonly"} = 0;
560 $kdeopts{"noautodist"} = 0;
561 $kdeopts{"foreign-libtool"} = $foreign_libtool;
562 $kdeopts{"nofinal"} = !$use_final; # default
563
564 read_variables();
565
566 if ($MakefileData =~ /\nKDE_OPTIONS\s*=[ \t]*([^\n]*)\n/) {
567 my $kde_options_str = $1;
568 local @kde_options = split(/[\034\s]+/, $kde_options_str);
569 if (grep(/^foreign$/, @kde_options)) {
570 push(@foreignfiles, $makefileDir . "/");
571 return 0; # don't touch me
572 }
573 for $opt (@kde_options) {
574 if (!defined $kdeopts{$opt}) {
575 print STDERR "Warning: unknown option $opt in $printname\n";
576 } else {
577 $kdeopts{$opt} = 1;
578 }
579 }
580 }
581
582 # Look for the tags that mean we should process this file.
583 $metasourceTags = 0;
584 $metasourceTags++ while ($MakefileData =~ /\n[^=\#]*METASOURCES\s*=/g);
585
586 my $pofileTag = 0;
587 $pofileTag++ while ($MakefileData =~ /\nPOFILES\s*=/g);
588 if ($pofileTag > 1)
589 {
590 print STDERR "Error: Only one POFILES tag allowed\n";
591 $errorflag = 1;
592 }
593
594 while ($MakefileData =~ /\n\.SUFFIXES:([^\n]+)\n/g) {
595 my $suffixes_str = $1;
596 my @list=split(' ', $suffixes_str);
597 foreach $ext (@list) {
598 if ($ext =~ /^\.$cppExt$/) {
599 $cxxsuffix = $ext;
600 $cxxsuffix =~ s/\.//g;
601 print STDOUT "will use suffix $cxxsuffix\n" if ($verbose);
602 last;
603 }
604 }
605 }
606
607 tag_KDEINIT();
608
609 while ($MakefileData =~ /\n(\S*)_OBJECTS\s*=[\034 \t]*([^\n]*)\n/g) {
610
611 my $program = $1;
612 my $objs = $2; # safe them
613
614 my $ocv = 0;
615
616 my @objlist = split(/[\034\s]+/, $objs);
617 foreach $obj (@objlist) {
618 if ($obj =~ /(\S*)\$\((\S+)\)/ ) {
619 my $pre = $1;
620 my $variable = $2;
621 if ($pre eq '' && exists($varcontent{$variable})) {
622 my @addlist = split(/[\034\s]+/, $varcontent{$variable});
623 push(@objlist, @addlist);
624 } elsif ($variable !~ 'OBJEXT') {
625 $ocv = 1;
626 }
627 }
628 }
629
630 next if ($ocv);
631 next if ($program =~ /^am_libkdeinit_/);
632
633 $program =~ s/^am_// if ($program =~ /^am_/);
634
635 my $sourceprogram = $program;
636 $sourceprogram =~ s/\@am_/\@/ if($sourceprogram =~ /^.*\@am_.+/);
637
638 print STDOUT "found program $program\n" if ($verbose);
639 push(@programs, $program);
640
641 $realObjs{$program} = $objs;
642
643 if ($MakefileData =~ /\n$sourceprogram\_SOURCES\s*=[ \t]*(.*)\n/) {
644 $sources{$program} = $1;
645 }
646 else {
647 $sources{$program} = "";
648 print STDERR "found program with no _SOURCES: $program\n";
649 }
650
651 my $realprogram = $program;
652 $realprogram =~ s/_/./g; # unmask to regexp
653 if ($MakefileData =~ /\n($realprogram)(\$\(EXEEXT\)?)?:.*\$\($program\_OBJECTS\)/) {
654 $realname{$program} = $1;
655 } else {
656 # not standard Makefile - nothing to worry about
657 $realname{$program} = "";
658 }
659 }
660
661 my $lookup = 'DEPDIR\s*=.*';
662 if ($MakefileData !~ /\n$lookup/) {
663 $lookup = 'bindir\s*=[ \t]*.*';
664 substituteLine($lookup, "DEPDIR = .deps\n$1") if ($MakefileData =~ /\n($lookup)/);
665 }
666
667 my @marks = ('MAINTAINERCLEANFILES', 'CLEANFILES', 'DISTCLEANFILES');
668 foreach $mark (@marks) {
669 while ($MakefileData =~ /\n($mark)\s*=[ \t]*([^\n]*)/g) {
670 my $clean_str = $2;
671 foreach $file (split('[\034\s]+', $clean_str)) {
672 $file =~ s/\.\///;
673 push(@cleanfiles, $file);
674 }
675 }
676 }
677
678 my $localTag = 0;
679 $localTag++ if ($MakefileData =~ /\ninstall-\S+-local:/);
680
681 return (!$errorflag);
682}
683
684#-----------------------------------------------------------------------------
685
686# Gets the list of user defined directories - relative to $srcdir - where
687# header files could be located.
688sub tag_META_INCLUDES ()
689{
690 my $lookup = '[^=\n]*META_INCLUDES\s*=[ \t]*(.*)';
691 return 1 if ($MakefileData !~ /($lookup)\n/);
692 print STDOUT "META_INCLUDE processing <$1>\n" if ($verbose);
693
694 my $headerStr = $2;
695 removeLine ($lookup, $1);
696
697 my @headerlist = split(/[\034\s]+/, $headerStr);
698
699 foreach $dir (@headerlist)
700 {
701 $dir =~ s#\$\(srcdir\)#.#;
702 if (! -d $dir)
703 {
704 print STDERR "Warning: $dir can't be found. ",
705 "Must be a relative path to \$(srcdir)\n";
706 }
707 else
708 {
709 push (@headerdirs, $dir);
710 }
711 }
712
713 return 0;
714}
715
716#-----------------------------------------------------------------------------
717
718sub tag_FINAL()
719{
720 my @final_names = ();
721
722 foreach $program (@programs) {
723
724 if ($sources{$program} =~ /\(/) {
725 print STDOUT "found ( in $program\_SOURCES. skipping\n" if ($verbose);
726 next;
727 }
728
729 my $mocs = ""; # Moc files (in this program)
730 my $moc_cpp_added = 0; # If we added some .moc.cpp files, due to
731 # no other .cpp file including the .moc one.
732
733 my @progsources = split(/[\034\s]+/, $sources{$program});
734 my %shash = ();
735 @shash{@progsources} = 1; # we are only interested in the existence
736 my %sourcelist = ();
737
738 foreach $source (@progsources) {
739 my $suffix = $source;
740 $suffix =~ s/^.*\.([^\.]+)$/$1/;
741
742 $sourcelist{$suffix} .= "$source ";
743 }
744 foreach my $mocFile (keys (%globalmocs))
745 {
746 my ($dir, $hFile, $cppFile) = split ("\035", $globalmocs{$mocFile}, 3);
747 if (defined ($cppFile)) {
748 $mocs .= " $mocFile.moc" if exists $shash{$cppFile};
749 } else {
750 $sourcelist{$cxxsuffix} .= "$mocFile.moc.$cxxsuffix ";
751 $moc_cpp_added = 1;
752 }
753 }
754 foreach $suffix (keys %sourcelist) {
755
756 # See if this file contains c++ code. (i.e., just check the file's suffix against c++ extensions)
757 my $suffix_is_cxx = 0;
758 if($suffix =~ /($cppExt)$/) {
759 $cxxsuffix = $1;
760 $suffix_is_cxx = 1;
761 }
762
763 my $mocfiles_in = ($suffix eq $cxxsuffix) && $moc_cpp_added;
764
765 my @sourcelist = split(/[\034\s]+/, $sourcelist{$suffix});
766
767 if ((@sourcelist == 1 && !$mocfiles_in) || $suffix_is_cxx != 1 ) {
768
769 # we support IDL on our own
770 if ($suffix eq "skel" || $suffix =~ /^stub/
771 || $suffix =~ /^signals/ # obsolete, remove in KDE-4
772 || $suffix eq "h" || $suffix eq "ui" ) {
773 next;
774 }
775
776 foreach $file (@sourcelist) {
777 $file =~ s/\Q$suffix\E$//;
778
779 $finalObjs{$program} .= $file;
780 if ($program =~ /_la$/) {
781 $finalObjs{$program} .= "lo ";
782 } else {
783 $finalObjs{$program} .= "o ";
784 }
785 }
786 next; # suffix
787 }
788
789 my $source_deps = "";
790 foreach $source (@sourcelist) {
791 if (-f $source) {
792 $source_deps .= " \$(srcdir)/$source";
793 } else {
794 $source_deps .= " $source";
795 }
796 }
797
798 $handling = "$program.all_$suffix.$suffix: \$(srcdir)/Makefile.in" . $source_deps . " " . join(' ', $mocs) . "\n";
799 $handling .= "\t\@echo 'creating $program.all_$suffix.$suffix ...'; \\\n";
800 $handling .= "\trm -f $program.all_$suffix.files $program.all_$suffix.final; \\\n";
801 $handling .= "\techo \"#define KDE_USE_FINAL 1\" >> $program.all_$suffix.final; \\\n";
802 $handling .= "\tfor file in " . $sourcelist{$suffix} . "; do \\\n";
803 $handling .= "\t echo \"#include \\\"\$\$file\\\"\" >> $program.all_$suffix.files; \\\n";
804 $handling .= "\t test ! -f \$\(srcdir\)/\$\$file || egrep '^#pragma +implementation' \$\(srcdir\)/\$\$file >> $program.all_$suffix.final; \\\n";
805 $handling .= "\tdone; \\\n";
806 $handling .= "\tcat $program.all_$suffix.final $program.all_$suffix.files > $program.all_$suffix.$suffix; \\\n";
807 $handling .= "\trm -f $program.all_$suffix.final $program.all_$suffix.files\n";
808
809 appendLines($handling);
810
811 push(@final_names, "$program.all_$suffix.$suffix");
812 my $finalObj = "$program.all_$suffix.";
813 if ($program =~ /_la$/) {
814 $finalObj .= "lo";
815 } else {
816 $finalObj .= "o";
817 }
818 $finalObjs{$program} .= $finalObj . " ";
819 }
820 }
821
822 if (!$kdeopts{"nofinal"} && @final_names >= 1) {
823 # add clean-final target
824 my $lines = "$cleantarget-final:\n";
825 $lines .= "\t-rm -f " . join(' ', @final_names) . "\n" if (@final_names);
826 appendLines($lines);
827 $target_adds{"$cleantarget-am"} .= "$cleantarget-final ";
828
829 foreach $finalfile (@final_names) {
830 $finalfile =~ s/\.[^.]*$/.P/;
831 $dep_finals .= " \$(DEPDIR)/$finalfile";
832 }
833 }
834}
835
836sub tag_KDEINIT()
837{
838 my @progs = ();
839 my $ltlibs = "";
840 my $lookup = 'kdeinit_LTLIBRARIES\s*=[ \t]*(.*)';
841
842 if ($MakefileData =~ m/\n$lookup/) {
843 @kdeinits = split(/[\034\s]+/, $1);
844 my $lines = "";
845 foreach my $kdeinit (@kdeinits) {
846 if ($kdeinit =~ m/\.la$/) {
847 $kdeinit =~ s/\.la$//;
848 push(@progs, $kdeinit);
849
850 $lines .= "\n${kdeinit}.la.$cxxsuffix:\n";
851 $lines .= "\techo 'extern \"C\" int kdemain(int argc, char* argv[]);' > ${kdeinit}.la.$cxxsuffix; \\\n";
852 $lines .= "\techo 'int main(int argc, char* argv[]) { return kdemain(argc,argv); }' >> ${kdeinit}.la.$cxxsuffix\n";
853
854 $lines .= "\n${kdeinit}_dummy.$cxxsuffix:\n";
855 $lines .= "\t echo > ${kdeinit}_dummy.$cxxsuffix\n";
856
857 push(@cleanfiles, "${kdeinit}.la.$cxxsuffix");
858 push(@cleanfiles, "${kdeinit}_dummy.$cxxsuffix");
859
860 # add dependency
861 $dep_files .= " \$(DEPDIR)/${kdeinit}.la.Po" if($dep_files !~/${kdeinit}.la.Po/ );
862 $dep_files .= " \$(DEPDIR)/${kdeinit}_dummy.Plo" if($dep_files !~/${kdeinit}_dummy.Plo/ );
863
864 # make library
865 $lookup = $kdeinit . '_la_LIBADD\s*=[ \t]*(.*)';
866 if($MakefileData =~ m/\n$lookup/) {
867 my $libadd = $1;
868 substituteLine($lookup, "${kdeinit}_la_LIBADD = libkdeinit_${kdeinit}.la");
869 appendLines("libkdeinit_${kdeinit}_la_LIBADD = $libadd\n");
870 }
871 appendLines("libkdeinit_${kdeinit}_la_LDFLAGS = \$(all_libraries)\n");
872
873 # add library dependencies
874 $lookup = $kdeinit . '_la_DEPENDENCIES\s*=[ \t]*(.*)';
875 if($MakefileData =~ m/\n$lookup/) {
876 my $libdeps = $1;
877 substituteLine($lookup, "${kdeinit}_la_DEPENDENCIES = libkdeinit_${kdeinit}.la");
878 appendLines("libkdeinit_${kdeinit}_la_DEPENDENCIES = $libdeps\n");
879 }
880
881 # make library objects
882 $lookup = "am_${kdeinit}_la_OBJECTS" . '\s*=[ \t]*(.*)';
883 if($MakefileData =~ m/\n$lookup/) {
884 my $libobjects = $1;
885 substituteLine($lookup, "am_${kdeinit}_la_OBJECTS = ${kdeinit}_dummy.lo");
886 appendLines("am_libkdeinit_${kdeinit}_la_OBJECTS = $libobjects\n");
887 my $prog = "libkdeinit_${kdeinit}_la";
888 push(@programs, $prog);
889 $realObjs{$prog} = $libobjects;
890 $realname{$prog} = "libkdeinit_${kdeinit}.la";
891 }
892 $target_adds{"libkdeinit_${kdeinit}.la"} = "\$(libkdeinit_${kdeinit}_la_OBJECTS) \$(libkdeinit_${kdeinit}_la_DEPENDENCIES)\n" .
893 "\t\$(CXXLINK) -rpath \$(libdir) \$(libkdeinit_${kdeinit}_la_LDFLAGS) ".
894 "\$(libkdeinit_${kdeinit}_la_OBJECTS) " .
895 "\$(libkdeinit_${kdeinit}_la_LIBADD) " .
896 "\$(LIBS)\n";
897
898 # make libkdeinit sources
899 $lookup = $kdeinit . '_la_SOURCES\s*=[ \t]*(.*)';
900 if($MakefileData =~ m/\n$lookup/) {
901 my $srces = $1;
902 $sources_changed{"libkdeinit_${kdeinit}_la"} = 1;
903 $sources{"libkdeinit_${kdeinit}_la"} = $srces;
904 }
905
906 # make libkdeinit metasources
907 $lookup = $kdeinit . '_la_METASOURCES\s*=[ \t]*(.*)';
908 substituteLine($lookup, "libkdeinit_${kdeinit}_la_METASOURCES = $1")
909 if($MakefileData =~ m/\n$lookup/);
910
911=cut
912 # make binary sources
913 $lookup = $kdeinit. '_SOURCES\s*=[ \t]*(.*)';
914 if($MakefileData =~ m/\n$lookup/) {
915 substituteLine($lookup, "${kdeinit}_SOURCES = ${kdeinit}.la.$cxxsuffix");
916 $lookup = 'SOURCES\s*=[ \t]*(.*)';
917 if($MakefileData =~ m/\n$lookup/) {
918 my $srces = $1;
919 $srces =~ s/\b$kdeinit\.c\b/\$(${kdeinit}_SOURCES)/;
920 $srces =~ s/\$\(${kdeinit}_la_SOURCES\)/\$(libkdeinit_${kdeinit}_la_SOURCES)/;
921 substituteLine($lookup, "SOURCES = $srces");
922 }
923 $lookup = 'DIST_SOURCES\s*=[ \t](.*)';
924 if($MakefileData =~ m/\n$lookup/) {
925 my $srces = $1;
926 $srces =~ s/\b$kdeinit\.c\b/\$(${kdeinit}_SOURCES)/;
927 $srces =~ s/\$\(${kdeinit}_la_SOURCES\)/\$(libkdeinit_${kdeinit}_la_SOURCES)/;
928 substituteLine($lookup, "DIST_SOURCES = $srces");
929 }
930 }
931
932 # make binary objects / libs
933 $lookup = $kdeinit . '_OBJECTS\s*=[ \t]*.*';
934 if($MakefileData =~ m/\n$lookup/) {
935 $realObjs{$kdeinit} = "${kdeinit}.la.\$(OBJEXT)";
936 substituteLine("${kdeinit}_LDFLAGS\\s*=.*", "${kdeinit}_LDFLAGS = \$(all_libraries)");
937 substituteLine("${kdeinit}_LDADD\\s*=.*", "${kdeinit}_LDADD = libkdeinit_${kdeinit}.la");
938 substituteLine("${kdeinit}_DEPENDENCIES\\s*=.*", "${kdeinit}_DEPENDENCIES = libkdeinit_${kdeinit}.la");
939 }
940=cut
941 # add binary
942 push(@programs, $kdeinit);
943 $realObjs{$kdeinit} = "${kdeinit}.la.\$(OBJEXT)";
944 $realname{$kdeinit} = $kdeinit;
945 $sources{$kdeinit} = "${kdeinit}.la.$cxxsuffix";
946
947 $lines .= "${kdeinit}_LDFLAGS = \$(all_libraries)\n";
948 $lines .= "${kdeinit}_LDADD = libkdeinit_${kdeinit}.la\n";
949 $lines .= "${kdeinit}_DEPENDENCIES = libkdeinit_${kdeinit}.la\n";
950
951 $target_adds{"${kdeinit}\$(EXEEXT)"} =
952 "\$(${kdeinit}_OBJECTS) \$(${kdeinit}_DEPENDENCIES)\n" .
953 "\t\@rm -f ${kdeinit}\$(EXEEXT)\n" .
954 "\t\$(CXXLINK) \$(${kdeinit}_LDFLAGS) \$(${kdeinit}_OBJECTS) \$(${kdeinit}_LDADD) \$(LIBS)\n";
955
956 $ltlibs .= " libkdeinit_${kdeinit}.la";
957 }
958 }
959 appendLines($lines);
960
961 # add libkdeinit target
962 $lookup = 'lib_LTLIBRARIES\s*=[ \t]*(.*)';
963 if($MakefileData =~ m/\n$lookup/) {
964 substituteLine($lookup, "lib_LTLIBRARIES = $1 $ltlibs");
965 }
966 else {
967 print STDERR
968 "Error: lib_LTLIBRARIES missing in $printname (required for kdeinit_LTLIBRARIES).\n";
969 $errorflag = 1;
970 }
971 }
972
973 if($#progs >= 0) {
974 if($MakefileData !~ m/\nbin_PROGRAMS\s*=/) {
975 print STDERR "Error: bin_PROGRAMS missing in $printname (required for bin_PROGRAMS).\n";
976 $errorflag = 1;
977 }
978 else {
979 # add our new progs to SOURCES, DIST_SOURCES and bin_PROGRAMS
980 my $progsources = "";
981 my $progexes = "";
982 foreach my $p (@progs) {
983 $progsources .= "\$(${p}_SOURCES) ";
984 $progexes .= "${p}\$(EXEEXT) ";
985 }
986 $lookup = 'SOURCES\s*=[ \t]*(.*)';
987 if($MakefileData =~ /\n$lookup/) {
988 substituteLine($lookup, "SOURCES = $1 $progsources");
989 }
990 $lookup = 'DIST_SOURCES\s*=[ \t]*(.*)';
991 if($MakefileData =~ /\n$lookup/) {
992 substituteLine($lookup, "DIST_SOURCES = $1 $progsources");
993 }
994 # bin_PROGRAMS is complicated, as it exists twice, so we do a little
995 # magic trick here
996 $lookup = 'PROGRAMS\s*=[ \t]*(.*)';
997 if ($MakefileData =~ /\n$lookup/) {
998 substituteLine($lookup, "bin_PROGRAMS += $progexes\nPROGRAMS = $1");
999 }
1000 }
1001 }
1002}
1003
1004#-----------------------------------------------------------------------------
1005
1006sub tag_COMPILE_FIRST()
1007{
1008 foreach $program (@programs) {
1009 my $lookup = "$program" . '_COMPILE_FIRST\s*=[ \t]*(.*)';
1010 if ($MakefileData =~ m/\n$lookup\n/) {
1011 my $compilefirst_str = $1;
1012 my @compilefirst = split(/[\034\s]+/, $compilefirst_str);
1013 my @progsources = split(/[\034\s]+/, $sources{$program});
1014 my %donesources = ();
1015 foreach $source (@progsources) {
1016 my @deps = ();
1017 my $sdeps = "";
1018 if (-f $source) {
1019 $sdeps = "\$(srcdir)/$source";
1020 } else {
1021 $sdeps = "$source";
1022 }
1023 foreach $depend (@compilefirst) {
1024 next if ($source eq $depend);
1025 # avoid cyclic dependencies
1026 next if defined($donesources{$depend});
1027 push @deps, $depend;
1028 }
1029 $target_adds{$sdeps} = join(' ', @deps) if (@deps);
1030 $donesources{$source} = 1;
1031 }
1032 }
1033 }
1034}
1035
1036#-----------------------------------------------------------------------------
1037
1038
1039# Organises the list of headers that we'll use to produce moc files
1040# from.
1041sub tag_METASOURCES ()
1042{
1043 local @newObs = (); # here we add to create object files
1044 local @depend = (); # here we add to create moc files
1045 local $mocExt = ".moc";
1046 local %mocFiles = ();
1047
1048 my $line = "";
1049 my $postEqual = "";
1050
1051 my $lookup;
1052 my $found = "";
1053 if ($metasourceTags > 1) {
1054 $lookup = $program . '_METASOURCES\s*=\s*(.*)';
1055 return 1 if ($MakefileData !~ /\n($lookup)\n/);
1056 $found = $1;
1057 } else {
1058 $lookup = $program . '_METASOURCES\s*=\s*(.*)';
1059 if ($MakefileData !~ /\n($lookup)\n/) {
1060 $lookup = 'METASOURCES\s*=\s*(.*)';
1061 return 1 if ($MakefileData !~ /\n($lookup)\n/);
1062 $found = $1;
1063 $metasourceTags = 0; # we can use the general target only once
1064 } else {
1065 $found = $1;
1066 }
1067 }
1068 print STDOUT "METASOURCE processing <$found>)\n" if ($verbose);
1069
1070 $postEqual = $found;
1071 $postEqual =~ s/[^=]*=//;
1072
1073 removeLine ($lookup, $found);
1074
1075 # Always find the header files that could be used to "moc"
1076 return 1 if (findMocCandidates ());
1077
1078 if ($postEqual =~ /AUTO\s*(\S*)|USE_AUTOMOC\s*(\S*)/)
1079 {
1080 print STDERR "$printname: the argument for AUTO|USE_AUTOMOC is obsolete" if ($+);
1081 $mocExt = ".moc.$cxxsuffix";
1082 $haveAutomocTag = 1;
1083 }
1084 else
1085 {
1086 # Not automoc so read the list of files supplied which
1087 # should be .moc files.
1088
1089 $postEqual =~ tr/\034/ /;
1090
1091 # prune out extra headers - This also checks to make sure that
1092 # the list is valid.
1093 pruneMocCandidates ($postEqual);
1094 }
1095
1096 checkMocCandidates ();
1097
1098 if (@newObs) {
1099 my $ext = ($program =~ /_la$/) ? ".moc.lo " : ".moc.o ";
1100 $realObjs{$program} .= "\034" . join ($ext, @newObs) . $ext;
1101 $dependmocs{$program} = join (".moc.$cxxsuffix " , @newObs) . ".moc.$cxxsuffix";
1102 foreach $file (@newObs) {
1103 $dep_files .= " \$(DEPDIR)/$file.moc.P" if($dep_files !~/$file.moc.P/);
1104 }
1105 }
1106 if (@depend) {
1107 $dependmocs{$program} .= " ";
1108 $dependmocs{$program} .= join('.moc ', @depend) . ".moc";
1109 $dependmocs{$program} .= " ";
1110 }
1111 addMocRules ();
1112 @globalmocs{keys %mocFiles}=values %mocFiles;
1113}
1114
1115#-----------------------------------------------------------------------------
1116
1117# Returns 0 if the line was processed - 1 otherwise.
1118# Errors are logged in the global $errorflags
1119sub tag_AUTOMAKE ()
1120{
1121 my $lookup = '.*cd \$\(top_srcdir\)\s+&&[\034\s]+\$\(AUTOMAKE\)(.*)';
1122 return 1 if ($MakefileData !~ /\n($lookup)\n/);
1123 print STDOUT "AUTOMAKE processing <$1>\n" if ($verbose);
1124
1125 my $newLine = $1."\n\tcd \$(top_srcdir) && perl $thisProg $printname";
1126 substituteLine ($lookup, $newLine);
1127 $automkCall = $1;
1128
1129 $lookup = '.*cd \$\(srcdir\)\s+&&[\034\s]+\$\(AUTOCONF\)(.*)';
1130 if ($MakefileData =~ /\n($lookup)\n/) {
1131 $newLine = "\tcd \$(srcdir) && rm -f configure && \$(MAKE) -f admin/Makefile.common configure";
1132 substituteLine ($lookup, $newLine);
1133 }
1134
1135 return 0;
1136}
1137
1138#-----------------------------------------------------------------------------
1139
1140sub handle_TOPLEVEL()
1141{
1142 my $pofiles = "";
1143 my @restfiles = ();
1144 opendir (THISDIR, ".");
1145 foreach $entry (readdir(THISDIR)) {
1146 next if (-d $entry);
1147
1148 next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/ || $entry =~ /.gmo$/);
1149
1150 if ($entry =~ /\.po$/) {
1151 next;
1152 }
1153 push(@restfiles, $entry);
1154 }
1155 closedir (THISDIR);
1156
1157 if (@restfiles) {
1158 $target_adds{"install-data-am"} .= "install-nls-files ";
1159 $lines = "install-nls-files:\n";
1160 $lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$kdelang\n";
1161 for $file (@restfiles) {
1162 $lines .= "\t\$(INSTALL_DATA) \$\(srcdir\)/$file \$(DESTDIR)\$(kde_locale)/$kdelang/$file\n";
1163 }
1164 $target_adds{"uninstall"} .= "uninstall-nls-files ";
1165 $lines .= "uninstall-nls-files:\n";
1166 for $file (@restfiles) {
1167 $lines .= "\t-rm -f \$(DESTDIR)\$(kde_locale)/$kdelang/$file\n";
1168 }
1169 appendLines($lines);
1170 }
1171
1172 return 0;
1173}
1174
1175#-----------------------------------------------------------------------------
1176
1177sub tag_SUBDIRS ()
1178{
1179 if ($MakefileData !~ /\nSUBDIRS\s*=\s*\$\(AUTODIRS\)\s*\n/) {
1180 return 1;
1181 }
1182
1183 my $subdirs = ".";
1184
1185 opendir (THISDIR, ".");
1186 foreach $entry (readdir(THISDIR)) {
1187 next if ($entry eq "CVS" || $entry =~ /^\./);
1188 if (-d $entry && -f $entry . "/Makefile.am") {
1189 $subdirs .= " $entry";
1190 next;
1191 }
1192 }
1193 closedir (THISDIR);
1194
1195 substituteLine('SUBDIRS\s*=.*', "SUBDIRS =$subdirs");
1196 return 0;
1197}
1198
1199sub tag_IDLFILES ()
1200{
1201 my @psources = split(/[\034\s]+/, $sources{$program});
1202 my $dep_lines = "";
1203 my @cppFiles = ();
1204
1205 foreach $source (@psources) {
1206 my $skel = ($source =~ m/\.skel$/);
1207 my $stub = ($source =~ m/\.stub$/);
1208 my $signals = ($source =~ m/\.signals$/); # obsolete, remove in KDE-4
1209
1210 if ($stub || $skel || $signals) {
1211
1212 my $qs = quotemeta($source);
1213 $sources{$program} =~ s/$qs//;
1214 $sources_changed{$program} = 1;
1215
1216 $source =~ s/\.(stub|skel|signals)$//;
1217 my $sourcename;
1218
1219 if ($skel) {
1220 $sourcename = "$source\_skel";
1221 } elsif ($stub) {
1222 $sourcename = "$source\_stub";
1223 } else {
1224 $sourcename = "$source\_signals";
1225 }
1226
1227 my $sourcedir = '';
1228 if (-f "$makefileDir/$source.h") {
1229 $sourcedir = '$(srcdir)/';
1230 } else {
1231 if ($MakefileData =~ /\n$source\_DIR\s*=\s*(\S+)\n/) {
1232 $sourcedir = $1;
1233 $sourcedir .= "/" if ($sourcedir !~ /\/$/);
1234 }
1235 }
1236
1237 if ($allidls !~ /$source\_kidl/) {
1238
1239 $dep_lines .= "$source.kidl: $sourcedir$source.h \$(DCOP_DEPENDENCIES)\n";
1240 $dep_lines .= "\t\$(DCOPIDL) $sourcedir$source.h > $source.kidl || ( rm -f $source.kidl ; false )\n";
1241
1242 $allidls .= $source . "_kidl ";
1243 }
1244
1245 if ($allidls !~ /$sourcename/) {
1246
1247 $dep_lines_tmp = "";
1248
1249 if ($skel) {
1250 $dep_lines .= "$sourcename.$cxxsuffix: $source.kidl\n";
1251 $dep_lines .= "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-signals --no-stub $source.kidl\n";
1252 } elsif ($stub) {
1253 $dep_lines_tmp = "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-signals --no-skel $source.kidl\n";
1254 } else { # signals - obsolete, remove in KDE 4
1255 $dep_lines_tmp = "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-stub --no-skel $source.kidl\n";
1256 }
1257
1258 if ($stub || $signals) {
1259 $target_adds{"$sourcename.$cxxsuffix"} .= "$sourcename.h ";
1260 $dep_lines .= "$sourcename.h: $source.kidl\n";
1261 $dep_lines .= $dep_lines_tmp;
1262 }
1263
1264 $allidls .= $sourcename . " ";
1265 }
1266
1267 $idlfiles{$program} .= $sourcename . " ";
1268
1269 if ($program =~ /_la$/) {
1270 $realObjs{$program} .= " $sourcename.lo";
1271 } else {
1272 $realObjs{$program} .= " $sourcename.\$(OBJEXT)";
1273 }
1274 $sources{$program} .= " $sourcename.$cxxsuffix";
1275 $sources_changed{$program} = 1;
1276 $important{$program} .= "$sourcename.h " if (!$skel);
1277 $idl_output .= "\\\n\t$sourcename.$cxxsuffix $sourcename.h $source.kidl ";
1278 push(@cleanfiles, "$sourcename.$cxxsuffix");
1279 push(@cleanfiles, "$sourcename.h");
1280 push(@cleanfiles, "$sourcename.kidl");
1281 $dep_files .= " \$(DEPDIR)/$sourcename.P" if ($dep_files !~/$sourcename.P/);
1282 }
1283 }
1284 if ($dep_lines) {
1285 appendLines($dep_lines);
1286 }
1287
1288 if (0) {
1289 my $lookup = "($program)";
1290 $lookup .= '(|\$\(EXEEXT\))';
1291 $lookup =~ s/\_/./g;
1292 $lookup .= ":(.*..$program\_OBJECTS..*)";
1293 # $lookup = quotemeta($lookup);
1294 if ($MakefileData =~ /\n$lookup\n/) {
1295
1296 my $line = "$1$2: ";
1297 foreach $file (split(' ', $idlfiles{$program})) {
1298 $line .= "$file.$cxxsuffix ";
1299 }
1300 $line .= $3;
1301 substituteLine($lookup, $line);
1302 } else {
1303 print STDERR "no built dependency found $lookup\n";
1304 }
1305 }
1306}
1307
1308sub tag_UIFILES ()
1309{
1310 my @psources = split(/[\034\s]+/, $sources{$program});
1311 my @depFiles = ();
1312
1313 foreach $source (@psources) {
1314
1315 if ($source =~ m/\.ui$/) {
1316
1317 print STDERR "adding UI file $source\n" if ($verbose);
1318
1319 my $qs = quotemeta($source);
1320 $sources{$program} =~ s/$qs//;
1321 $sources_changed{$program} = 1;
1322
1323 $source =~ s/\.ui$//;
1324
1325 my $sourcedir = '';
1326 if (-f "$makefileDir/$source.ui") {
1327 $sourcedir = '$(srcdir)/';
1328 }
1329
1330 if (!$uiFiles{$source}) {
1331
1332 my $dep_lines = "$source.$cxxsuffix: $sourcedir$source.ui $source.h $source.moc\n";
1333 $dep_lines .= "\trm -f $source.$cxxsuffix\n";
1334 if (!$kdeopts{"qtonly"}) {
1335 $dep_lines .= "\techo '#include <klocale.h>' > $source.$cxxsuffix\n";
1336 my ($mangled_source) = $source;
1337 $mangled_source =~ s/[^A-Za-z0-9]/_/g; # get rid of garbage
1338 $dep_lines .= "\t\$(UIC) -tr \${UIC_TR} -i $source.h $sourcedir$source.ui > $source.$cxxsuffix.temp ; ret=\$\$?; \\\n";
1339 $dep_lines .= "\tsed -e \"s,\${UIC_TR}( \\\"\\\" ),QString::null,g\" $source.$cxxsuffix.temp | sed -e \"s,\${UIC_TR}( \\\"\\\"\\, \\\"\\\" ),QString::null,g\" | sed -e \"s,image\\([0-9][0-9]*\\)_data,img\\1_" . $mangled_source . ",g\" >> $source.$cxxsuffix ;\\\n";
1340 $dep_lines .= "\trm -f $source.$cxxsuffix.temp ;\\\n";
1341 } else {
1342 $dep_lines .= "\t\$(UIC) -i $source.h $sourcedir$source.ui > $source.$cxxsuffix; ret=\$\$?; \\\n";
1343 }
1344 $dep_lines .= "\tif test \"\$\$ret\" = 0; then echo '#include \"$source.moc\"' >> $source.$cxxsuffix; else rm -f $source.$cxxsuffix ; exit \$\$ret ; fi\n\n";
1345 $dep_lines .= "$source.h: $sourcedir$source.ui\n";
1346 $dep_lines .= "\t\$(UIC) -o $source.h $sourcedir$source.ui\n\n";
1347 $dep_lines .= "$source.moc: $source.h\n";
1348 $dep_lines .= "\t\$(MOC) $source.h -o $source.moc\n";
1349
1350 $rule_adds{"$source.$cxxsuffix"} = $dep_lines;
1351
1352 $uiFiles{$source} = 1;
1353 $dependmocs{$program} .= " $source.moc";
1354 $globalmocs{$source} = "\035$source.h\035$source.cpp";
1355 }
1356
1357 if ($program =~ /_la$/) {
1358 $realObjs{$program} .= " $source.lo";
1359 } else {
1360 $realObjs{$program} .= " $source.\$(OBJEXT)";
1361 }
1362 $sources{$program} .= " $source.$cxxsuffix";
1363 $sources_changed{$program} = 1;
1364 $important{$program} .= "$source.h ";
1365 $ui_output .= "\\\n\t$source.$cxxsuffix $source.h $source.moc ";
1366 push(@cleanfiles, "$source.$cxxsuffix");
1367 push(@cleanfiles, "source.h");
1368 push(@cleanfiles, "$source.moc");
1369 $dep_files .= " \$(DEPDIR)/$source.P" if($dep_files !~/$source.P/ );
1370 }
1371 }
1372}
1373
1374sub tag_ICON()
1375{
1376 my $lookup = '([^\s]*)_ICON\s*=[ \t]*(.*)';
1377 my $install = "";
1378 my $uninstall = "";
1379
1380 while ($MakefileData =~ /\n$lookup/g) {
1381 my $destdir;
1382 if ($1 eq "KDE") {
1383 $destdir = "kde_icondir";
1384 } else {
1385 $destdir = $1 . "dir";
1386 }
1387 my $iconauto = ($2 =~ /AUTO\s*$/);
1388 my @appnames = ();
1389 if ( ! $iconauto ) {
1390 my $appicon_str = $2;
1391 my @_appnames = split(" ", $appicon_str);
1392 print STDOUT "KDE_ICON processing <@_appnames>\n" if ($verbose);
1393 foreach $appname (@_appnames) {
1394 push(@appnames, quotemeta($appname));
1395 }
1396 } else {
1397 print STDOUT "KDE_ICON processing <AUTO>\n" if ($verbose);
1398 }
1399
1400 my @files = ();
1401 opendir (THISDIR, ".");
1402 foreach $entry (readdir(THISDIR)) {
1403 next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
1404 next if (! -f $entry);
1405 if ( $iconauto )
1406 {
1407 push(@files, $entry)
1408 if ($entry =~ /\.xpm/ || $entry =~ /\.png/ || $entry =~ /\.mng/ || $entry =~ /\.svg/);
1409 } else {
1410 foreach $appname (@appnames) {
1411 push(@files, $entry)
1412 if ($entry =~ /-$appname\.xpm/ || $entry =~ /-$appname\.png/ || $entry =~ /-$appname\.mng/ || $entry =~ /-$appname\.svg/);
1413 }
1414 }
1415 }
1416 closedir (THISDIR);
1417
1418 my %directories = ();
1419
1420 foreach $file (@files) {
1421 my $newfile = $file;
1422 my $prefix = $file;
1423 $prefix =~ s/\.(png|xpm|mng|svg|svgz)$//;
1424 my $appname = $prefix;
1425 $appname =~ s/^[^-]+-// if ($appname =~ /-/) ;
1426 $appname =~ s/^[^-]+-// if ($appname =~ /-/) ;
1427 $appname = quotemeta($appname);
1428 $prefix =~ s/$appname$//;
1429 $prefix =~ s/-$//;
1430
1431 $prefix = 'lo16-app' if ($prefix eq 'mini');
1432 $prefix = 'lo32-app' if ($prefix eq 'lo');
1433 $prefix = 'hi48-app' if ($prefix eq 'large');
1434 $prefix .= '-app' if ($prefix =~ m/^...$/);
1435
1436 my $type = $prefix;
1437 $type =~ s/^.*-([^-]+)$/$1/;
1438 $prefix =~ s/^(.*)-[^-]+$/$1/;
1439
1440 my %type_hash =
1441 (
1442 'action' => 'actions',
1443 'app' => 'apps',
1444 'device' => 'devices',
1445 'filesys' => 'filesystems',
1446 'mime' => 'mimetypes'
1447 );
1448
1449 if (! defined $type_hash{$type} ) {
1450 print STDERR "unknown icon type $type in $printname ($file)\n";
1451 next;
1452 }
1453
1454 my %dir_hash =
1455 (
1456 'los' => 'locolor/16x16',
1457 'lom' => 'locolor/32x32',
1458 'him' => 'hicolor/32x32',
1459 'hil' => 'hicolor/48x48',
1460 'lo16' => 'locolor/16x16',
1461 'lo22' => 'locolor/22x22',
1462 'lo32' => 'locolor/32x32',
1463 'hi16' => 'hicolor/16x16',
1464 'hi22' => 'hicolor/22x22',
1465 'hi32' => 'hicolor/32x32',
1466 'hi48' => 'hicolor/48x48',
1467 'hi64' => 'hicolor/64x64',
1468 'hi128' => 'hicolor/128x128',
1469 'hisc' => 'hicolor/scalable',
1470 'cr16' => 'crystalsvg/16x16',
1471 'cr22' => 'crystalsvg/22x22',
1472 'cr32' => 'crystalsvg/32x32',
1473 'cr48' => 'crystalsvg/48x48',
1474 'cr64' => 'crystalsvg/64x64',
1475 'cr128' => 'crystalsvg/128x128',
1476 'crsc' => 'crystalsvg/scalable'
1477 );
1478
1479 $newfile =~ s@.*-($appname\.(png|xpm|mng|svgz|svg?))@$1@;
1480
1481 if (! defined $dir_hash{$prefix}) {
1482 print STDERR "unknown icon prefix $prefix in $printname\n";
1483 next;
1484 }
1485
1486 my $dir = $dir_hash{$prefix} . "/" . $type_hash{$type};
1487 if ($newfile =~ /-[^\.]/) {
1488 my $tmp = $newfile;
1489 $tmp =~ s/^([^-]+)-.*$/$1/;
1490 $dir = $dir . "/" . $tmp;
1491 $newfile =~ s/^[^-]+-//;
1492 }
1493
1494 if (!defined $directories{$dir}) {
1495 $install .= "\t\$(mkinstalldirs) \$(DESTDIR)\$($destdir)/$dir\n";
1496 $directories{$dir} = 1;
1497 }
1498
1499 $install .= "\t\$(INSTALL_DATA) \$(srcdir)/$file \$(DESTDIR)\$($destdir)/$dir/$newfile\n";
1500 $uninstall .= "\t-rm -f \$(DESTDIR)\$($destdir)/$dir/$newfile\n";
1501
1502 }
1503 }
1504
1505 if (length($install)) {
1506 $target_adds{"install-data-am"} .= "install-kde-icons ";
1507 $target_adds{"uninstall-am"} .= "uninstall-kde-icons ";
1508 appendLines("install-kde-icons:\n" . $install . "\nuninstall-kde-icons:\n" . $uninstall);
1509 }
1510}
1511
1512sub handle_POFILES($$)
1513{
1514 my @pofiles = split(" ", $_[0]);
1515 my $lang = $_[1];
1516
1517 # Build rules for creating the gmo files
1518 my $tmp = "";
1519 my $allgmofiles = "";
1520 my $pofileLine = "POFILES =";
1521 foreach $pofile (@pofiles)
1522 {
1523 $pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1524 $tmp .= "$1.gmo: $pofile\n";
1525 $tmp .= "\trm -f $1.gmo; \$(GMSGFMT) -o $1.gmo \$(srcdir)/$pofile\n";
1526 $tmp .= "\ttest ! -f $1.gmo || touch $1.gmo\n";
1527 $allgmofiles .= " $1.gmo";
1528 $pofileLine .= " $1.po";
1529 }
1530 appendLines ($tmp);
1531 my $lookup = 'POFILES\s*=([^\n]*)';
1532 if ($MakefileData !~ /\n$lookup/) {
1533 appendLines("$pofileLine\nGMOFILES =$allgmofiles");
1534 } else {
1535 substituteLine ($lookup, "$pofileLine\nGMOFILES =$allgmofiles");
1536 }
1537
1538 if ($allgmofiles) {
1539
1540 # Add the "clean" rule so that the maintainer-clean does something
1541 appendLines ("clean-nls:\n\t-rm -f $allgmofiles\n");
1542
1543 $target_adds{"maintainer-clean"} .= "clean-nls ";
1544
1545 $lookup = 'DISTFILES\s*=[ \t]*(.*)';
1546 if ($MakefileData =~ /\n$lookup/) {
1547 $tmp = "DISTFILES = \$(GMOFILES) \$(POFILES) $1";
1548 substituteLine ($lookup, $tmp);
1549 }
1550 }
1551
1552 $target_adds{"install-data-am"} .= "install-nls ";
1553
1554 $tmp = "install-nls:\n";
1555 if ($lang) {
1556 $tmp .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES\n";
1557 }
1558 $tmp .= "\t\@for base in ";
1559 foreach $pofile (@pofiles)
1560 {
1561 $pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1562 $tmp .= "$1 ";
1563 }
1564
1565 $tmp .= "; do \\\n";
1566 if ($lang) {
1567 $tmp .= "\t echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n";
1568 $tmp .= "\t if test -f \$\$base.gmo; then \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n";
1569 $tmp .= "\t elif test -f \$(srcdir)/\$\$base.gmo; then \$(INSTALL_DATA) \$(srcdir)/\$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n";
1570 $tmp .= "\t fi ;\\\n";
1571 } else {
1572 $tmp .= "\t echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
1573 $tmp .= "\t \$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES ; \\\n";
1574 $tmp .= "\t if test -f \$\$base.gmo; then \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
1575 $tmp .= "\t elif test -f \$(srcdir)/\$\$base.gmo; then \$(INSTALL_DATA) \$(srcdir)/\$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
1576 $tmp .= "\t fi ;\\\n";
1577 }
1578 $tmp .= "\tdone\n\n";
1579 appendLines ($tmp);
1580
1581 $target_adds{"uninstall"} .= "uninstall-nls ";
1582
1583 $tmp = "uninstall-nls:\n";
1584 foreach $pofile (@pofiles)
1585 {
1586 $pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1587 if ($lang) {
1588 $tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/$1.mo\n";
1589 } else {
1590 $tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$1/LC_MESSAGES/\$(PACKAGE).mo\n";
1591 }
1592 }
1593 appendLines($tmp);
1594
1595 $target_adds{"all"} .= "all-nls ";
1596
1597 $tmp = "all-nls: \$(GMOFILES)\n";
1598
1599 appendLines($tmp);
1600
1601 $target_adds{"distdir"} .= "distdir-nls ";
1602
1603 $tmp = "distdir-nls:\$(GMOFILES)\n";
1604 $tmp .= "\tfor file in \$(POFILES); do \\\n";
1605 $tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n";
1606 $tmp .= "\tdone\n";
1607 $tmp .= "\tfor file in \$(GMOFILES); do \\\n";
1608 $tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n";
1609 $tmp .= "\tdone\n";
1610
1611 appendLines ($tmp);
1612
1613 if (!$lang) {
1614 appendLines("merge:\n\t\$(MAKE) -C \$(top_srcdir)/po -f \$(top_srcdir)/admin/Makefile.common package-merge POFILES=\"\${POFILES}\" PACKAGE=\${PACKAGE}\n\n");
1615 }
1616
1617}
1618
1619#-----------------------------------------------------------------------------
1620
1621# Returns 0 if the line was processed - 1 otherwise.
1622# Errors are logged in the global $errorflags
1623sub tag_POFILES ()
1624{
1625 my $lookup = 'POFILES\s*=([^\n]*)';
1626 return 1 if ($MakefileData !~ /\n$lookup/);
1627 print STDOUT "POFILES processing <$1>\n" if ($verbose);
1628
1629 my $tmp = $1;
1630
1631 # make sure these are all gone.
1632 if ($MakefileData =~ /\n\.po\.gmo:\n/)
1633 {
1634 print STDERR "Warning: Found old .po.gmo rules in $printname. New po rules not added\n";
1635 return 1;
1636 }
1637
1638 # Either find the pofiles in the directory (AUTO) or use
1639 # only the specified po files.
1640 my $pofiles = "";
1641 if ($tmp =~ /^\s*AUTO\s*$/)
1642 {
1643 opendir (THISDIR, ".");
1644 $pofiles = join(" ", grep(/\.po$/, readdir(THISDIR)));
1645 closedir (THISDIR);
1646 print STDOUT "pofiles found = $pofiles\n" if ($verbose);
1647 if (-f "charset" && -f "kdelibs.po") {
1648 handle_TOPLEVEL();
1649 }
1650 }
1651 else
1652 {
1653 $tmp =~ s/\034/ /g;
1654 $pofiles = $tmp;
1655 }
1656 return 1 if (!$pofiles); # Nothing to do
1657
1658 handle_POFILES($pofiles, $kdelang);
1659
1660 return 0;
1661}
1662
1663sub helper_LOCALINSTALL($)
1664{
1665 my $lookup = "\035" . $_[0] . " *:[^\035]*\035\t";
1666 my $copy = $MakefileData;
1667 $copy =~ s/\n/\035/g;
1668 if ($copy =~ /($lookup.*)$/) {
1669
1670 $install = $1;
1671 $install =~ s/\035$_[0] *:[^\035]*\035//;
1672 my $emptyline = 0;
1673 while (! $emptyline ) {
1674 if ($install =~ /([^\035]*)\035(.*)/) {
1675 local $line = $1;
1676 $install = $2;
1677 if ($line !~ /^\s*$/ && $line !~ /^(\@.*\@)*\t/) {
1678 $emptyline = 1;
1679 } else {
1680 replaceDestDir($line);
1681 }
1682 } else {
1683 $emptyline = 1;
1684 }
1685 }
1686 }
1687
1688}
1689
1690sub tag_LOCALINSTALL ()
1691{
1692 helper_LOCALINSTALL('install-exec-local');
1693 helper_LOCALINSTALL('install-data-local');
1694 helper_LOCALINSTALL('uninstall-local');
1695
1696 return 0;
1697}
1698
1699sub replaceDestDir($) {
1700 local $line = $_[0];
1701
1702 if ( $line =~ /^\s*(\@.*\@)*\s*\$\(mkinstalldirs\)/
1703 || $line =~ /^\s*(\@.*\@)*\s*\$\(INSTALL\S*\)/
1704 || $line =~ /^\s*(\@.*\@)*\s*(-?rm.*) \S*$/)
1705 {
1706 $line =~ s/^(.*) ([^\s]+)\s*$/$1 \$(DESTDIR)$2/ if ($line !~ /\$\(DESTDIR\)/);
1707 }
1708
1709 if ($line ne $_[0]) {
1710 $_[0] = quotemeta $_[0];
1711 substituteLine($_[0], $line);
1712 }
1713}
1714
1715#---------------------------------------------------------------------------
1716# libtool is very hard to persuade it could use -Wl,--no-undefined for making
1717# -no-undefined actually work
1718# append $(KDE_NO_UNFINED) after every -no-undefined in LDFLAGS
1719# this may go away if libtool ever does this on its own
1720sub tag_NO_UNDEFINED () {
1721 return if ($program !~ /_la$/);
1722
1723 my $lookup = quotemeta($realname{$program}) . ":.*?\n\t.*?\\((.*?)\\) .*\n";
1724 $MakefileData =~ m/$lookup/;
1725 return if (!defined($1));
1726 return if ($1 !~ /CXXLINK/);
1727
1728 if ($MakefileData !~ /\n$program\_LDFLAGS\s*=.*-no-undefined/ ) {
1729 return;
1730 }
1731
1732 $lookup = $program . '\_LDFLAGS(\s*)=(.*)-no-undefined(.*)';
1733 if ($MakefileData =~ /\n$lookup\n/) {
1734 my $replace = $program . "\_LDFLAGS$1=$2-no-undefined \$(KDE_NO_UNDEFINED)$3";
1735 substituteLine($lookup, $replace);
1736 }
1737}
1738
1739sub tag_CLOSURE () {
1740 return if ($program !~ /_la$/);
1741
1742 my $lookup = quotemeta($realname{$program}) . ":.*?\n\t.*?\\((.*?)\\) .*\n";
1743 $MakefileData =~ m/$lookup/;
1744 return if (!defined($1));
1745 return if ($1 !~ /CXXLINK/);
1746
1747 if ($MakefileData !~ /\n$program\_LDFLAGS\s*=.*-no-undefined/ &&
1748 $MakefileData !~ /\n$program\_LDFLAGS\s*=.*KDE_PLUGIN/ ) {
1749 print STDERR "Report: $program contains undefined in $printname\n" if ($program =~ /^lib/ && $dryrun);
1750 return;
1751 }
1752
1753 my $closure = $realname{$program} . ".closure";
1754 my $lines = "$closure: \$($program\_OBJECTS) \$($program\_DEPENDENCIES)\n";
1755 $lines .= "\t\@echo \"int main() {return 0;}\" > $program\_closure.$cxxsuffix\n";
1756 $lines .= "\t\@\$\(LTCXXCOMPILE\) -c $program\_closure.$cxxsuffix\n";
1757 $lines .= "\t\$\(CXXLINK\) $program\_closure.lo \$($program\_LDFLAGS) \$($program\_OBJECTS) \$($program\_LIBADD) \$(LIBS)\n";
1758 $lines .= "\t\@rm -f $program\_closure.* $closure\n";
1759 $lines .= "\t\@echo \"timestamp\" > $closure\n";
1760 $lines .= "\n";
1761 appendLines($lines);
1762 $lookup = $realname{$program} . ": (.*)";
1763 if ($MakefileData =~ /\n$lookup\n/) {
1764 $lines = "\@KDE_USE_CLOSURE_TRUE@". $realname{$program} . ": $closure $1";
1765 $lines .= "\n\@KDE_USE_CLOSURE_FALSE@" . $realname{$program} . ": $1";
1766 substituteLine($lookup, $lines);
1767 }
1768 $closure_output .= " $closure";
1769}
1770
1771sub tag_NMCHECK () {
1772 return if ($program !~ /_la$/);
1773 my $lookup = quotemeta($realname{$program}) . ":.*?\n\t.*?\\((.*?)\\) .*\n";
1774 $MakefileData =~ m/$lookup/;
1775 my $linkcmd = $1;
1776 return if (!defined($1));
1777 return if ($linkcmd !~ /CXXLINK/ && $linkcmd !~ /LINK/);
1778
1779 $lookup = $program . '_NMCHECK\s*=([^\n]*)';
1780 if( $MakefileData !~ m/\n$lookup\n/ ) {
1781 return;
1782 }
1783 my $allowed = $1;
1784 $allowed =~ s/^ *//;
1785 $lookup = $program . '_NMCHECKWEAK\s*=([^\n]*)';
1786 my $weak = "";
1787 my $is_weak = 0;
1788 if( $MakefileData =~ m/\n$lookup\n/ ) {
1789 $weak = $1;
1790 $is_weak = 1;
1791 }
1792 $weak =~ s/^ *//;
1793
1794 if( $is_weak )
1795 {
1796 $weak = '--allowweak=\'' . $weak . '\' ';
1797 }
1798 my $nmline = "\@KDE_USE_NMCHECK_TRUE@\t\@\$(MAKE) \$(AM_MAKEFLAGS) nmcheck_$realname{$program} || ( rm -f $realname{$program}; exit 1 )";
1799 $lookup = '(\t\$\(CXXLINK\)[^\n]*' . $program . '_OBJECTS[^\n]*)';
1800 if( $MakefileData =~ /\n$lookup\n/ ) {
1801 my $oldstuff = $1;
1802 substituteLine( $lookup, $oldstuff . "\n" . $nmline );
1803 }
1804 $lookup = '(\t\$\(LINK\)[^\n]*' . $program . '_OBJECTS[^\n]*)';
1805 if( $MakefileData =~ /\n$lookup\n/ ) {
1806 my $oldstuff = $1;
1807 substituteLine( $lookup, $oldstuff . "\n" . $nmline );
1808 }
1809 $nmline = "\@\$(top_srcdir)/admin/nmcheck $realname{$program} \'$allowed\' $weak";
1810 appendLines( "\nnmcheck_$realname{$program}: $realname{$program} \n\t$nmline\n" );
1811 $target_adds{ "nmcheck" } .= "nmcheck_$realname{$program} ";
1812}
1813
1814sub tag_DIST () {
1815 my %foundfiles = ();
1816 opendir (THISDIR, ".");
1817 foreach $entry (readdir(THISDIR)) {
1818 next if ($entry eq "CVS" || $entry =~ /^\./ || $entry eq "Makefile" || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
1819 next if (! -f $entry);
1820 next if ($entry =~ /\.moc/ || $entry =~ /\.moc.$cppExt$/ || $entry =~ /\.lo$/ || $entry =~ /\.la$/ || $entry =~ /\.o/);
1821 next if ($entry =~ /\.all_$cppExt\.$cppExt$/);
1822 $foundfiles{$entry} = 1;
1823 }
1824 closedir (THISDIR);
1825
1826 # doing this for MAINTAINERCLEANFILES would be wrong
1827 my @marks = ("EXTRA_DIST", "DIST_COMMON", '\S*_SOURCES', '\S*_HEADERS', 'CLEANFILES', 'DISTCLEANFILES', '\S*_OBJECTS');
1828 foreach $mark (@marks) {
1829 while ($MakefileData =~ /\n($mark)\s*=[ \t]*([^\n]*)/g) {
1830 my $cleanfiles_str = $2;
1831 foreach $file (split('[\034\s]+', $cleanfiles_str)) {
1832 $file =~ s/\.\///;
1833 $foundfiles{$file} = 0 if (defined $foundfiles{$file});
1834 }
1835 }
1836 }
1837 my @files = ("Makefile", "config.cache", "config.log", "stamp-h",
1838 "stamp-h1", "stamp-h1", "config.h", "Makefile",
1839 "config.status", "config.h", "libtool", "core" );
1840 foreach $file (@files) {
1841 $foundfiles{$file} = 0 if (defined $foundfiles{$file});
1842 }
1843
1844 my $KDE_DIST = "";
1845 foreach $file (keys %foundfiles) {
1846 if ($foundfiles{$file} == 1) {
1847 $KDE_DIST .= "$file ";
1848 }
1849 }
1850 if ($KDE_DIST) {
1851 print "KDE_DIST $printname $KDE_DIST\n" if ($verbose);
1852
1853 my $lookup = 'DISTFILES\s*=[ \t]*(.*)';
1854 if ($MakefileData =~ /\n$lookup/) {
1855 substituteLine($lookup, "DISTFILES = $1 \$(KDE_DIST)");
1856 appendLines("KDE_DIST=$KDE_DIST\n");
1857 }
1858 }
1859}
1860
1861#-----------------------------------------------------------------------------
1862# Returns 0 if the line was processed - 1 otherwise.
1863# Errors are logged in the global $errorflags
1864sub tag_DOCFILES ()
1865{
1866 $target_adds{"all"} .= "docs-am ";
1867
1868 my $lookup = 'KDE_DOCS\s*=[ \t]*([^\n]*)';
1869 goto nodocs if ($MakefileData !~ /\n$lookup/);
1870 print STDOUT "KDE_DOCS processing <$1>\n" if ($verbose);
1871
1872 my $tmp = $1;
1873
1874 # Either find the files in the directory (AUTO) or use
1875 # only the specified po files.
1876 my $files = "";
1877 my $appname = $tmp;
1878 $appname =~ s/^(\S*)\s*.*$/$1/;
1879 if ($appname =~ /AUTO/) {
1880 $appname = basename($makefileDir);
1881 if ("$appname" eq "en") {
1882 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";
1883 exit(1);
1884 }
1885 }
1886
1887 if ($tmp !~ / - /)
1888 {
1889 opendir (THISDIR, ".");
1890 foreach $entry (readdir(THISDIR)) {
1891 next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/ || $entry eq "core" || $entry eq "index.cache.bz2");
1892 next if (! -f $entry);
1893 $files .= "$entry ";
1894 }
1895 closedir (THISDIR);
1896 print STDOUT "docfiles found = $files\n" if ($verbose);
1897 }
1898 else
1899 {
1900 $tmp =~ s/\034/ /g;
1901 $tmp =~ s/^\S*\s*-\s*//;
1902 $files = $tmp;
1903 }
1904 goto nodocs if (!$files); # Nothing to do
1905
1906 if ($files =~ /(^| )index\.docbook($| )/) {
1907
1908 my $lines = "";
1909 my $lookup = 'MEINPROC\s*=';
1910 if ($MakefileData !~ /\n($lookup)/) {
1911 $lines = "MEINPROC=/\$(kde_bindir)/meinproc\n";
1912 }
1913 $lookup = 'KDE_XSL_STYLESHEET\s*=';
1914 if ($MakefileData !~ /\n($lookup)/) {
1915 $lines .= "KDE_XSL_STYLESHEET=/\$(kde_datadir)/ksgmltools2/customization/kde-chunk.xsl\n";
1916 }
1917 $lookup = '\nindex.cache.bz2:';
1918 if ($MakefileData !~ /\n($lookup)/) {
1919 $lines .= "index.cache.bz2: \$(srcdir)/index.docbook \$(KDE_XSL_STYLESHEET) $files\n";
1920 $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";
1921 $lines .= "\n";
1922 }
1923
1924 $lines .= "docs-am: index.cache.bz2\n";
1925 $lines .= "\n";
1926 $lines .= "install-docs: docs-am install-nls\n";
1927 $lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n";
1928 $lines .= "\t\@if test -f index.cache.bz2; then \\\n";
1929 $lines .= "\techo \$(INSTALL_DATA) index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n";
1930 $lines .= "\t\$(INSTALL_DATA) index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n";
1931 $lines .= "\telif test -f \$(srcdir)/index.cache.bz2; then \\\n";
1932 $lines .= "\techo \$(INSTALL_DATA) \$(srcdir)/index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n";
1933 $lines .= "\t\$(INSTALL_DATA) \$(srcdir)/index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n";
1934 $lines .= "\tfi\n";
1935 $lines .= "\t-rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n";
1936 $lines .= "\t\$(LN_S) \$(kde_libs_htmldir)/$kdelang/common \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n";
1937
1938 $lines .= "\n";
1939 $lines .= "uninstall-docs:\n";
1940 $lines .= "\t-rm -rf \$(kde_htmldir)/$kdelang/$appname\n";
1941 $lines .= "\n";
1942 $lines .= "clean-docs:\n";
1943 $lines .= "\t-rm -f index.cache.bz2\n";
1944 $lines .= "\n";
1945 $target_adds{"install-data-am"} .= "install-docs ";
1946 $target_adds{"uninstall"} .= "uninstall-docs ";
1947 $target_adds{"clean-am"} .= "clean-docs ";
1948 appendLines ($lines);
1949 } else {
1950 appendLines("docs-am: $files\n");
1951 }
1952
1953 $target_adds{"install-data-am"} .= "install-nls ";
1954 $target_adds{"uninstall"} .= "uninstall-nls ";
1955
1956 $tmp = "install-nls:\n";
1957 $tmp .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n";
1958 $tmp .= "\t\@for base in $files; do \\\n";
1959 $tmp .= "\t echo \$(INSTALL_DATA) \$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1960 $tmp .= "\t \$(INSTALL_DATA) \$(srcdir)/\$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1961 $tmp .= "\tdone\n";
1962 if ($appname eq 'common') {
1963 $tmp .= "\t\@echo \"merging common and language specific dir\" ;\\\n";
1964 $tmp .= "\tif test ! -f \$(kde_htmldir)/en/common/kde-common.css; then echo 'no english docs found in \$(kde_htmldir)/en/common/'; exit 1; fi \n";
1965 $tmp .= "\t\@com_files=`cd \$(kde_htmldir)/en/common && echo *` ;\\\n";
1966 $tmp .= "\tcd \$(DESTDIR)\$(kde_htmldir)/$kdelang/common ;\\\n";
1967 $tmp .= "\tif test -n \"\$\$com_files\"; then for p in \$\$com_files ; do \\\n";
1968 $tmp .= "\t case \" $files \" in \\\n";
1969 $tmp .= "\t *\" \$\$p \"*) ;; \\\n";
1970 $tmp .= "\t *) test ! -f \$\$p && echo \$(LN_S) ../../en/common/\$\$p \$(DESTDIR)\$(kde_htmldir)/$kdelang/common/\$\$p && \$(LN_S) ../../en/common/\$\$p \$\$p ;; \\\n";
1971 $tmp .= "\t esac ; \\\n";
1972 $tmp .= "\tdone ; fi ; true\n";
1973 }
1974 $tmp .= "\n";
1975 $tmp .= "uninstall-nls:\n";
1976 $tmp .= "\tfor base in $files; do \\\n";
1977 $tmp .= "\t rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1978 $tmp .= "\tdone\n\n";
1979 appendLines ($tmp);
1980
1981 $target_adds{"distdir"} .= "distdir-nls ";
1982
1983 $tmp = "distdir-nls:\n";
1984 $tmp .= "\tfor file in $files; do \\\n";
1985 $tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n";
1986 $tmp .= "\tdone\n";
1987
1988 appendLines ($tmp);
1989
1990 return 0;
1991
1992 nodocs:
1993 appendLines("docs-am:\n");
1994 return 1;
1995}
1996
1997#-----------------------------------------------------------------------------
1998# Find headers in any of the source directories specified previously, that
1999# are candidates for "moc-ing".
2000sub findMocCandidates ()
2001{
2002 foreach $dir (@headerdirs)
2003 {
2004 my @list = ();
2005 opendir (SRCDIR, "$dir");
2006 @hFiles = grep { /.+\.$hExt$/o && !/^\./ } readdir(SRCDIR);
2007 closedir SRCDIR;
2008 foreach $hf (@hFiles)
2009 {
2010 next if ($hf =~ /^\.\#/);
2011 $hf =~ /(.*)\.[^\.]*$/; # Find name minus extension
2012 next if ($uiFiles{$1});
2013 open (HFIN, "$dir/$hf") || die "Could not open $dir/$hf: $!\n";
2014 my $hfsize = 0;
2015 seek(HFIN, 0, 2);
2016 $hfsize = tell(HFIN);
2017 seek(HFIN, 0, 0);
2018 read HFIN, $hfData, $hfsize;
2019 close HFIN;
2020 # push (@list, $hf) if(index($hfData, "Q_OBJECT") >= 0); ### fast but doesn't handle //Q_OBJECT
2021 # handle " { friend class blah; Q_OBJECT ", but don't match antlarr_Q_OBJECT (\b).
2022 if ( $hfData =~ /{([^}]*)\bQ_OBJECT/s ) {
2023 push (@list, $hf) unless $1 =~ m://[^\n]*Q_OBJECT[^\n]*$:s; ## reject "// Q_OBJECT"
2024 }
2025 }
2026 # The assoc array of root of headerfile and header filename
2027 foreach $hFile (@list)
2028 {
2029 $hFile =~ /(.*)\.[^\.]*$/; # Find name minus extension
2030 if ($mocFiles{$1})
2031 {
2032 print STDERR "Warning: Multiple header files found for $1\n";
2033 next; # Use the first one
2034 }
2035 $mocFiles{$1} = "$dir\035$hFile"; # Add relative dir
2036 }
2037 }
2038
2039 return 0;
2040}
2041
2042#-----------------------------------------------------------------------------
2043
2044# The programmer has specified a moc list. Prune out the moc candidates
2045# list that we found based on looking at the header files. This generates
2046# a warning if the programmer gets the list wrong, but this doesn't have
2047# to be fatal here.
2048sub pruneMocCandidates ($)
2049{
2050 my %prunedMoc = ();
2051 local @mocList = split(' ', $_[0]);
2052
2053 foreach $mocname (@mocList)
2054 {
2055 $mocname =~ s/\.moc$//;
2056 if ($mocFiles{$mocname})
2057 {
2058 $prunedMoc{$mocname} = $mocFiles{$mocname};
2059 }
2060 else
2061 {
2062 my $print = $makefileDir;
2063 $print =~ s/^\Q$topdir\E\\//;
2064 # They specified a moc file but we can't find a header that
2065 # will generate this moc file. That's possible fatal!
2066 print STDERR "Warning: No moc-able header file for $print/$mocname\n";
2067 }
2068 }
2069
2070 undef %mocFiles;
2071 %mocFiles = %prunedMoc;
2072}
2073
2074#-----------------------------------------------------------------------------
2075
2076# Finds the cpp files (If they exist).
2077# The cpp files get appended to the header file separated by \035
2078sub checkMocCandidates ()
2079{
2080 my @cppFiles;
2081 my $cpp2moc; # which c++ file includes which .moc files
2082 my $moc2cpp; # which moc file is included by which c++ files
2083
2084 return unless (keys %mocFiles);
2085 opendir(THISDIR, ".") || return;
2086 @cppFiles = grep { /.+\.$cppExt$/o && !/.+\.moc\.$cppExt$/o
2087 && !/.+\.all_$cppExt\.$cppExt$/o
2088 && !/^\./ } readdir(THISDIR);
2089 closedir THISDIR;
2090 return unless (@cppFiles);
2091 my $files = join (" ", @cppFiles);
2092 $cpp2moc = {};
2093 $moc2cpp = {};
2094 foreach $cxxf (@cppFiles)
2095 {
2096 open (CXXFIN, $cxxf) || die "Could not open $cxxf: $!\n";
2097 seek(CXXFIN, 0, 2);
2098 my $cxxfsize = tell(CXXFIN);
2099 seek(CXXFIN, 0, 0);
2100 read CXXFIN, $cxxfData, $cxxfsize;
2101 close CXXFIN;
2102 while(($cxxfData =~ m/^[ \t]*\#include\s*[<\"](.*\.moc)[>\"]/gm)) {
2103 $cpp2moc->{$cxxf}->{$1} = 1;
2104 $moc2cpp->{$1}->{$cxxf} = 1;
2105 }
2106 }
2107 foreach my $mocFile (keys (%mocFiles))
2108 {
2109 @cppFiles = keys %{$moc2cpp->{"$mocFile.moc"}};
2110 if (@cppFiles == 1) {
2111 $mocFiles{$mocFile} .= "\035" . $cppFiles[0];
2112 push(@depend, $mocFile);
2113 } elsif (@cppFiles == 0) {
2114 push (@newObs, $mocFile); # Produce new object file
2115 next if ($haveAutomocTag); # This is expected...
2116 # But this is an error we can deal with - let them know
2117 print STDERR
2118 "Warning: No c++ file that includes $mocFile.moc\n";
2119 } else {
2120 # We can't decide which file to use, so it's fatal. Although as a
2121 # guess we could use the mocFile.cpp file if it's in the list???
2122 print STDERR
2123 "Error: Multiple c++ files that include $mocFile.moc\n";
2124 print STDERR "\t",join ("\t", @cppFiles),"\n";
2125 $errorflag = 1;
2126 delete $mocFiles{$mocFile};
2127 # Let's continue and see what happens - They have been told!
2128 }
2129 }
2130}
2131
2132#-----------------------------------------------------------------------------
2133
2134# Add the rules for generating moc source from header files
2135# For Automoc output *.moc.cpp but normally we'll output *.moc
2136# (We must compile *.moc.cpp separately. *.moc files are included
2137# in the appropriate *.cpp file by the programmer)
2138sub addMocRules ()
2139{
2140 my $cppFile;
2141 my $hFile;
2142
2143 foreach $mocFile (keys (%mocFiles))
2144 {
2145 undef $cppFile;
2146 ($dir, $hFile, $cppFile) = split ("\035", $mocFiles{$mocFile}, 3);
2147 $dir =~ s#^\.#\$(srcdir)#;
2148 if (defined ($cppFile))
2149 {
2150 $cppFile =~ s,\.[^.]*$,,;
2151 $target_adds{"$cppFile.o"} .= "$mocFile.moc ";
2152 $target_adds{"$cppFile.lo"} .= "$mocFile.moc ";
2153 appendLines ("$mocFile.moc: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile.moc\n");
2154 $cleanMoc .= " $mocFile.moc";
2155 appendLines ("mocs: $mocFile.moc\n");
2156 }
2157 else
2158 {
2159 appendLines ("$mocFile$mocExt: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile$mocExt\n");
2160 $cleanMoc .= " $mocFile$mocExt";
2161 appendLines ("mocs: $mocFile$mocExt\n");
2162 }
2163 }
2164}
2165
2166sub make_bcheck_target()
2167{
2168 my $lookup = 'RECURSIVE_TARGETS\s*=[ \t]*(.*)';
2169 my $bcheckdep = "bcheck-am";
2170 $bcheckdep = "bcheck-recursive" if ($MakefileData =~ /\n$lookup/);
2171
2172 my $headers= "";
2173 $headers = $1 if($MakefileData =~ /\nHEADERS\s*=[ \t]*(.+)/);
2174 $headers =~ s/\$\((?:noinst|EXTRA)_HEADERS\)//g;
2175
2176 $target_adds{"clean-am"} .= "clean-bcheck ";
2177
2178 my $t = "clean-bcheck: \n" .
2179 "\trm -f *.bchecktest.cc *.bchecktest.cc.class a.out\n\n" .
2180 "bcheck: $bcheckdep\n\n" .
2181 "bcheck-am:\n" .
2182 "\t\@for i in $headers; do \\\n" .
2183 "\t if test \$(srcdir)/\$\$i -nt \$\$i.bchecktest.cc; then \\\n" .
2184 "\t echo \"int main() {return 0;}\" > \$\$i.bchecktest.cc ; \\\n" .
2185 "\t echo \"#include \\\"\$\$i\\\"\" >> \$\$i.bchecktest.cc ; \\\n" .
2186 "\t echo \"\$\$i\"; \\\n" .
2187 "\t if ! ";
2188 $t .= $cxxsuffix eq "KKK" ?
2189 "\$(CXX) \$(DEFS) -I. -I\$(srcdir) -I\$(top_builddir) \$(INCLUDES) \$(AM_CPPFLAGS) \$(CPPFLAGS) \$(KDE_CXXFLAGS) " :
2190 "\$(CXXCOMPILE) ";
2191 $t .= " --dump-class-hierarchy \$\$i.bchecktest.cc; then \\\n" .
2192 "\t rm -f \$\$i.bchecktest.cc; exit 1; \\\n" .
2193 "\t fi ; \\\n" .
2194 "\t echo \"\" >> \$\$i.bchecktest.cc.class; \\\n" .
2195 "\t perl \$(top_srcdir)/admin/bcheck.pl \$\$i.bchecktest.cc.class || { rm -f \$\$i.bchecktest.cc; exit 1; }; \\\n" .
2196 "\t rm -f a.out; \\\n" .
2197 "\t fi ; \\\n" .
2198 "\tdone\n";
2199 appendLines("$t\n");
2200}
2201
2202sub make_meta_classes ()
2203{
2204 return if ($kdeopts{"qtonly"});
2205
2206 my $cppFile;
2207 my $hFile;
2208 my $moc_class_headers = "";
2209 foreach $program (@programs) {
2210 my $mocs = "";
2211 my @progsources = split(/[\034\s]+/, $sources{$program});
2212 my @depmocs = split(' ', $dependmocs{$program});
2213 my %shash = (), %mhash = ();
2214 @shash{@progsources} = 1; # we are only interested in the existence
2215 @mhash{@depmocs} = 1;
2216
2217 print STDOUT "program=$program\n" if ($verbose);
2218 print STDOUT "psources=[".join(' ', keys %shash)."]\n" if ($verbose);
2219 print STDOUT "depmocs=[".join(' ', keys %mhash)."]\n" if ($verbose);
2220 print STDOUT "globalmocs=[".join(' ', keys(%globalmocs))."]\n" if ($verbose);
2221 foreach my $mocFile (keys (%globalmocs))
2222 {
2223 my ($dir, $hFile, $cppFile) = split ("\035", $globalmocs{$mocFile}, 3);
2224 if (defined ($cppFile))
2225 {
2226 $mocs .= " $mocFile.moc" if exists $shash{$cppFile};
2227 }
2228 else
2229 {
2230 # Bah. This is the case, if no C++ file includes the .moc
2231 # file. We make a .moc.cpp file for that. Unfortunately this
2232 # is not included in the %sources hash, but rather is mentioned
2233 # in %dependmocs. If the user wants to use AUTO he can't just
2234 # use an unspecific METAINCLUDES. Instead he must use
2235 # program_METAINCLUDES. Anyway, it's not working real nicely.
2236 # E.g. Its not clear what happens if user specifies two
2237 # METAINCLUDES=AUTO in the same Makefile.am.
2238 $mocs .= " $mocFile.moc.$cxxsuffix"
2239 if exists $mhash{$mocFile.".moc.$cxxsuffix"};
2240 }
2241 }
2242 if ($mocs) {
2243 print STDOUT "==> mocs=[".$mocs."]\n" if ($verbose);
2244 }
2245 print STDOUT "\n" if $verbose;
2246 }
2247 if ($moc_class_headers) {
2248 appendLines ("$cleantarget-moc-classes:\n\t-rm -f $moc_class_headers\n");
2249 $target_adds{"$cleantarget-am"} .= "$cleantarget-moc-classes ";
2250 }
2251}
2252
2253#-----------------------------------------------------------------------------
2254
2255sub updateMakefile ()
2256{
2257 return if ($dryrun);
2258
2259 open (FILEOUT, "> $makefile")
2260 || die "Could not create $makefile: $!\n";
2261
2262 $MakefileData =~ s/\034/\\\n/g; # Restore continuation lines
2263 # Append our $progId line, _below_ the "generated by automake" line
2264 # because automake-1.6 relies on the first line to be his own.
2265 my $progIdLine = "\# $progId - " . '$Revision: 1.1.1.1 $ '."\n";
2266 if ( !( $MakefileData =~ s/^(.*generated .*by automake.*\n)/$1$progIdLine/ ) ) {
2267 warn "automake line not found in $makefile\n";
2268 # Fallback: first line
2269 print FILEOUT $progIdLine;
2270 };
2271 print FILEOUT $MakefileData;
2272 close FILEOUT;
2273}
2274
2275#-----------------------------------------------------------------------------
2276
2277# The given line needs to be removed from the makefile
2278# Do this by adding the special "removed line" comment at the line start.
2279sub removeLine ($$)
2280{
2281 my ($lookup, $old) = @_;
2282
2283 $old =~ s/\034/\\\n#>- /g; # Fix continuation lines
2284 $MakefileData =~ s/\n$lookup/\n#>\- $old/;
2285}
2286
2287#-----------------------------------------------------------------------------
2288
2289# Replaces the old line with the new line
2290# old line(s) are retained but tagged as removed. The new line(s) have the
2291# "added" tag placed before it.
2292sub substituteLine ($$)
2293{
2294 my ($lookup, $new) = @_;
2295
2296 if ($MakefileData =~ /\n($lookup)/) {
2297 $old = $1;
2298 $old =~ s/\034/\\\n#>\- /g; # Fix continuation lines
2299 my $newCount = ($new =~ tr/\034//) + ($new =~ tr/\n//) + 1;
2300 $new =~ s/\\\n/\034/g;
2301 $MakefileData =~ s/\n$lookup/\n#>- $old\n#>\+ $newCount\n$new/;
2302 } else {
2303 warn "Warning: substitution of \"$lookup\" in $printname failed\n";
2304 }
2305}
2306
2307#-----------------------------------------------------------------------------
2308
2309# Slap new lines on the back of the file.
2310sub appendLines ($)
2311{
2312 my ($new) = @_;
2313 my $copynew = $new;
2314 my $newCount = ($new =~ tr/\034//) + ($new =~ tr/\n//) + 1;
2315 $new =~ s/\\\n/\034/g; # Fix continuation lines
2316 $MakefileData .= "\n#>\+ $newCount\n$new";
2317}
2318
2319#-----------------------------------------------------------------------------
2320
2321# Restore the Makefile.in to the state it was before we fiddled with it
2322sub restoreMakefile ()
2323{
2324 $MakefileData =~ s/# $progId[^\n\034]*[\n\034]*//g;
2325 # Restore removed lines
2326 $MakefileData =~ s/([\n\034])#>\- /$1/g;
2327 # Remove added lines
2328 while ($MakefileData =~ /[\n\034]#>\+ ([^\n\034]*)/)
2329 {
2330 my $newCount = $1;
2331 my $removeLines = "";
2332 while ($newCount--) {
2333 $removeLines .= "[^\n\034]*([\n\034]|)";
2334 }
2335 $MakefileData =~ s/[\n\034]#>\+.*[\n\034]$removeLines/\n/;
2336 }
2337}
2338
2339#-----------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.