3
# Expands the specialised KDE tags in Makefile.in to (hopefully) valid
5
# When called without file parameters, we work recursively on all Makefile.in
6
# in and below the current subdirectory. When called with file parameters,
7
# only those Makefile.in are changed.
8
# The currently supported tags are
10
# {program}_METASOURCES
11
# where you have a choice of two styles
12
# {program}_METASOURCES = name1.moc name2.moc ... [\]
13
# {program}_METASOURCES = AUTO
14
# The second style requires other tags as well.
17
# KDE_ICON = iconname iconname2 ...
23
# and more new tags TBD!
25
# The concept (and base code) for this program came from automoc,
26
# supplied by the following
28
# Matthias Ettrich <ettrich@kde.org> (The originator)
29
# Kalle Dalheimer <kalle@kde.org> (The original implementator)
30
# Harri Porten <porten@tu-harburg.de>
31
# Alex Zepeda <jazepeda@pacbell.net>
32
# David Faure <faure@kde.org>
33
# Stephan Kulow <coolo@kde.org>
39
# Prototype the functions
41
sub processMakefile ($);
42
sub updateMakefile ();
43
sub restoreMakefile ();
47
sub substituteLine ($$);
49
sub findMocCandidates ();
50
sub pruneMocCandidates ($);
51
sub checkMocCandidates ();
55
sub tag_META_INCLUDES ();
56
sub tag_METASOURCES ();
59
sub tag_LOCALINSTALL();
67
# Some global globals...
68
$verbose = 0; # a debug flag
69
$thisProg = "$0"; # This programs name
70
$topdir = cwd(); # The current directory
71
@makefiles = (); # Contains all the files we'll process
73
$start = (times)[0]; # some stats for testing - comment out for release
76
$cppExt = "(cpp|cc|cxx|C|c\\+\\+)";
77
$hExt = "(h|H|hh|hxx|hpp|h\\+\\+)";
78
$progId = "KDE tags expanded automatically by " . basename($thisProg);
80
$printname = ""; # used to display the directory the Makefile is in
81
$use_final = 1; # create code for --enable-final
82
$cleantarget = "clean";
86
while (defined ($ARGV[0]))
92
print STDOUT basename($thisProg), " $version\n",
93
"This is really free software, unencumbered by the GPL.\n",
94
"You can do anything you like with it except sueing me.\n",
95
"Copyright 1998 Kalle Dalheimer <kalle\@kde.org>\n",
96
"Concept, design and unnecessary questions about perl\n",
97
" by Matthias Ettrich <ettrich\@kde.org>\n\n",
98
"Making it useful by Stephan Kulow <coolo\@kde.org> and\n",
99
"Harri Porten <porten\@kde.org>\n",
100
"Updated (Feb-1999), John Birch <jb.nz\@writeme.com>\n",
101
"Current Maintainer Stephan Kulow\n\n";
104
elsif (/^--verbose$|^-v$/)
106
$verbose = 1; # Oh is there a problem...?
108
elsif (/^-p(.+)$|^--path=(.+)$/)
110
$thisProg = "$1/".basename($thisProg) if($1);
111
$thisProg = "$2/".basename($thisProg) if($2);
112
warn ("$thisProg doesn't exist\n") if (!(-f $thisProg));
115
elsif (/^--help$|^-h$/)
117
print STDOUT "Usage $thisProg [OPTION] ... [dir/Makefile.in]...\n",
119
"Patches dir/Makefile.in generated from automake\n",
120
"(where dir can be a full or relative directory name)",
122
" -v, --verbose verbosely list files processed\n",
123
" -h, --help print this help, then exit\n",
124
" --version print version number, then exit\n",
125
" -p, --path= use the path to am_edit if the path\n",
126
" --no-final don't patch for --enable-final\n",
127
" called from is not the one to be used\n";
131
elsif (/^--no-final$/)
134
$thisProg .= " --no-final";
142
# user selects what input files to check
143
# add full path if relative path is given
144
$_ = cwd()."/".$_ if (! /^\//);
145
print "User wants $_\n" if ($verbose);
146
push (@makefiles, $_);
150
if ($thisProg =~ /^\// && !$pathoption )
152
print STDERR "Illegal full pathname call performed...\n",
153
"The call to \"$thisProg\"\nwould be inserted in some Makefile.in.\n",
154
"Please use option --path.\n";
158
# Only scan for files when the user hasn't entered data
161
print STDOUT "Scanning for Makefile.in\n" if ($verbose);
162
find (\&add_makefile, cwd());
165
print STDOUT "Using user enter input files\n" if ($verbose);
168
foreach $makefile (sort(@makefiles))
170
processMakefile ($makefile);
171
last if ($errorflag);
174
# Just some debug statistics - comment out for release as it uses printf.
175
printf STDOUT "Time %.2f CPU sec\n", (times)[0] - $start if ($verbose);
177
exit $errorflag; # causes make to fail if erroflag is set
179
#-----------------------------------------------------------------------------
181
# In conjunction with the "find" call, this builds the list of input files
184
push (@makefiles, $File::Find::name) if (/Makefile.in$/);
187
#-----------------------------------------------------------------------------
189
# Processes a single make file
190
# The parameter contains the full path name of the Makefile.in to use
191
sub processMakefile ($)
193
# some useful globals for the subroutines called here
194
local ($makefile) = @_;
195
local @headerdirs = ('.');
196
local $haveAutomocTag = 0;
197
local $MakefileData = "";
199
local $cxxsuffix = "KKK";
201
local @programs = (); # lists the names of programs and libraries
204
local %realObjs = (); # lists the objects compiled into $program
205
local %sources = (); # lists the sources used for $program
206
local %finalObjs = (); # lists the objects compiled when final
207
local %realname = (); # the binary name of program variable
208
local %idlfiles = (); # lists the idl files used for $program
209
local %globalmocs = ();# list of all mocfiles (in %mocFiles format)
210
local %important = (); # list of files to be generated asap
214
local $idl_output = "";# lists all idl generated files for cleantarget
215
local $ui_output = "";# lists all uic generated files for cleantarget
217
local %depedmocs = ();
219
local $metasourceTags = 0;
220
local $dep_files = "";
221
local $dep_finals = "";
222
local %target_adds = (); # the targets to add
224
local @cleanfiles = ();
225
local $cleanMoc = "";
226
local $closure_output = "";
228
$makefileDir = dirname($makefile);
229
chdir ($makefileDir);
230
$printname = $makefile;
231
$printname =~ s/^\Q$topdir\E\///;
232
$makefile = basename($makefile);
234
print STDOUT "Processing makefile $printname\n" if ($verbose);
236
# Setup and see if we need to do this.
237
return if (!initialise());
239
tag_AUTOMAKE (); # Allows a "make" to redo the Makefile.in
240
tag_META_INCLUDES (); # Supplies directories for src locations
242
foreach $program (@programs) {
243
$sources_changed{$program} = 0;
244
$depedmocs{$program} = "";
245
$important{$program} = "";
246
tag_IDLFILES(); # Sorts out idl rules
248
tag_UIFILES(); # Sorts out ui rules
249
tag_METASOURCES (); # Sorts out the moc rules
250
if ($sources_changed{$program}) {
251
my $lookup = "$program" . '_SOURCES\s*=\s*(.*)';
252
substituteLine($lookup, "$program\_SOURCES=" . $sources{$program});
254
if ($important{$program}) {
255
local %source_dict = ();
256
for $source (split(/[\034\s]+/, $sources{$program})) {
257
$source_dict{$source} = 1;
259
for $source (@cleanfiles) {
260
$source_dict{$source} = 0;
262
for $source (keys %source_dict) {
264
if ($source_dict{$source}) {
267
print STDERR "Error: $source is listed in a _SOURCE line in $printname, but doesn't exist yet. Put it in DISTCLEANFILES!\n";
269
$target_adds{"\$(srcdir)/$source"} .= $important{$program};
276
# Always add dist clean tag
277
# Add extra *.moc.cpp files created for USE_AUTOMOC because they
278
# aren't included in the normal *.moc clean rules.
279
appendLines ("$cleantarget-metasources:\n\t-rm -f $cleanMoc\n");
280
$target_adds{"$cleantarget-am"} .= "$cleantarget-metasources ";
285
appendLines ("$cleantarget-idl:\n\t-rm -f $idl_output\n");
286
$target_adds{"$cleantarget-am"} .= "$cleantarget-idl ";
290
appendLines ("$cleantarget-ui:\n\t-rm -f $ui_output\n");
291
$target_adds{"$cleantarget-am"} .= "$cleantarget-ui ";
294
if ($closure_output) {
295
appendLines ("$cleantarget-closures:\n\t-rm -f $closure_output\n");
296
$target_adds{"$cleantarget-am"} .= "$cleantarget-closures ";
299
if ($MakefileData =~ /\nKDE_LANG\s*=\s*(\S*)\s*\n/) {
300
$kdelang = '$(KDE_LANG)'
305
tag_POFILES (); # language rules for po directory
306
tag_DOCFILES (); # language rules for doc directories
307
tag_LOCALINSTALL(); # add $(DESTDIR) before all kde_ dirs
311
my $tmp = "force-reedit:\n";
312
$tmp .= "\t$automkCall\n\tcd \$(top_srcdir) && perl $thisProg $printname\n\n";
316
tag_FINAL() if (!$kdeopts{"nofinal"});
318
my $final_lines = "final:\n\t\$(MAKE) ";
319
my $final_install_lines = "final-install:\n\t\$(MAKE) ";
320
my $nofinal_lines = "no-final:\n\t\$(MAKE) ";
321
my $nofinal_install_lines = "no-final-install:\n\t\$(MAKE) ";
323
foreach $program (@programs) {
325
my $lookup = "$program\_OBJECTS.*=[^\n]*";
329
my @list = split(/[\034\s]+/, $realObjs{$program});
331
if (!$kdeopts{"nofinal"} && @list > 1 && $finalObjs{$program}) {
333
$new .= "$program\_final\_OBJECTS = " . $finalObjs{$program};
334
$new .= "\n$program\_nofinal\_OBJECTS = " . $realObjs{$program};
335
$new .= "\n\@KDE_USE_FINAL_FALSE\@$program\_OBJECTS = \$($program\_nofinal\_OBJECTS)";
336
$new .= "\n\@KDE_USE_FINAL_TRUE\@$program\_OBJECTS = \$($program\_final\_OBJECTS)";
338
$final_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" ";
339
$final_install_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" ";
340
$nofinal_lines .= "$program\_OBJECTS=\"\$($program\_nofinal\_OBJECTS)\" ";
341
$nofinal_install_lines .= "$program\_OBJECTS=\"\$($program\_nofinal_OBJECTS)\" ";
343
$new = "$program\_OBJECTS = " . $realObjs{$program};
345
substituteLine ($lookup, $new);
347
appendLines($final_lines . "all-am");
348
appendLines($final_install_lines . "install-am");
349
appendLines($nofinal_lines . "all-am");
350
appendLines($nofinal_install_lines . "install-am");
352
my $lookup = 'DEP_FILES\s*=([^\n]*)';
353
if ($MakefileData =~ /\n$lookup\n/o) {
357
$lines = "\@KDE_USE_FINAL_TRUE\@DEP_FILES = $dep_files $dep_finals \034\t$depfiles\n";
358
$lines .= "\@KDE_USE_FINAL_FALSE\@DEP_FILES = $dep_files $depfiles\n";
360
$lines = "DEP_FILES = $dep_files $depfiles\n";
363
substituteLine($lookup, $lines);
366
my $cvs_lines = "cvs-clean:\n";
367
$cvs_lines .= "\t\$(MAKE) -f \$(top_srcdir)/admin/Makefile.common cvs-clean\n";
368
appendLines($cvs_lines);
370
$cvs_lines = "kde-rpo-clean:\n";
371
$cvs_lines .= "\t-rm -f *.rpo\n";
372
appendLines($cvs_lines);
373
$target_adds{"clean"} .= "kde-rpo-clean ";
375
# some strange people like to do a install-exec, and expect that also
376
# all modules are installed. automake doesn't know this, so we need to move
377
# this here from install-data to install-exec.
378
if ($MakefileData =~ m/\nkde_module_LTLIBRARIES\s*=/) {
379
$target_adds{"install-exec-am"} .= "install-kde_moduleLTLIBRARIES";
380
my $lookup = 'install-data-am:\s*(.*)';
381
if ($MakefileData =~ /\n$lookup\n/) {
383
$newdeps =~ s/\s*install-kde_moduleLTLIBRARIES\s*/ /g;
384
substituteLine($lookup, "install-data-am: " . $newdeps);
390
foreach $add (keys %target_adds) {
391
my $lookup = quotemeta($add) . ':([^\n]*)';
392
if ($MakefileData =~ /\n$lookup\n/) {
393
substituteLine($lookup, "$add: " . $target_adds{$add} . $1);
395
$lines .= "$add: " . $target_adds{$add} . "\n";
405
if ($MakefileData =~ m/\n(.*)\$\(CXXFLAGS\)(.*)\n/) {
406
my $vor = $1; # "vor" means before in German
407
my $nach = $2; # "nach" means after in German
408
my $lookup = quotemeta("$1\$(CXXFLAGS)$2");
409
my $replacement = "$1\$(KCXXFLAGS)$2";
410
$MakefileData =~ s/$lookup/$replacement/;
411
$lookup =~ s/\\\$\\\(CXXFLAGS\\\)/\\\$\\\(KCXXFLAGS\\\)/;
412
$replacement = "$vor\$(KCXXFLAGS) \$(KDE_CXXFLAGS)$nach";
413
substituteLine($lookup, $replacement);
419
$lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=link) (\$\(CXXLD\).*\$\(KCXXFLAGS\))';
421
if ($MakefileData =~ m/$lookup/ ) {
422
$MakefileData =~ s/$lookup/$1 --tag=CXX $2/;
425
$lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=compile) (\$\(CXX\).*\$\(KCXXFLAGS\))';
426
if ($MakefileData =~ m/$lookup/ ) {
427
$MakefileData =~ s/$lookup/$1 --tag=CXX $2/;
430
$MakefileData =~ s/\$\(KCXXFLAGS\)/\$\(CXXFLAGS\)/g;
432
$lookup = '(.*)cp -pr \$\$/\$\$file \$\(distdir\)/\$\$file(.*)';
433
if ($MakefileData =~ m/\n$lookup\n/) {
434
substituteLine($lookup, "$1cp -pr \$\$d/\$\$file \$(distdir)/\$\$file$2");
437
# Always update the Makefile.in
442
#-----------------------------------------------------------------------------
444
# Check to see whether we should process this make file.
445
# This is where we look for tags that we need to process.
446
# A small amount of initialising on the tags is also done here.
447
# And of course we open and/or create the needed make files.
450
if (! -r "Makefile.am") {
451
print STDOUT "found Makefile.in without Makefile.am\n" if ($verbose);
455
# Checking for files to process...
456
open (FILEIN, $makefile)
457
|| die "Could not open $makefileDir/$makefile: $!\n";
459
# stat(FILEIN)[7] might look more elegant, but is slower as it
460
# requires stat'ing the file
462
my $fsize = tell(FILEIN);
464
read FILEIN, $MakefileData, $fsize;
466
print "DOS CRLF within $makefileDir/$makefile!\n" if($MakefileData =~ y/\r//d);
468
# Remove the line continuations, but keep them marked
469
# Note: we lose the trailing spaces but that's ok.
470
$MakefileData =~ s/\\\s*\n\s*/\034/g;
472
# If we've processed the file before...
473
restoreMakefile () if ($MakefileData =~ /$progId/);
475
foreach $dir (@foreignfiles) {
476
if (substr($makefileDir,0,length($dir)) eq $dir) {
482
$kdeopts{"foreign"} = 0;
483
$kdeopts{"qtonly"} = 0;
484
$kdeopts{"nofinal"} = !$use_final; # default
486
if ($MakefileData =~ /\nKDE_OPTIONS\s*=\s*([^\n]*)\n/) {
487
local @kde_options = split(/[\s\034]/, $1);
488
if (grep(/^foreign$/, @kde_options)) {
489
push(@foreignfiles, $makefileDir . "/");
490
return 0; # don't touch me
492
for $opt (@kde_options) {
493
if (!defined $kdeopts{$opt}) {
494
print STDERR "Warning: unknown option $opt in $printname\n";
501
# Look for the tags that mean we should process this file.
503
$metasourceTags++ while ($MakefileData =~ /\n[^=\#]*METASOURCES\s*=/g);
506
$pofileTag++ while ($MakefileData =~ /\nPOFILES\s*=/g);
509
print STDERR "Error: Only one POFILES tag allowed\n";
513
while ($MakefileData =~ /\n\.SUFFIXES:([^\n]+)\n/g) {
514
my @list=split(' ', $1);
515
foreach $ext (@list) {
516
if ($ext =~ /^\.$cppExt$/) {
518
$cxxsuffix =~ s/\.//g;
519
print STDOUT "will use suffix $cxxsuffix\n" if ($verbose);
525
while ($MakefileData =~ /\n(\S*)_OBJECTS\s*=[ \t\034]*([^\n]*)\n/g) {
528
my $objs = $2; # safe them
532
my @objlist = split(/[\s\034]+/, $objs);
533
foreach $obj (@objlist) {
534
if ($obj =~ /\$\((\S+)\)/ ) {
536
if ($variable !~ 'OBJEXT') {
544
$program =~ s/^am_// if ($program =~ /^am_/);
546
my $sourceprogram = $program;
547
$sourceprogram =~ s/\@am_/\@/ if($sourceprogram =~ /^.*\@am_.+/);
549
print STDOUT "found program $program\n" if ($verbose);
550
push(@programs, $program);
552
$realObjs{$program} = $objs;
554
if ($MakefileData =~ /\n$sourceprogram\_SOURCES\s*=\s*(.*)\n/) {
555
$sources{$program} = $1;
558
$sources{$program} = "";
559
print STDERR "found program with no _SOURCES: $program\n";
562
my $realprogram = $program;
563
$realprogram =~ s/_/./g; # unmask to regexp
564
if ($MakefileData =~ /\n($realprogram)(\$\(EXEEXT\)?)?:.*\$\($program\_OBJECTS\)/) {
565
$realname{$program} = $1;
567
# not standard Makefile - nothing to worry about
568
$realname{$program} = "";
572
my $lookup = '\nDEPDIR\s*=.*';
573
if ($MakefileData !~ /($lookup)\n/o) {
574
$lookup = '\nbindir\s*=.*';
575
if ($MakefileData =~ /($lookup)\n/) {
576
substituteLine ($lookup, "DEPDIR = .deps\n$1");
580
my @marks = ('MAINTAINERCLEANFILES', 'CLEANFILES', 'DISTCLEANFILES');
581
foreach $mark (@marks) {
582
while ($MakefileData =~ /\n($mark)\s*=\s*([^\n]*)/g) {
583
foreach $file (split('[\034\s]', $2)) {
585
push(@cleanfiles, $file);
591
$localTag++ if ($MakefileData =~ /\ninstall-\S+-local:/);
593
return (!$errorflag);
596
#-----------------------------------------------------------------------------
598
# Gets the list of user defined directories - relative to $srcdir - where
599
# header files could be located.
600
sub tag_META_INCLUDES ()
602
my $lookup = '[^=\n]*META_INCLUDES\s*=\s*(.*)';
603
return 1 if ($MakefileData !~ /($lookup)\n/o);
604
print STDOUT "META_INCLUDE processing <$1>\n" if ($verbose);
607
removeLine ($lookup, $1);
609
$headerStr =~ tr/\034/ /;
610
my @headerlist = split(' ', $headerStr);
612
foreach $dir (@headerlist)
614
$dir =~ s#\$\(srcdir\)#.#;
617
print STDERR "Warning: $dir can't be found. ",
618
"Must be a relative path to \$(srcdir)\n";
622
push (@headerdirs, $dir);
629
#-----------------------------------------------------------------------------
633
my @final_names = ();
635
foreach $program (@programs) {
637
if ($sources{$program} =~ /\(/) {
638
print STDOUT "found ( in $program\_SOURCES. skipping\n" if ($verbose);
644
my @progsources = split(/[\s\034]+/, $sources{$program});
647
foreach $source (@progsources) {
648
my $suffix = $source;
649
$suffix =~ s/^.*\.([^\.]+)$/$1/;
651
if (defined($sourcelist{$suffix})) {
652
$sourcelist{$suffix} .= " " . $source;
654
$sourcelist{$suffix} .= $source;
658
foreach $suffix (keys %sourcelist) {
660
# See if this file contains c++ code. (ie Just check the files suffix against
661
my $suffix_is_cxx = 0;
662
if($suffix =~ /($cppExt)$/) {
667
my $mocfiles_in = ($suffix eq $cxxsuffix) &&
668
defined($depedmocs{$program});
670
my @sourcelist = split(/[\s\034]+/, $sourcelist{$suffix});
672
if ((@sourcelist == 1 && !$mocfiles_in) || $suffix_is_cxx != 1 ) {
674
# we support IDL on our own
675
if ($suffix =~ /^skel$/ || $suffix =~ /^stub/ || $suffix =~ /^h$/
676
|| $suffix =~ /^ui$/ ) {
680
foreach $file (@sourcelist) {
682
$file =~ s/\Q$suffix\E$//;
684
$finalObjs{$program} .= $file;
685
if ($program =~ /_la$/) {
686
$finalObjs{$program} .= "lo ";
688
$finalObjs{$program} .= "o ";
694
my $source_deps = "";
695
foreach $source (@sourcelist) {
697
$source_deps .= "\$(srcdir)/$source ";
699
$source_deps .= "$source ";
703
$handling = "$program.all_$suffix.$suffix: \$(srcdir)/Makefile.in " . $source_deps . " ";
706
$handling .= $depedmocs{$program};
707
foreach $mocfile (split(' ', $depedmocs{$program})) {
709
if ($mocfile =~ m/\.$suffix$/) {
710
$mocsources .= " " . $mocfile;
716
$handling .= "\t\@echo 'creating $program.all_$suffix.$suffix ...'; \\\n";
717
$handling .= "\trm -f $program.all_$suffix.files $program.all_$suffix.final; \\\n";
718
$handling .= "\techo \"#define KDE_USE_FINAL 1\" >> $program.all_$suffix.final; \\\n";
719
$handling .= "\tfor file in " . $sourcelist{$suffix} . " $mocsources; do \\\n";
720
$handling .= "\t echo \"#include \\\"\$\$file\\\"\" >> $program.all_$suffix.files; \\\n";
721
$handling .= "\t test ! -f \$\(srcdir\)/\$\$file || egrep '^#pragma +implementation' \$\(srcdir\)/\$\$file >> $program.all_$suffix.final; \\\n";
722
$handling .= "\tdone; \\\n";
723
$handling .= "\tcat $program.all_$suffix.final $program.all_$suffix.files > $program.all_$suffix.$suffix; \\\n";
724
$handling .= "\trm -f $program.all_$suffix.final $program.all_$suffix.files\n";
726
appendLines($handling);
728
push(@final_names, "$program.all_$suffix.$suffix");
729
$finalObjs{$program} .= "$program.all_$suffix.";
730
if ($program =~ /_la$/) {
731
$finalObjs{$program} .= "lo ";
733
$finalObjs{$program} .= "o ";
738
if (!$kdeopts{"nofinal"} && @final_names >= 1) {
739
# add clean-final target
740
my $lines = "$cleantarget-final:\n";
741
$lines .= "\t-rm -f " . join(' ', @final_names) . "\n" if (@final_names);
743
$target_adds{"$cleantarget-am"} .= "$cleantarget-final ";
745
foreach $finalfile (@final_names) {
746
$finalfile =~ s/\.[^.]*$/.P/;
747
$dep_finals .= " \$(DEPDIR)/$finalfile";
752
# Organises the list of headers that we'll use to produce moc files
754
sub tag_METASOURCES ()
756
local @newObs = (); # here we add to create object files
757
local @deped = (); # here we add to create moc files
758
local $mocExt = ".moc";
759
local %mocFiles = ();
767
if ($metasourceTags > 1) {
768
$lookup = $program . '_METASOURCES\s*=\s*(.*)';
769
return 1 if ($MakefileData !~ /\n($lookup)\n/);
772
$lookup = $program . '_METASOURCES\s*=\s*(.*)';
773
if ($MakefileData !~ /\n($lookup)\n/) {
774
$lookup = 'METASOURCES\s*=\s*(.*)';
775
return 1 if ($MakefileData !~ /\n($lookup)\n/o);
777
$metasourceTags = 0; # we can use the general target only once
782
print STDOUT "METASOURCE processing <$found>)\n" if ($verbose);
785
$postEqual =~ s/[^=]*=//;
787
removeLine ($lookup, $found);
789
# Always find the header files that could be used to "moc"
790
return 1 if (findMocCandidates ());
792
if ($postEqual =~ /AUTO\s*(\S*)|USE_AUTOMOC\s*(\S*)/)
794
print STDERR "$printname: the argument for AUTO|USE_AUTOMOC is obsolete" if ($+);
795
$mocExt = ".moc.$cxxsuffix";
800
# Not automoc so read the list of files supplied which
801
# should be .moc files.
803
$postEqual =~ tr/\034/ /;
805
# prune out extra headers - This also checks to make sure that
807
pruneMocCandidates ($postEqual);
810
checkMocCandidates ();
813
my $ext = ($program =~ /_la$/) ? ".moc.lo " : ".moc.o ";
814
$realObjs{$program} .= "\034" . join ($ext, @newObs) . $ext;
815
$depedmocs{$program} = join (".moc.$cxxsuffix " , @newObs) . ".moc.$cxxsuffix";
816
foreach $file (@newObs) {
817
$dep_files .= " \$(DEPDIR)/$file.moc.P" if($dep_files !~/$file.moc.P/);
821
$depedmocs{$program} .= " ";
822
$depedmocs{$program} .= join('.moc ', @deped) . ".moc";
823
$depedmocs{$program} .= " ";
826
@globalmocs{keys %mocFiles}=values %mocFiles;
829
#-----------------------------------------------------------------------------
831
# Returns 0 if the line was processed - 1 otherwise.
832
# Errors are logged in the global $errorflags
835
my $lookup = '.*cd \$\(top_srcdir\)\s+&&[\s\034]+\$\(AUTOMAKE\)(.*)';
836
return 1 if ($MakefileData !~ /\n($lookup)\n/);
837
print STDOUT "AUTOMAKE processing <$1>\n" if ($verbose);
839
my $newLine = $1."\n\tcd \$(top_srcdir) && perl $thisProg $printname";
840
substituteLine ($lookup, $newLine);
845
#-----------------------------------------------------------------------------
847
sub handle_TOPLEVEL()
851
opendir (THISDIR, ".");
852
foreach $entry (readdir(THISDIR)) {
855
next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/ || $entry =~ /.gmo$/);
857
if ($entry =~ /\.po$/) {
860
push(@restfiles, $entry);
865
$target_adds{"install-data-am"} .= "install-nls-files ";
866
$lines = "install-nls-files:\n";
867
$lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$kdelang\n";
868
for $file (@restfiles) {
869
$lines .= "\t\$(INSTALL_DATA) \$\(srcdir\)/$file \$(DESTDIR)\$(kde_locale)/$kdelang/$file\n";
871
$target_adds{"uninstall"} .= "uninstall-nls-files ";
872
$lines .= "uninstall-nls-files:\n";
873
for $file (@restfiles) {
874
$lines .= "\t-rm -f \$(DESTDIR)\$(kde_locale)/$kdelang/$file\n";
882
#-----------------------------------------------------------------------------
886
if ($MakefileData !~ /\nSUBDIRS\s*=\s*\$\(AUTODIRS\)\s*\n/) {
892
opendir (THISDIR, ".");
893
foreach $entry (readdir(THISDIR)) {
894
next if ($entry eq "CVS" || $entry =~ /^\./);
895
if (-d $entry && -f $entry . "/Makefile.am") {
896
$subdirs .= " $entry";
902
my $lines = "SUBDIRS =$subdirs\n";
903
substituteLine('SUBDIRS\s*=.*', $lines);
909
my @psources = split(/[\034\s]+/, $sources{$program});
913
foreach $source (@psources) {
915
my $skel = ($source =~ m/\.skel$/);
917
if ($source =~ m/\.stub$/ || $skel) {
919
my $qs = quotemeta($source);
920
$sources{$program} =~ s/$qs//;
921
$sources_changed{$program} = 1;
923
print STDOUT "adding IDL file $source\n" if ($verbose);
925
$source =~ s/\.(stub|skel)$//;
930
$sourcename = "$source\_skel";
932
$sourcename = "$source\_stub";
936
if (-f "$makefileDir/$source.h") {
937
$sourcedir = '$(srcdir)/';
939
if ($MakefileData =~ /\n$source\_DIR\s*=\s*(\S+)\n/) {
941
$sourcedir .= "/" if ($sourcedir !~ /\/$/);
945
if ($allidls !~ /$source\_kidl/) {
947
$dep_lines .= "$source.kidl: $sourcedir$source.h \$(DCOPIDL_DEPENDENCIES)\n";
948
$dep_lines .= "\t\$(DCOPIDL) $sourcedir$source.h > $source.kidl || ( rm -f $source.kidl ; /bin/false )\n";
950
$allidls .= $source . "_kidl ";
953
if ($allidls !~ /$sourcename/) {
956
$dep_lines .= "$sourcename.$cxxsuffix: $source.kidl\n";
957
$dep_lines .= "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-stub $source.kidl\n";
959
$target_adds{"$sourcename.$cxxsuffix"} .= "$sourcename.h ";
960
$dep_lines .= "$sourcename.h: $source.kidl\n";
961
$dep_lines .= "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-skel $source.kidl\n";
964
$allidls .= $sourcename . " ";
967
$idlfiles{$program} .= $sourcename . " ";
969
if ($program =~ /_la$/) {
970
$realObjs{$program} .= " $sourcename.lo";
972
$realObjs{$program} .= " $sourcename.\$(OBJEXT)";
974
$sources{$program} .= " $sourcename.$cxxsuffix";
975
$sources_changed{$program} = 1;
976
$important{$program} .= "$sourcename.h " if (!$skel);
977
$idl_output .= "\\\n\t$sourcename.$cxxsuffix $sourcename.h $source.kidl ";
978
push(@cleanfiles, "$sourcename.$cxxsuffix");
979
push(@cleanfiles, "$sourcename.h");
980
push(@cleanfiles, "$sourcename.kidl");
981
$dep_files .= " \$(DEPDIR)/$sourcename.P" if ($dep_files !~/$sourcename.P/);
985
appendLines($dep_lines);
989
my $lookup = "($program)";
990
$lookup .= '(|\$\(EXEEXT\))';
992
$lookup .= ":(.*..$program\_OBJECTS..*)";
993
# $lookup = quotemeta($lookup);
994
if ($MakefileData =~ /\n$lookup\n/) {
997
foreach $file (split(' ', $idlfiles{$program})) {
998
$line .= "$file.$cxxsuffix ";
1001
substituteLine($lookup, $line);
1003
print STDERR "no built dependency found $lookup\n";
1010
my @psources = split(/[\034\s]+/, $sources{$program});
1014
foreach $source (@psources) {
1016
if ($source =~ m/\.ui$/) {
1018
print STDERR "adding UI file $source\n" if ($verbose);
1020
my $qs = quotemeta($source);
1021
$sources{$program} =~ s/$qs//;
1022
$sources_changed{$program} = 1;
1024
$source =~ s/\.ui$//;
1027
if (-f "$makefileDir/$source.ui") {
1028
$sourcedir = '$(srcdir)/';
1031
if (!$uiFiles{$source}) {
1033
$dep_lines .= "$source.$cxxsuffix: $sourcedir$source.ui $source.h $source.moc\n";
1034
$dep_lines .= "\trm -f $source.$cxxsuffix\n";
1035
if (!$kdeopts{"qtonly"}) {
1036
$dep_lines .= "\techo '#include <klocale.h>' > $source.$cxxsuffix\n";
1037
$dep_lines .= "\t\$(UIC) -tr \${UIC_TR} -i $source.h $sourcedir$source.ui | sed -e \"s,\${UIC_TR}( \\\"\\\" ),QString::null,g\" | sed -e \"s,\${UIC_TR}( \\\"\\\"\\, \\\"\\\" ),QString::null,g\" >> $source.$cxxsuffix || rm -f $source.$cxxsuffix\n";
1039
$dep_lines .= "\t\$(UIC) -i $source.h $sourcedir$source.ui > $source.$cxxsuffix || rm -f $source.$cxxsuffix\n";
1041
$dep_lines .= "\techo '#include \"$source.moc\"' >> $source.$cxxsuffix\n\n";
1042
$dep_lines .= "$source.h: $sourcedir$source.ui\n";
1043
$dep_lines .= "\t\$(UIC) -o $source.h $sourcedir$source.ui\n\n";
1044
$dep_lines .= "$source.moc: $source.h\n";
1045
$dep_lines .= "\t\$(MOC) $source.h -o $source.moc\n";
1047
$uiFiles{$source} = 1;
1048
$depedmocs{$program} .= " $source.moc";
1049
$globalmocs{$source} = "\035$source.h\035$source.cpp";
1052
if ($program =~ /_la$/) {
1053
$realObjs{$program} .= " $source.lo";
1055
$realObjs{$program} .= " $source.\$(OBJEXT)";
1057
$sources{$program} .= " $source.$cxxsuffix";
1058
$sources_changed{$program} = 1;
1059
$important{$program} .= "$source.h ";
1060
$ui_output .= "\\\n\t$source.$cxxsuffix $source.h $source.moc ";
1061
push(@cleanfiles, "$source.$cxxsuffix");
1062
push(@cleanfiles, "source.h");
1063
push(@cleanfiles, "$source.moc");
1064
$dep_files .= " \$(DEPDIR)/$source.P" if($dep_files !~/$source.P/ );
1068
appendLines($dep_lines);
1074
my $lookup = '([^\s]*)_ICON\s*=\s*([^\n]*)';
1078
while ($MakefileData =~ /\n$lookup/og) {
1081
$destdir = "kde_icondir";
1083
$destdir = $1 . "dir";
1085
my $iconauto = ($2 =~ /AUTO\s*$/);
1087
if ( ! $iconauto ) {
1088
my @_appnames = split(" ", $2);
1089
print STDOUT "KDE_ICON processing <@_appnames>\n" if ($verbose);
1090
foreach $appname (@_appnames) {
1091
push(@appnames, quotemeta($appname));
1094
print STDOUT "KDE_ICON processing <AUTO>\n" if ($verbose);
1098
opendir (THISDIR, ".");
1099
foreach $entry (readdir(THISDIR)) {
1100
next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
1101
next if (! -f $entry);
1104
push(@files, $entry)
1105
if ($entry =~ /\.xpm/ || $entry =~ /\.png/);
1107
foreach $appname (@appnames) {
1108
push(@files, $entry)
1109
if ($entry =~ /-$appname\.xpm/ || $entry =~ /-$appname\.png/);
1115
my %directories = ();
1117
foreach $file (@files) {
1118
my $newfile = $file;
1120
$prefix =~ s/\.(png|xpm)$//;
1121
my $appname = $prefix;
1122
$appname =~ s/^[^-]+-// if ($appname =~ /-/) ;
1123
$appname =~ s/^[^-]+-// if ($appname =~ /-/) ;
1124
$appname = quotemeta($appname);
1125
$prefix =~ s/$appname$//;
1128
$prefix = 'lo16-app' if ($prefix eq 'mini');
1129
$prefix = 'lo32-app' if ($prefix eq 'lo');
1130
$prefix = 'hi48-app' if ($prefix eq 'large');
1131
$prefix .= '-app' if ($prefix =~ m/^...$/);
1134
$type =~ s/^.*-([^-]+)$/$1/;
1135
$prefix =~ s/^(.*)-[^-]+$/$1/;
1139
'action' => 'actions',
1141
'device' => 'devices',
1142
'filesys' => 'filesystems',
1143
'mime' => 'mimetypes'
1146
if (! defined $type_hash{$type} ) {
1147
print STDERR "unknown icon type $type in $printname ($file)\n";
1153
'los' => 'locolor/16x16',
1154
'lom' => 'locolor/32x32',
1155
'him' => 'hicolor/32x32',
1156
'hil' => 'hicolor/48x48',
1157
'lo16' => 'locolor/16x16',
1158
'lo22' => 'locolor/22x22',
1159
'lo32' => 'locolor/32x32',
1160
'hi16' => 'hicolor/16x16',
1161
'hi22' => 'hicolor/22x22',
1162
'hi32' => 'hicolor/32x32',
1163
'hi48' => 'hicolor/48x48',
1164
'hi64' => 'hicolor/64x64',
1165
'hisc' => 'hicolor/scalable'
1168
$newfile =~ s@.*-($appname\.(png|xpm?))@$1@;
1170
if (! defined $dir_hash{$prefix}) {
1171
print STDERR "unknown icon prefix $prefix in $printname\n";
1175
my $dir = $dir_hash{$prefix} . "/" . $type_hash{$type};
1176
if ($newfile =~ /-[^\.]/) {
1178
$tmp =~ s/^([^-]+)-.*$/$1/;
1179
$dir = $dir . "/" . $tmp;
1180
$newfile =~ s/^[^-]+-//;
1183
if (!defined $directories{$dir}) {
1184
$install .= "\t\$(mkinstalldirs) \$(DESTDIR)\$($destdir)/$dir\n";
1185
$directories{$dir} = 1;
1188
$install .= "\t\$(INSTALL_DATA) \$(srcdir)/$file \$(DESTDIR)\$($destdir)/$dir/$newfile\n";
1189
$uninstall .= "\t-rm -f \$(DESTDIR)\$($destdir)/$dir/$newfile\n";
1194
if (length($install)) {
1195
$target_adds{"install-data-am"} .= "install-kde-icons ";
1196
$target_adds{"uninstall-am"} .= "uninstall-kde-icons ";
1197
appendLines("install-kde-icons:\n" . $install . "\nuninstall-kde-icons:\n" . $uninstall);
1201
sub handle_POFILES($$)
1203
my @pofiles = split(" ", $_[0]);
1206
# Build rules for creating the gmo files
1208
my $allgmofiles = "";
1209
my $pofileLine = "POFILES =";
1210
foreach $pofile (@pofiles)
1212
$pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1213
$tmp .= "$1.gmo: $pofile\n";
1214
$tmp .= "\trm -f $1.gmo; \$(GMSGFMT) -o $1.gmo \$(srcdir)/$pofile\n";
1215
$tmp .= "\ttest ! -f $1.gmo || touch $1.gmo\n";
1216
$allgmofiles .= " $1.gmo";
1217
$pofileLine .= " $1.po";
1220
my $lookup = 'POFILES\s*=([^\n]*)';
1221
if ($MakefileData !~ /\n$lookup/o) {
1222
appendLines("$pofileLine\nGMOFILES =$allgmofiles");
1224
substituteLine ($lookup, "$pofileLine\nGMOFILES =$allgmofiles");
1229
# Add the "clean" rule so that the maintainer-clean does something
1230
appendLines ("clean-nls:\n\t-rm -f $allgmofiles\n");
1232
$target_adds{"maintainer-clean"} .= "clean-nls ";
1234
$lookup = 'DISTFILES\s*=\s*(.*)';
1235
if ($MakefileData =~ /\n$lookup\n/o) {
1236
$tmp = "DISTFILES = \$(GMOFILES) \$(POFILES) $1";
1237
substituteLine ($lookup, $tmp);
1241
$target_adds{"install-data-am"} .= "install-nls ";
1243
$tmp = "install-nls:\n";
1245
$tmp .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES\n";
1247
$tmp .= "\t\@for base in ";
1248
foreach $pofile (@pofiles)
1250
$pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1254
$tmp .= "; do \\\n";
1256
$tmp .= "\t echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n";
1257
$tmp .= "\t test ! -f \$\$base.gmo || \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n"
1259
$tmp .= "\t echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
1260
$tmp .= "\t \$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES ; \\\n";
1261
$tmp .= "\t test ! -f \$\$base.gmo || \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
1263
$tmp .= "\tdone\n\n";
1266
$target_adds{"uninstall"} .= "uninstall-nls ";
1268
$tmp = "uninstall-nls:\n";
1269
foreach $pofile (@pofiles)
1271
$pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1273
$tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/$1.mo\n";
1275
$tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$1/LC_MESSAGES/\$(PACKAGE).mo\n";
1280
$target_adds{"all"} .= "all-nls ";
1282
$tmp = "all-nls: \$(GMOFILES)\n";
1286
$target_adds{"distdir"} .= "distdir-nls ";
1288
$tmp = "distdir-nls:\$(GMOFILES)\n";
1289
$tmp .= "\tfor file in \$(POFILES); do \\\n";
1290
$tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n";
1292
$tmp .= "\tfor file in \$(GMOFILES); do \\\n";
1293
$tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n";
1299
appendLines("merge:\n\t\$(MAKE) -f \$(top_srcdir)/admin/Makefile.common package-merge POFILES=\"\${POFILES}\" PACKAGE=\${PACKAGE}\n\n");
1304
#-----------------------------------------------------------------------------
1306
# Returns 0 if the line was processed - 1 otherwise.
1307
# Errors are logged in the global $errorflags
1310
my $lookup = 'POFILES\s*=([^\n]*)';
1311
return 1 if ($MakefileData !~ /\n$lookup/o);
1312
print STDOUT "POFILES processing <$1>\n" if ($verbose);
1316
# make sure these are all gone.
1317
if ($MakefileData =~ /\n\.po\.gmo:\n/)
1319
print STDERR "Warning: Found old .po.gmo rules in $printname. New po rules not added\n";
1323
# Either find the pofiles in the directory (AUTO) or use
1324
# only the specified po files.
1326
if ($tmp =~ /^\s*AUTO\s*$/)
1328
opendir (THISDIR, ".");
1329
$pofiles = join(" ", grep(/\.po$/, readdir(THISDIR)));
1331
print STDOUT "pofiles found = $pofiles\n" if ($verbose);
1332
if (-f "charset" && -f "kdelibs.po") {
1341
return 1 if (!$pofiles); # Nothing to do
1343
handle_POFILES($pofiles, $kdelang);
1348
sub helper_LOCALINSTALL($)
1350
my $lookup = "\n" . $_[0] . ":";
1351
if ($MakefileData =~ /($lookup)/) {
1353
my $install = $MakefileData;
1354
$install =~ s/\n/\035/g;
1355
$install =~ s/.*\035$_[0]:[^\035]*\035//;
1357
while (! $emptyline) {
1358
if ($install =~ /([^\035]*)\035(.*)/) {
1361
if ($line !~ /^\s*$/ && $line !~ /^(\@.*\@)*\t/) {
1364
replaceDestDir($line);
1374
sub tag_LOCALINSTALL ()
1376
helper_LOCALINSTALL('install-exec-local');
1377
helper_LOCALINSTALL('install-data-local');
1378
helper_LOCALINSTALL('uninstall-local');
1383
sub replaceDestDir($) {
1384
local $line = $_[0];
1386
if ( $line =~ /^\s*(\@.*\@)*\s*\$\(mkinstalldirs\)/
1387
|| $line =~ /^\s*(\@.*\@)*\s*\$\(INSTALL\S*\)/
1388
|| $line =~ /^\s*(\@.*\@)*\s*(-?rm.*) \S*$/)
1390
$line =~ s/^(.*) ([^\s]*)\s*$/$1 \$(DESTDIR)$2/ if ($line !~ /\$\(DESTDIR\)/);
1393
if ($line ne $_[0]) {
1394
$_[0] = quotemeta $_[0];
1395
substituteLine($_[0], $line);
1399
#---------------------------------------------------------------------------
1400
sub tag_CLOSURE () {
1401
return if ($program !~ /_la$/);
1403
my $lookup = quotemeta($realname{$program}) . ":.*?\n\t.*?\\((.*?)\\) .*\n";
1404
$MakefileData =~ m/$lookup/;
1405
return if ($1 !~ /CXXLINK/);
1407
if ($MakefileData !~ /\n$program\_LDFLAGS\s*=.*-no-undefined/ &&
1408
$MakefileData !~ /\n$program\_LDFLAGS\s*=.*KDE_PLUGIN/ ) {
1409
print STDERR "Report: $program contains undefined in $printname\n" if ($program =~ /^lib/ && $dryrun);
1412
my $closure = $realname{$program} . ".closure";
1413
my $lines = "$closure: \$($program\_OBJECTS) \$($program\_DEPENDENCIES)\n";
1414
$lines .= "\t\@echo \"int main() {return 0;}\" > $program\_closure.$cxxsuffix\n";
1415
$lines .= "\t\@\$\(LTCXXCOMPILE\) -c $program\_closure.$cxxsuffix\n";
1416
$lines .= "\t\$\(CXXLINK\) $program\_closure.lo \$($program\_LDFLAGS) \$($program\_OBJECTS) \$($program\_LIBADD) \$(LIBS)\n";
1417
$lines .= "\t\@rm -f $program\_closure.* $closure\n";
1418
$lines .= "\t\@echo \"timestamp\" > $closure\n";
1420
appendLines($lines);
1421
$lookup = $realname{$program} . ": (.*)";
1422
if ($MakefileData =~ /\n$lookup\n/) {
1423
$lines = "\@KDE_USE_CLOSURE_TRUE@". $realname{$program} . ": $closure $1";
1424
$lines .= "\n\@KDE_USE_CLOSURE_FALSE@" . $realname{$program} . ": $1";
1425
substituteLine($lookup, $lines);
1427
$closure_output .= " $closure";
1431
my %foundfiles = ();
1432
opendir (THISDIR, ".");
1433
foreach $entry (readdir(THISDIR)) {
1434
next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile$$/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
1435
next if (! -f $entry);
1436
next if ($entry =~ /\.moc/ || $entry =~ /\.lo$/ || $entry =~ /\.la$/ || $entry =~ /\.o/);
1437
next if ($entry =~ /.+meta_unload.$cppExt$/ || $entry =~ /\.all_$cppExt\.$cppExt$/);
1438
$foundfiles{$entry} = 1;
1442
my @marks = ("EXTRA_DIST", "DIST_COMMON", '\S*_SOURCES', '\S*_HEADERS', 'MAINTAINERCLEANFILES', 'CLEANFILES', 'DISTCLEANFILES', '\S*_OBJECTS');
1443
foreach $mark (@marks) {
1444
while ($MakefileData =~ /\n($mark)\s*=\s*([^\n]*)/g) {
1445
foreach $file (split('[\034\s]', $2)) {
1447
$foundfiles{$file} = 0 if (defined $foundfiles{$file});
1451
my @files = ("Makefile", "config.cache", "config.log", "stamp-h",
1452
"stamp-h1", "stamp-h1", "config.h", "Makefile", "config.status", "config.h", "libtool");
1453
foreach $file (@files) {
1454
$foundfiles{$file} = 0 if (defined $foundfiles{$file});
1458
foreach $file (keys %foundfiles) {
1459
if ($foundfiles{$file} == 1) {
1460
$KDE_DIST .= "$file ";
1464
print "KDE_DIST $printname $KDE_DIST\n" if ($verbose);
1466
my $lookup = "DISTFILES *=(.*)";
1467
if ($MakefileData =~ /\n$lookup\n/o) {
1468
substituteLine($lookup, "KDE_DIST=$KDE_DIST\n\nDISTFILES=$1 \$(KDE_DIST)\n");
1473
#-----------------------------------------------------------------------------
1474
# Returns 0 if the line was processed - 1 otherwise.
1475
# Errors are logged in the global $errorflags
1478
# if ($MakefileData =~ /\nSUBDIRS\s*=/) { # subdirs
1479
# $MakefileData =~ /\n(.*-recursive:\s*)\n/;
1480
# my $orig_rules = $1;
1481
# my $rules = $orig_rules;
1482
# $rules =~ s/:\s*$//;
1483
# substituteLine($orig_rules, "$rules docs-recursive:");
1484
# appendLines("docs: docs-recursive docs-am\n");
1486
# appendLines("docs: docs-am\n");
1488
$target_adds{"all"} .= "docs-am ";
1490
my $lookup = 'KDE_DOCS\s*=\s*([^\n]*)';
1491
goto nodocs if ($MakefileData !~ /\n$lookup/o);
1492
print STDOUT "KDE_DOCS processing <$1>\n" if ($verbose);
1496
# Either find the files in the directory (AUTO) or use
1497
# only the specified po files.
1500
$appname =~ s/^(\S*)\s*.*$/$1/;
1501
if ($appname =~ /AUTO/) {
1502
$appname = basename($makefileDir);
1503
if ("$appname" eq "en") {
1504
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";
1511
opendir (THISDIR, ".");
1512
foreach $entry (readdir(THISDIR)) {
1513
next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
1514
next if (! -f $entry);
1515
$files .= "$entry ";
1518
print STDOUT "docfiles found = $files\n" if ($verbose);
1523
$tmp =~ s/^\S*\s*-\s*//;
1526
goto nodocs if (!$files); # Nothing to do
1528
if ($files =~ /(^| )index\.docbook($| )/) {
1531
my $lookup = 'MEINPROC\s*=';
1532
if ($MakefileData !~ /\n($lookup)/) {
1533
$lines = "MEINPROC=/\$(kde_bindir)/meinproc\n";
1535
$lookup = 'KDE_XSL_STYLESHEET\s*=';
1536
if ($MakefileData !~ /\n($lookup)/) {
1537
$lines .= "KDE_XSL_STYLESHEET=/\$(kde_datadir)/ksgmltools2/customization/kde-chunk.xsl\n";
1539
$lookup = '\nindex.cache.bz2:';
1540
if ($MakefileData !~ /\n($lookup)/) {
1541
$lines .= "index.cache.bz2: \$(srcdir)/index.docbook \$(KDE_XSL_STYLESHEET) $files\n";
1542
$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";
1546
$lines .= "docs-am: index.cache.bz2\n";
1548
$lines .= "install-docs: docs-am install-nls\n";
1549
$lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n";
1550
$lines .= "\t\@if test -f index.cache.bz2; then \\\n";
1551
$lines .= "\techo \$(INSTALL_DATA) index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n";
1552
$lines .= "\t\$(INSTALL_DATA) index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n";
1554
$lines .= "\t-rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n";
1555
$lines .= "\t\$(LN_S) \$(kde_libs_htmldir)/$kdelang/common \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n";
1558
$lines .= "uninstall-docs:\n";
1559
$lines .= "\t-rm -rf \$(kde_htmldir)/$kdelang/$appname\n";
1561
$lines .= "clean-docs:\n";
1562
$lines .= "\t-rm -f index.cache.bz2\n";
1564
$target_adds{"install-data-am"} .= "install-docs ";
1565
$target_adds{"uninstall"} .= "uninstall-docs ";
1566
$target_adds{"clean-am"} .= "clean-docs ";
1567
appendLines ($lines);
1569
appendLines("docs-am: $files\n");
1572
$target_adds{"install-data-am"} .= "install-nls";
1573
$target_adds{"uninstall"} .= "uninstall-nls ";
1575
$tmp = "install-nls:\n";
1576
$tmp .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n";
1577
$tmp .= "\t\@for base in $files; do \\\n";
1578
$tmp .= "\t echo \$(INSTALL_DATA) \$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1579
$tmp .= "\t \$(INSTALL_DATA) \$(srcdir)/\$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1581
if ($appname eq 'common') {
1582
$tmp .= "\t\@echo \"merging common and language specific dir\" ;\\\n";
1583
$tmp .= "\tif test ! -e \$(kde_htmldir)/en/common/kde-common.css; then echo 'no english docs found in \$(kde_htmldir)/en/common/'; exit 1; fi \n";
1584
$tmp .= "\t\@com_files=`cd \$(kde_htmldir)/en/common && echo *` ;\\\n";
1585
$tmp .= "\tcd \$(DESTDIR)\$(kde_htmldir)/$kdelang/common ;\\\n";
1586
$tmp .= "\tif test -n \"\$\$com_files\"; then for p in \$\$com_files ; do \\\n";
1587
$tmp .= "\t case \" $files \" in \\\n";
1588
$tmp .= "\t *\" \$\$p \"*) ;; \\\n";
1589
$tmp .= "\t *) test ! -e \$\$p && echo \$(LN_S) ../../en/common/\$\$p \$(DESTDIR)\$(kde_htmldir)/$kdelang/common/\$\$p && \$(LN_S) ../../en/common/\$\$p \$\$p ;; \\\n";
1590
$tmp .= "\t esac ; \\\n";
1591
$tmp .= "\tdone ; fi ; true\n";
1594
$tmp .= "uninstall-nls:\n";
1595
$tmp .= "\tfor base in $files; do \\\n";
1596
$tmp .= "\t rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1597
$tmp .= "\tdone\n\n";
1600
$target_adds{"distdir"} .= "distdir-nls ";
1602
$tmp = "distdir-nls:\n";
1603
$tmp .= "\tfor file in $files; do \\\n";
1604
$tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n";
1612
appendLines("docs-am:\n");
1616
#-----------------------------------------------------------------------------
1617
# Find headers in any of the source directories specified previously, that
1618
# are candidates for "moc-ing".
1619
sub findMocCandidates ()
1621
foreach $dir (@headerdirs)
1624
opendir (SRCDIR, "$dir");
1625
@hFiles = grep { /.+\.$hExt$/o } readdir(SRCDIR);
1627
foreach $hf (@hFiles)
1629
next if ($hf =~ /^\.\#/);
1630
$hf =~ /(.*)\.[^\.]*$/; # Find name minus extension
1631
next if ($uiFiles{$1});
1632
open (HFIN, "$dir/$hf") || die "Could not open $dir/$hf: $!\n";
1635
$hfsize = tell(HFIN);
1637
read HFIN, $hfData, $hfsize;
1639
# push (@list, $hf) if(index($hfData, "Q_OBJECT") >= 0); ### fast but doesn't handle //Q_OBJECT
1640
if ( $hfData =~ /{([^}]*)Q_OBJECT/s ) { ## handle " { friend class blah; Q_OBJECT "
1641
push (@list, $hf) unless $1 =~ m://[^\n]*Q_OBJECT[^\n]*$:s; ## handle "// Q_OBJECT"
1644
# The assoc array of root of headerfile and header filename
1645
foreach $hFile (@list)
1647
$hFile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1650
print STDERR "Warning: Multiple header files found for $1\n";
1651
next; # Use the first one
1653
$mocFiles{$1} = "$dir\035$hFile"; # Add relative dir
1660
#-----------------------------------------------------------------------------
1662
# The programmer has specified a moc list. Prune out the moc candidates
1663
# list that we found based on looking at the header files. This generates
1664
# a warning if the programmer gets the list wrong, but this doesn't have
1666
sub pruneMocCandidates ($)
1669
local @mocList = split(' ', $_[0]);
1671
foreach $mocname (@mocList)
1673
$mocname =~ s/\.moc$//;
1674
if ($mocFiles{$mocname})
1676
$prunedMoc{$mocname} = $mocFiles{$mocname};
1680
my $print = $makefileDir;
1681
$print =~ s/^\Q$topdir\E\\//;
1682
# They specified a moc file but we can't find a header that
1683
# will generate this moc file. That's possible fatal!
1684
print STDERR "Warning: No moc-able header file for $print/$mocname\n";
1689
%mocFiles = %prunedMoc;
1692
#-----------------------------------------------------------------------------
1694
# Finds the cpp files (If they exist).
1695
# The cpp files get appended to the header file separated by \035
1696
sub checkMocCandidates ()
1699
my $cpp2moc; # which c++ file includes which .moc files
1700
my $moc2cpp; # which moc file is included by which c++ files
1702
return unless (keys %mocFiles);
1703
opendir(THISDIR, ".") || return;
1704
@cppFiles = grep { /.+\.$cppExt$/o && !/.+\.moc\.$cppExt$/o
1705
&& !/.+\.all_$cppExt\.$cppExt$/o } readdir(THISDIR);
1707
return unless (@cppFiles);
1708
my $files = join (" ", @cppFiles);
1711
foreach $cxxf (@cppFiles)
1713
open (CXXFIN, $cxxf) || die "Could not open $cxxf: $!\n";
1715
my $cxxfsize = tell(CXXFIN);
1717
read CXXFIN, $cxxfData, $cxxfsize;
1719
while(($cxxfData =~ m/^[ \t]*\#include\s*[<\"](.*\.moc)[>\"]/gm)) {
1720
$cpp2moc->{$cxxf}->{$1} = 1;
1721
$moc2cpp->{$1}->{$cxxf} = 1;
1724
foreach my $mocFile (keys (%mocFiles))
1726
@cppFiles = keys %{$moc2cpp->{"$mocFile.moc"}};
1727
if (@cppFiles == 1) {
1728
$mocFiles{$mocFile} .= "\035" . $cppFiles[0];
1729
push(@deped, $mocFile);
1730
} elsif (@cppFiles == 0) {
1731
push (@newObs, $mocFile); # Produce new object file
1732
next if ($haveAutomocTag); # This is expected...
1733
# But this is an error we can deal with - let them know
1735
"Warning: No c++ file that includes $mocFile.moc\n";
1737
# We can't decide which file to use, so it's fatal. Although as a
1738
# guess we could use the mocFile.cpp file if it's in the list???
1740
"Error: Multiple c++ files that include $mocFile.moc\n";
1741
print STDERR "\t",join ("\t", @cppFiles),"\n";
1743
delete $mocFiles{$mocFile};
1744
# Let's continue and see what happens - They have been told!
1749
#-----------------------------------------------------------------------------
1751
# Add the rules for generating moc source from header files
1752
# For Automoc output *.moc.cpp but normally we'll output *.moc
1753
# (We must compile *.moc.cpp separately. *.moc files are included
1754
# in the appropriate *.cpp file by the programmer)
1760
foreach $mocFile (keys (%mocFiles))
1763
($dir, $hFile, $cppFile) = split ("\035", $mocFiles{$mocFile}, 3);
1764
$dir =~ s#^\.#\$(srcdir)#;
1765
if (defined ($cppFile))
1767
$target_adds{"\$(srcdir)/$cppFile"} .= "$mocFile.moc ";
1768
appendLines ("$mocFile.moc: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile.moc\n");
1769
$cleanMoc .= " $mocFile.moc";
1773
appendLines ("$mocFile$mocExt: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile$mocExt\n");
1774
$cleanMoc .= " $mocFile$mocExt";
1779
sub make_meta_classes ()
1781
return if ($kdeopts{"qtonly"});
1785
my $moc_class_headers = "";
1786
foreach $program (@programs) {
1788
my @progsources = split(/[\s\034]+/, $sources{$program});
1789
my @depmocs = split(' ', $depedmocs{$program});
1790
my %shash = (), %mhash = ();
1791
@shash{@progsources} = 1; # we are only interested in the existence
1792
@mhash{@depmocs} = 1;
1794
print STDOUT "program=$program\n" if ($verbose);
1795
print STDOUT "psources=[".join(' ', keys %shash)."]\n" if ($verbose);
1796
print STDOUT "depmocs=[".join(' ', keys %mhash)."]\n" if ($verbose);
1797
print STDOUT "globalmocs=[".join(' ', keys(%globalmocs))."]\n" if ($verbose);
1798
foreach my $mocFile (keys (%globalmocs))
1801
($dir, $hFile, $cppFile) = split ("\035", $globalmocs{$mocFile}, 3);
1802
$dir =~ s#^\.#\$(srcdir)#;
1803
if (defined ($cppFile))
1805
$mocs .= " $mocFile.moc" if exists $shash{$cppFile};
1809
# Bah. This is the case, if no C++ file includes the .moc
1810
# file. We make a .moc.cpp file for that. Unfortunately this
1811
# is not included in the %sources hash, but rather is mentioned
1812
# in %depedmocs. If the user wants to use AUTO he can't just
1813
# use an unspecific METAINCLUDES. Instead he must use
1814
# program_METAINCLUDES. Anyway, it's not working real nicely.
1815
# E.g. Its not clear what happens if user specifies two
1816
# METAINCLUDES=AUTO in the same Makefile.am.
1817
$mocs .= " $mocFile.moc.$cxxsuffix"
1818
if exists $mhash{$mocFile.".moc.$cxxsuffix"};
1822
print STDOUT "==> mocs=[".$mocs."]\n" if ($verbose);
1823
my $sourcename = $program."_meta_unload";
1824
my $ext = ($program =~ /_la$/) ? ".lo" : ".o";
1825
my $srcfile = $sourcename.".$cxxsuffix";
1826
my $objfile = $sourcename.$ext;
1827
$moc_class_headers .= " $srcfile";
1829
$appl = "$srcfile: $mocs\n";
1830
$appl .= "\t\@echo 'creating $srcfile'\n";
1831
$appl .= "\t\@-rm -f $srcfile\n";
1832
$appl .= "\t\@if test \${kde_qtver} = 2; then \\\n";
1833
$appl .= "\t\techo 'static const char * _metalist_$program\[\] = {' > $srcfile ;\\\n";
1834
$appl .= "\t\tcat $mocs | grep 'char.*className' | ";
1835
$appl .= "sed -e 's/.*[^A-Za-z0-9_:]\\([A-Za-z0-9_:]*\\)::className.*\$\$/\\\"\\1\\\",/' | sort | uniq >> $srcfile ;\\\n";
1836
$appl .= "\t\techo '0};' >> $srcfile ;\\\n";
1837
$appl .= "\t\techo '#include <kunload.h>' >> $srcfile ;\\\n";
1838
$appl .= "\t\techo '_UNLOAD($program)' >> $srcfile ;\\\n";
1839
$appl .= "\telse echo > $srcfile; fi\n";
1842
$realObjs{$program} .= " \034" . $objfile . " ";
1843
$sources{$program} .= " $srcfile";
1844
$sources_changed{$program} = 1;
1845
$dep_files .= " \$(DEPDIR)/$sourcename.P" if($dep_files !~/$sourcename.P/);
1846
appendLines ($appl);
1848
print STDOUT "\n" if $verbose;
1850
if ($moc_class_headers) {
1851
appendLines ("$cleantarget-moc-classes:\n\t-rm -f $moc_class_headers\n");
1852
$target_adds{"$cleantarget-am"} .= "$cleantarget-moc-classes ";
1856
#-----------------------------------------------------------------------------
1858
sub updateMakefile ()
1860
return if ($dryrun);
1862
open (FILEOUT, "> $makefile")
1863
|| die "Could not create $makefile: $!\n";
1865
print FILEOUT "\# $progId - " . '$Revision: 1.265.2.2 $ ' . "\n";
1866
$MakefileData =~ s/\034/\\\n\t/g; # Restore continuation lines
1867
print FILEOUT $MakefileData;
1871
#-----------------------------------------------------------------------------
1873
# The given line needs to be removed from the makefile
1874
# Do this by adding the special "removed line" comment at the line start.
1877
my ($lookup, $old) = @_;
1879
$old =~ s/\034/\\\n#>- /g; # Fix continuation lines
1880
$MakefileData =~ s/\n$lookup/\n#>\- $old/;
1883
#-----------------------------------------------------------------------------
1885
# Replaces the old line with the new line
1886
# old line(s) are retained but tagged as removed. The new line(s) have the
1887
# "added" tag placed before it.
1888
sub substituteLine ($$)
1890
my ($lookup, $new) = @_;
1892
if ($MakefileData =~ /\n($lookup)/) {
1894
$old =~ s/\034/\\\n#>\- /g; # Fix continuation lines
1895
$new =~ s/\034/\\\n\t/g;
1896
my $newCount = ($new =~ tr/\n//) + 1;
1897
$MakefileData =~ s/\n$lookup/\n#>- $old\n#>\+ $newCount\n$new/;
1899
print STDERR "Warning: substitution of \"$lookup\" in $printname failed\n";
1903
#-----------------------------------------------------------------------------
1905
# Slap new lines on the back of the file.
1909
$new =~ s/\034/\\\n\t/g; # Fix continuation lines
1910
my $newCount = ($new =~ tr/\n//) + 1;
1911
$MakefileData .= "\n#>\+ $newCount\n$new";
1914
#-----------------------------------------------------------------------------
1916
# Restore the Makefile.in to the state it was before we fiddled with it
1917
sub restoreMakefile ()
1919
$MakefileData =~ s/# $progId[^\n\034]*[\n\034]*//g;
1920
# Restore removed lines
1921
$MakefileData =~ s/([\n\034])#>\- /$1/g;
1922
# Remove added lines
1923
while ($MakefileData =~ /[\n\034]#>\+ ([^\n\034]*)/)
1926
my $removeLines = "";
1927
while ($newCount--) {
1928
$removeLines .= "[^\n\034]*([\n\034]|)";
1930
$MakefileData =~ s/[\n\034]#>\+.*[\n\034]$removeLines/\n/;
1934
#-----------------------------------------------------------------------------