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