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>
35
# I've puddled around with automoc and produced something different
36
# 1999-02-01 John Birch <jb.nz@writeme.com>
37
# * Rewritten automoc to cater for more than just moc file expansion
38
# Version 0.01 does the same as automoc at this stage.
40
# * We must always write a Makefile.in file out even if we fail
41
# because we need the "perl autokmake" in the AUTOMAKE so that a
42
# "make" will regenerate the Makefile.in correctly.
43
# Reworked moc file checking so that missing includes in cpp
44
# will work and includes in cpp when using use_automoc will also
47
# * Added POFILE processing and changed the USE_AUTOMOC tag to
49
# ... See ChangeLog for more logs
55
# Prototype the functions
57
sub processMakefile ($);
58
sub updateMakefile ();
59
sub restoreMakefile ();
63
sub substituteLine ($$);
65
sub findMocCandidates ();
66
sub pruneMocCandidates ($);
67
sub checkMocCandidates ();
71
sub tag_META_INCLUDES ();
72
sub tag_METASOURCES ();
75
sub tag_LOCALINSTALL();
83
# Some global globals...
84
$verbose = 0; # a debug flag
85
$thisProg = "$0"; # This programs name
86
$topdir = cwd(); # The current directory
87
@makefiles = (); # Contains all the files we'll process
89
$start = (times)[0]; # some stats for testing - comment out for release
92
$cppExt = "(cpp|cc|cxx|C|c\\+\\+)";
93
$hExt = "(h|H|hh|hxx|hpp|h\\+\\+)";
94
$progId = "KDE tags expanded automatically by " . basename($thisProg);
96
$printname = ""; # used to display the directory the Makefile is in
97
$use_final = 1; # create code for --enable-final
98
$cleantarget = "clean";
102
while (defined ($ARGV[0]))
108
print STDOUT basename($thisProg), " $version\n",
109
"This is really free software, unencumbered by the GPL.\n",
110
"You can do anything you like with it except sueing me.\n",
111
"Copyright 1998 Kalle Dalheimer <kalle\@kde.org>\n",
112
"Concept, design and unnecessary questions about perl\n",
113
" by Matthias Ettrich <ettrich\@kde.org>\n\n",
114
"Making it useful by Stephan Kulow <coolo\@kde.org> and\n",
115
"Harri Porten <porten\@kde.org>\n",
116
"Updated (Feb-1999), John Birch <jb.nz\@writeme.com>\n",
117
"Current Maintainer Stephan Kulow\n\n";
120
elsif (/^--verbose$|^-v$/)
122
$verbose = 1; # Oh is there a problem...?
124
elsif (/^-p(.+)$|^--path=(.+)$/)
126
$thisProg = "$1/".basename($thisProg) if($1);
127
$thisProg = "$2/".basename($thisProg) if($2);
128
warn ("$thisProg doesn't exist\n") if (!(-f $thisProg));
131
elsif (/^--help$|^-h$/)
133
print STDOUT "Usage $thisProg [OPTION] ... [dir/Makefile.in]...\n",
135
"Patches dir/Makefile.in generated from automake\n",
136
"(where dir can be a full or relative directory name)",
138
" -v, --verbose verbosely list files processed\n",
139
" -h, --help print this help, then exit\n",
140
" --version print version number, then exit\n",
141
" -p, --path= use the path to am_edit if the path\n",
142
" --no-final don't patch for --enable-final\n",
143
" called from is not the one to be used\n";
147
elsif (/^--no-final$/)
150
$thisProg .= " --no-final";
158
# user selects what input files to check
159
# add full path if relative path is given
160
$_ = cwd()."/".$_ if (! /^\//);
161
print "User wants $_\n" if ($verbose);
162
push (@makefiles, $_);
166
if ($thisProg =~ /^\// && !$pathoption )
168
print STDERR "Illegal full pathname call performed...\n",
169
"The call to \"$thisProg\"\nwould be inserted in some Makefile.in.\n",
170
"Please use option --path.\n";
174
# Only scan for files when the user hasn't entered data
177
print STDOUT "Scanning for Makefile.in\n" if ($verbose);
178
find (\&add_makefile, cwd());
181
print STDOUT "Using user enter input files\n" if ($verbose);
184
foreach $makefile (sort(@makefiles))
186
processMakefile ($makefile);
187
last if ($errorflag);
190
# Just some debug statistics - comment out for release as it uses printf.
191
printf STDOUT "Time %.2f CPU sec\n", (times)[0] - $start if ($verbose);
193
exit $errorflag; # causes make to fail if erroflag is set
195
#-----------------------------------------------------------------------------
197
# In conjunction with the "find" call, this builds the list of input files
200
push (@makefiles, $File::Find::name) if (/Makefile.in$/);
203
#-----------------------------------------------------------------------------
205
# Processes a single make file
206
# The parameter contains the full path name of the Makefile.in to use
207
sub processMakefile ($)
209
# some useful globals for the subroutines called here
210
local ($makefile) = @_;
211
local @headerdirs = ('.');
212
local $haveAutomocTag = 0;
213
local $MakefileData = "";
215
local $cxxsuffix = "KKK";
217
local @programs = (); # lists the names of programs and libraries
220
local %realObjs = (); # lists the objects compiled into $program
221
local %sources = (); # lists the sources used for $program
222
local %finalObjs = (); # lists the objects compiled when final
223
local %realname = (); # the binary name of program variable
224
local %idlfiles = (); # lists the idl files used for $program
225
local %globalmocs = ();# list of all mocfiles (in %mocFiles format)
226
local %important = (); # list of files to be generated asap
230
local $idl_output = "";# lists all idl generated files for cleantarget
231
local $ui_output = "";# lists all uic generated files for cleantarget
233
local %depedmocs = ();
235
local $metasourceTags = 0;
236
local $dep_files = "";
237
local $dep_finals = "";
238
local %target_adds = (); # the targets to add
240
local @cleanfiles = ();
241
local $cleanMoc = "";
242
local $closure_output = "";
244
$makefileDir = dirname($makefile);
245
chdir ($makefileDir);
246
$printname = $makefile;
247
$printname =~ s/^\Q$topdir\E\///;
248
$makefile = basename($makefile);
250
print STDOUT "Processing makefile $printname\n" if ($verbose);
252
# Setup and see if we need to do this.
253
return if (!initialise());
255
tag_AUTOMAKE (); # Allows a "make" to redo the Makefile.in
256
tag_META_INCLUDES (); # Supplies directories for src locations
258
foreach $program (@programs) {
259
$sources_changed{$program} = 0;
260
$depedmocs{$program} = "";
261
$important{$program} = "";
262
tag_IDLFILES(); # Sorts out idl rules
264
tag_UIFILES(); # Sorts out ui rules
265
tag_METASOURCES (); # Sorts out the moc rules
266
if ($sources_changed{$program}) {
267
my $lookup = "$program" . '_SOURCES\s*=\s*(.*)';
268
substituteLine($lookup, "$program\_SOURCES=" . $sources{$program});
270
if ($important{$program}) {
271
local %source_dict = ();
272
for $source (split(/[\034\s]+/, $sources{$program})) {
273
$source_dict{$source} = 1;
275
for $source (@cleanfiles) {
276
$source_dict{$source} = 0;
278
for $source (keys %source_dict) {
280
if ($source_dict{$source}) {
283
print STDERR "Error: $source is listed in a _SOURCE line in $printname, but doesn't exist yet. Put it in DISTCLEANFILES!\n";
285
$target_adds{"\$(srcdir)/$source"} .= $important{$program};
292
# Always add dist clean tag
293
# Add extra *.moc.cpp files created for USE_AUTOMOC because they
294
# aren't included in the normal *.moc clean rules.
295
appendLines ("$cleantarget-metasources:\n\t-rm -f $cleanMoc\n");
296
$target_adds{"$cleantarget-am"} .= "$cleantarget-metasources ";
301
appendLines ("$cleantarget-idl:\n\t-rm -f $idl_output\n");
302
$target_adds{"$cleantarget-am"} .= "$cleantarget-idl ";
306
appendLines ("$cleantarget-ui:\n\t-rm -f $ui_output\n");
307
$target_adds{"$cleantarget-am"} .= "$cleantarget-ui ";
310
if ($closure_output) {
311
appendLines ("$cleantarget-closures:\n\t-rm -f $closure_output\n");
312
$target_adds{"$cleantarget-am"} .= "$cleantarget-closures ";
315
if ($MakefileData =~ /\nKDE_LANG\s*=\s*(\S*)\s*\n/) {
316
$kdelang = '$(KDE_LANG)'
321
tag_POFILES (); # language rules for po directory
322
tag_DOCFILES (); # language rules for doc directories
323
tag_LOCALINSTALL(); # add $(DESTDIR) before all kde_ dirs
327
my $tmp = "force-reedit:\n";
328
$tmp .= "\t$automkCall\n\tcd \$(top_srcdir) && perl $thisProg $printname\n\n";
332
tag_FINAL() if (!$kdeopts{"nofinal"});
334
my $final_lines = "final:\n\t\$(MAKE) ";
335
my $final_install_lines = "final-install:\n\t\$(MAKE) ";
336
my $nofinal_lines = "no-final:\n\t\$(MAKE) ";
337
my $nofinal_install_lines = "no-final-install:\n\t\$(MAKE) ";
339
foreach $program (@programs) {
341
my $lookup = "$program\_OBJECTS.*=[^\n]*";
345
my @list = split(/[\034\s]+/, $realObjs{$program});
347
if (!$kdeopts{"nofinal"} && @list > 1 && $finalObjs{$program}) {
349
$new .= "$program\_final\_OBJECTS = " . $finalObjs{$program};
350
$new .= "\n$program\_nofinal\_OBJECTS = " . $realObjs{$program};
351
$new .= "\n\@KDE_USE_FINAL_FALSE\@$program\_OBJECTS = \$($program\_nofinal\_OBJECTS)";
352
$new .= "\n\@KDE_USE_FINAL_TRUE\@$program\_OBJECTS = \$($program\_final\_OBJECTS)";
354
$final_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" ";
355
$final_install_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" ";
356
$nofinal_lines .= "$program\_OBJECTS=\"\$($program\_nofinal\_OBJECTS)\" ";
357
$nofinal_install_lines .= "$program\_OBJECTS=\"\$($program\_nofinal_OBJECTS)\" ";
359
$new = "$program\_OBJECTS = " . $realObjs{$program};
361
substituteLine ($lookup, $new);
363
appendLines($final_lines . "all-am");
364
appendLines($final_install_lines . "install-am");
365
appendLines($nofinal_lines . "all-am");
366
appendLines($nofinal_install_lines . "install-am");
368
my $lookup = 'DEP_FILES\s*=([^\n]*)';
369
if ($MakefileData =~ /\n$lookup\n/o) {
373
$lines = "\@KDE_USE_FINAL_TRUE\@DEP_FILES = $dep_files $dep_finals \034\t$depfiles\n";
374
$lines .= "\@KDE_USE_FINAL_FALSE\@DEP_FILES = $dep_files $depfiles\n";
376
$lines = "DEP_FILES = $dep_files $depfiles\n";
379
substituteLine($lookup, $lines);
382
my $cvs_lines = "cvs-clean:\n";
383
$cvs_lines .= "\t\$(MAKE) -f \$(top_srcdir)/admin/Makefile.common cvs-clean\n";
384
appendLines($cvs_lines);
386
$cvs_lines = "kde-rpo-clean:\n";
387
$cvs_lines .= "\t-rm -f *.rpo\n";
388
appendLines($cvs_lines);
389
$target_adds{"clean"} .= "kde-rpo-clean ";
391
# some strange people like to do a install-exec, and expect that also
392
# all modules are installed. automake doesn't know this, so we need to move
393
# this here from install-data to install-exec.
394
if ($MakefileData =~ m/\nkde_module_LTLIBRARIES\s*=/) {
395
$target_adds{"install-exec-am"} .= "install-kde_moduleLTLIBRARIES";
396
my $lookup = "install-data-am:\s*(.*)";
397
if ($MakefileData =~ /\n$lookup\n/) {
399
$newdeps =~ s/\s*install-kde_moduleLTLIBRARIES\s*/ /g;
400
substituteLine($lookup, "install-data-am: " . $newdeps);
406
foreach $add (keys %target_adds) {
407
my $lookup = quotemeta($add) . ":\s*(.*)";
408
if ($MakefileData =~ /\n$lookup\n/) {
409
substituteLine($lookup, "$add: " . $target_adds{$add} . $1);
411
$lines .= "$add: " . $target_adds{$add} . "\n";
421
if ($MakefileData =~ m/\n(.*)\$\(CXXFLAGS\)(.*)\n/) {
422
my $vor = $1; # "vor" means before in German
423
my $nach = $2; # "nach" means after in German
424
my $lookup = quotemeta("$1\$(CXXFLAGS)$2");
425
my $replacement = "$1\$(KCXXFLAGS)$2";
426
$MakefileData =~ s/$lookup/$replacement/;
427
$lookup =~ s/\\\$\\\(CXXFLAGS\\\)/\\\$\\\(KCXXFLAGS\\\)/;
428
$replacement = "$vor\$(KCXXFLAGS) \$(KDE_CXXFLAGS)$nach";
429
substituteLine($lookup, $replacement);
435
$lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=link) (\$\(CXXLD\).*\$\(KCXXFLAGS\))';
437
if ($MakefileData =~ m/$lookup/ ) {
438
$MakefileData =~ s/$lookup/$1 --tag=CXX $2/;
441
$lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=compile) (\$\(CXX\).*\$\(KCXXFLAGS\))';
442
if ($MakefileData =~ m/$lookup/ ) {
443
$MakefileData =~ s/$lookup/$1 --tag=CXX $2/;
446
$MakefileData =~ s/\$\(KCXXFLAGS\)/\$\(CXXFLAGS\)/g;
448
$lookup = '(.*)cp -pr \$\$/\$\$file \$\(distdir\)/\$\$file(.*)';
449
if ($MakefileData =~ m/\n$lookup\n/) {
450
substituteLine($lookup, "$1cp -pr \$\$d/\$\$file \$(distdir)/\$\$file$2");
453
# Always update the Makefile.in
458
#-----------------------------------------------------------------------------
460
# Check to see whether we should process this make file.
461
# This is where we look for tags that we need to process.
462
# A small amount of initialising on the tags is also done here.
463
# And of course we open and/or create the needed make files.
466
if (! -r "Makefile.am") {
467
print STDOUT "found Makefile.in without Makefile.am\n" if ($verbose);
471
# Checking for files to process...
472
open (FILEIN, $makefile)
473
|| die "Could not open $makefileDir/$makefile: $!\n";
475
# stat(FILEIN)[7] might look more elegant, but is slower as it
476
# requires stat'ing the file
478
my $fsize = tell(FILEIN);
480
read FILEIN, $MakefileData, $fsize;
482
print "DOS CRLF within $makefileDir/$makefile!\n" if($MakefileData =~ y/\r//d);
484
# Remove the line continuations, but keep them marked
485
# Note: we lose the trailing spaces but that's ok.
486
$MakefileData =~ s/\\\s*\n/\034/g;
488
# If we've processed the file before...
489
restoreMakefile () if ($MakefileData =~ /$progId/);
491
foreach $dir (@foreignfiles) {
492
if (substr($makefileDir,0,length($dir)) eq $dir) {
498
$kdeopts{"foreign"} = 0;
499
$kdeopts{"qtonly"} = 0;
500
$kdeopts{"nofinal"} = !$use_final; # default
502
if ($MakefileData =~ /\nKDE_OPTIONS\s*=\s*([^\n]*)\n/) {
503
local @kde_options = split(/[\s\034]/, $1);
504
if (grep(/^foreign$/, @kde_options)) {
505
push(@foreignfiles, $makefileDir . "/");
506
return 0; # don't touch me
508
for $opt (@kde_options) {
509
if (!defined $kdeopts{$opt}) {
510
print STDERR "Warning: unknown option $opt in $printname\n";
517
# Look for the tags that mean we should process this file.
519
$metasourceTags++ while ($MakefileData =~ /\n[^=\#]*METASOURCES\s*=/g);
522
$pofileTag++ while ($MakefileData =~ /\nPOFILES\s*=/g);
525
print STDERR "Error: Only one POFILES tag allowed\n";
529
while ($MakefileData =~ /\n\.SUFFIXES:([^\n]+)\n/g) {
530
my @list=split(' ', $1);
531
foreach $ext (@list) {
532
if ($ext =~ /^\.$cppExt$/) {
534
$cxxsuffix =~ s/\.//g;
535
print STDOUT "will use suffix $cxxsuffix\n" if ($verbose);
541
while ($MakefileData =~ /\n(\S*)_OBJECTS\s*=[ \t\034]*([^\n]*)\n/g) {
544
my $objs = $2; # safe them
548
my @objlist = split(/[\s\034]+/, $objs);
549
foreach $obj (@objlist) {
550
if ($obj =~ /\$\((\S+)\)/ ) {
552
if ($variable !~ 'OBJEXT') {
560
$program =~ s/^am_// if ($program =~ /^am_/);
562
my $sourceprogram = $program;
563
$sourceprogram =~ s/\@am_/\@/ if($sourceprogram =~ /^.*\@am_.+/);
565
print STDOUT "found program $program\n" if ($verbose);
566
push(@programs, $program);
568
$realObjs{$program} = $objs;
570
if ($MakefileData =~ /\n$sourceprogram\_SOURCES\s*=\s*(.*)\n/) {
571
$sources{$program} = $1;
574
$sources{$program} = "";
575
print STDERR "found program with no _SOURCES: $program\n";
578
my $realprogram = $program;
579
$realprogram =~ s/_/./g; # unmask to regexp
580
if ($MakefileData =~ /\n($realprogram)(\$\(EXEEXT\)?)?:.*\$\($program\_OBJECTS\)/) {
581
$realname{$program} = $1;
583
# not standard Makefile - nothing to worry about
584
$realname{$program} = "";
588
my $lookup = '\nDEPDIR\s*=.*';
589
if ($MakefileData !~ /($lookup)\n/o) {
590
$lookup = '\nbindir\s*=.*';
591
if ($MakefileData =~ /($lookup)\n/) {
592
substituteLine ($lookup, "DEPDIR = .deps\n$1");
596
my @marks = ('MAINTAINERCLEANFILES', 'CLEANFILES', 'DISTCLEANFILES');
597
foreach $mark (@marks) {
598
while ($MakefileData =~ /\n($mark)\s*=\s*([^\n]*)/g) {
599
foreach $file (split('[\034\s]', $2)) {
601
push(@cleanfiles, $file);
607
$localTag++ if ($MakefileData =~ /\ninstall-\S+-local:/);
609
return (!$errorflag);
612
#-----------------------------------------------------------------------------
614
# Gets the list of user defined directories - relative to $srcdir - where
615
# header files could be located.
616
sub tag_META_INCLUDES ()
618
my $lookup = '[^=\n]*META_INCLUDES\s*=\s*(.*)';
619
return 1 if ($MakefileData !~ /($lookup)\n/o);
620
print STDOUT "META_INCLUDE processing <$1>\n" if ($verbose);
623
removeLine ($lookup, $1);
625
$headerStr =~ tr/\034/ /;
626
my @headerlist = split(' ', $headerStr);
628
foreach $dir (@headerlist)
630
$dir =~ s#\$\(srcdir\)#.#;
633
print STDERR "Warning: $dir can't be found. ",
634
"Must be a relative path to \$(srcdir)\n";
638
push (@headerdirs, $dir);
645
#-----------------------------------------------------------------------------
649
my @final_names = ();
651
foreach $program (@programs) {
653
if ($sources{$program} =~ /\(/) {
654
print STDOUT "found ( in $program\_SOURCES. skipping\n" if ($verbose);
660
my @progsources = split(/[\s\034]+/, $sources{$program});
663
foreach $source (@progsources) {
664
my $suffix = $source;
665
$suffix =~ s/^.*\.([^\.]+)$/$1/;
667
if (defined($sourcelist{$suffix})) {
668
$sourcelist{$suffix} .= " " . $source;
670
$sourcelist{$suffix} .= $source;
674
foreach $suffix (keys %sourcelist) {
676
# See if this file contains c++ code. (ie Just check the files suffix against
677
my $suffix_is_cxx = 0;
678
if($suffix =~ /($cppExt)$/) {
683
my $mocfiles_in = ($suffix eq $cxxsuffix) &&
684
defined($depedmocs{$program});
686
my @sourcelist = split(/[\s\034]+/, $sourcelist{$suffix});
688
if ((@sourcelist == 1 && !$mocfiles_in) || $suffix_is_cxx != 1 ) {
690
# we support IDL on our own
691
if ($suffix =~ /^skel$/ || $suffix =~ /^stub/ || $suffix =~ /^h$/
692
|| $suffix =~ /^ui$/ ) {
696
foreach $file (@sourcelist) {
698
$file =~ s/\Q$suffix\E$//;
700
$finalObjs{$program} .= $file;
701
if ($program =~ /_la$/) {
702
$finalObjs{$program} .= "lo ";
704
$finalObjs{$program} .= "o ";
710
my $source_deps = "";
711
foreach $source (@sourcelist) {
713
$source_deps .= "\$(srcdir)/$source ";
715
$source_deps .= "$source ";
719
$handling = "$program.all_$suffix.$suffix: \$(srcdir)/Makefile.in " . $source_deps . " ";
722
$handling .= $depedmocs{$program};
723
foreach $mocfile (split(' ', $depedmocs{$program})) {
724
if ($mocfile =~ m/\.$suffix$/) {
725
$mocsources .= " " . $mocfile;
731
$handling .= "\t\@echo 'creating $program.all_$suffix.$suffix ...'; \\\n";
732
$handling .= "\trm -f $program.all_$suffix.files $program.all_$suffix.final; \\\n";
733
$handling .= "\techo \"#define KDE_USE_FINAL 1\" >> $program.all_$suffix.final; \\\n";
734
$handling .= "\tfor file in " . $sourcelist{$suffix} . " $mocsources; do \\\n";
735
$handling .= "\t echo \"#include \\\"\$\$file\\\"\" >> $program.all_$suffix.files; \\\n";
736
$handling .= "\t test ! -f \$\(srcdir\)/\$\$file || egrep '^#pragma +implementation' \$\(srcdir\)/\$\$file >> $program.all_$suffix.final; \\\n";
737
$handling .= "\tdone; \\\n";
738
$handling .= "\tcat $program.all_$suffix.final $program.all_$suffix.files > $program.all_$suffix.$suffix; \\\n";
739
$handling .= "\trm -f $program.all_$suffix.final $program.all_$suffix.files\n";
741
appendLines($handling);
743
push(@final_names, "$program.all_$suffix.$suffix");
744
$finalObjs{$program} .= "$program.all_$suffix.";
745
if ($program =~ /_la$/) {
746
$finalObjs{$program} .= "lo ";
748
$finalObjs{$program} .= "o ";
753
if (!$kdeopts{"nofinal"} && @final_names >= 1) {
754
# add clean-final target
755
my $lines = "$cleantarget-final:\n";
756
$lines .= "\t-rm -f " . join(' ', @final_names) . "\n" if (@final_names);
758
$target_adds{"$cleantarget-am"} .= "$cleantarget-final ";
760
foreach $finalfile (@final_names) {
761
$finalfile =~ s/\.[^.]*$/.P/;
762
$dep_finals .= " \$(DEPDIR)/$finalfile";
767
# Organises the list of headers that we'll use to produce moc files
769
sub tag_METASOURCES ()
771
local @newObs = (); # here we add to create object files
772
local @deped = (); # here we add to create moc files
773
local $mocExt = ".moc";
774
local %mocFiles = ();
782
if ($metasourceTags > 1) {
783
$lookup = $program . '_METASOURCES\s*=\s*(.*)';
784
return 1 if ($MakefileData !~ /\n($lookup)\n/);
787
$lookup = $program . '_METASOURCES\s*=\s*(.*)';
788
if ($MakefileData !~ /\n($lookup)\n/) {
789
$lookup = 'METASOURCES\s*=\s*(.*)';
790
return 1 if ($MakefileData !~ /\n($lookup)\n/o);
792
$metasourceTags = 0; # we can use the general target only once
797
print STDOUT "METASOURCE processing <$found>)\n" if ($verbose);
800
$postEqual =~ s/[^=]*=//;
802
removeLine ($lookup, $found);
804
# Always find the header files that could be used to "moc"
805
return 1 if (findMocCandidates ());
807
if ($postEqual =~ /AUTO\s*(\S*)|USE_AUTOMOC\s*(\S*)/)
809
print STDERR "$printname: the argument for AUTO|USE_AUTOMOC is obsolete" if ($+);
810
$mocExt = ".moc.$cxxsuffix";
815
# Not automoc so read the list of files supplied which
816
# should be .moc files.
818
$postEqual =~ tr/\034/ /;
820
# prune out extra headers - This also checks to make sure that
822
pruneMocCandidates ($postEqual);
825
checkMocCandidates ();
828
my $ext = ($program =~ /_la$/) ? ".moc.lo " : ".moc.o ";
829
$realObjs{$program} .= "\034" . join ($ext, @newObs) . $ext;
830
$depedmocs{$program} = join (".moc.$cxxsuffix " , @newObs) . ".moc.$cxxsuffix";
831
foreach $file (@newObs) {
832
$dep_files .= " \$(DEPDIR)/$file.moc.P" if($dep_files !~/$file.moc.P/);
836
$depedmocs{$program} .= " ";
837
$depedmocs{$program} .= join('.moc ', @deped) . ".moc";
838
$depedmocs{$program} .= " ";
841
@globalmocs{keys %mocFiles}=values %mocFiles;
844
#-----------------------------------------------------------------------------
846
# Returns 0 if the line was processed - 1 otherwise.
847
# Errors are logged in the global $errorflags
850
my $lookup = '.*cd \$\(top_srcdir\)\s+&&[\s\034]+\$\(AUTOMAKE\)(.*)';
851
return 1 if ($MakefileData !~ /\n($lookup)\n/);
852
print STDOUT "AUTOMAKE processing <$1>\n" if ($verbose);
854
my $newLine = $1."\n\tcd \$(top_srcdir) && perl $thisProg $printname";
855
substituteLine ($lookup, $newLine);
860
#-----------------------------------------------------------------------------
862
sub handle_TOPLEVEL()
866
opendir (THISDIR, ".");
867
foreach $entry (readdir(THISDIR)) {
870
next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/ || $entry =~ /.gmo$/);
872
if ($entry =~ /\.po$/) {
875
push(@restfiles, $entry);
880
$target_adds{"install-data-am"} .= "install-nls-files ";
881
$lines = "install-nls-files:\n";
882
$lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$kdelang\n";
883
for $file (@restfiles) {
884
$lines .= "\t\$(INSTALL_DATA) \$\(srcdir\)/$file \$(DESTDIR)\$(kde_locale)/$kdelang/$file\n";
886
$target_adds{"uninstall"} .= "uninstall-nls-files ";
887
$lines .= "uninstall-nls-files:\n";
888
for $file (@restfiles) {
889
$lines .= "\t-rm -f \$(DESTDIR)\$(kde_locale)/$kdelang/$file\n";
897
#-----------------------------------------------------------------------------
901
if ($MakefileData !~ /\nSUBDIRS\s*=\s*\$\(AUTODIRS\)\s*\n/) {
907
opendir (THISDIR, ".");
908
foreach $entry (readdir(THISDIR)) {
909
next if ($entry eq "CVS" || $entry =~ /^\./);
910
if (-d $entry && -f $entry . "/Makefile.am") {
911
$subdirs .= " $entry";
917
my $lines = "SUBDIRS =$subdirs\n";
918
substituteLine('SUBDIRS\s*=.*', $lines);
924
my @psources = split(/[\034\s]+/, $sources{$program});
928
foreach $source (@psources) {
930
my $skel = ($source =~ m/\.skel$/);
932
if ($source =~ m/\.stub$/ || $skel) {
934
my $qs = quotemeta($source);
935
$sources{$program} =~ s/$qs//;
936
$sources_changed{$program} = 1;
938
print STDOUT "adding IDL file $source\n" if ($verbose);
940
$source =~ s/\.(stub|skel)$//;
945
$sourcename = "$source\_skel";
947
$sourcename = "$source\_stub";
951
if (-f "$makefileDir/$source.h") {
952
$sourcedir = '$(srcdir)/';
954
if ($MakefileData =~ /\n$source\_DIR\s*=\s*(\S+)\n/) {
956
$sourcedir .= "/" if ($sourcedir !~ /\/$/);
960
if ($allidls !~ /$source\_kidl/) {
962
$dep_lines .= "$source.kidl: $sourcedir$source.h \$(DCOPIDL_DEPENDENCIES)\n";
963
$dep_lines .= "\t\$(DCOPIDL) $sourcedir$source.h > $source.kidl || ( rm -f $source.kidl ; /bin/false )\n";
965
$allidls .= $source . "_kidl ";
968
if ($allidls !~ /$sourcename/) {
971
$dep_lines .= "$sourcename.$cxxsuffix: $source.kidl\n";
972
$dep_lines .= "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-stub $source.kidl\n";
974
$target_adds{"$sourcename.$cxxsuffix"} .= "$sourcename.h ";
975
$dep_lines .= "$sourcename.h: $source.kidl\n";
976
$dep_lines .= "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-skel $source.kidl\n";
979
$allidls .= $sourcename . " ";
982
$idlfiles{$program} .= $sourcename . " ";
984
if ($program =~ /_la$/) {
985
$realObjs{$program} .= " $sourcename.lo";
987
$realObjs{$program} .= " $sourcename.\$(OBJEXT)";
989
$sources{$program} .= " $sourcename.$cxxsuffix";
990
$sources_changed{$program} = 1;
991
$important{$program} .= "$sourcename.h " if (!$skel);
992
$idl_output .= "\\\n\t$sourcename.$cxxsuffix $sourcename.h $source.kidl ";
993
push(@cleanfiles, "$sourcename.$cxxsuffix");
994
push(@cleanfiles, "$sourcename.h");
995
push(@cleanfiles, "$sourcename.kidl");
996
$dep_files .= " \$(DEPDIR)/$sourcename.P" if ($dep_files !~/$sourcename.P/);
1000
appendLines($dep_lines);
1004
my $lookup = "($program)";
1005
$lookup .= '(|\$\(EXEEXT\))';
1006
$lookup =~ s/\_/./g;
1007
$lookup .= ":(.*..$program\_OBJECTS..*)";
1008
# $lookup = quotemeta($lookup);
1009
if ($MakefileData =~ /\n$lookup\n/) {
1011
my $line = "$1$2: ";
1012
foreach $file (split(' ', $idlfiles{$program})) {
1013
$line .= "$file.$cxxsuffix ";
1016
substituteLine($lookup, $line);
1018
print STDERR "no built dependency found $lookup\n";
1025
my @psources = split(/[\034\s]+/, $sources{$program});
1029
foreach $source (@psources) {
1031
if ($source =~ m/\.ui$/) {
1033
print STDERR "adding UI file $source\n" if ($verbose);
1035
my $qs = quotemeta($source);
1036
$sources{$program} =~ s/$qs//;
1037
$sources_changed{$program} = 1;
1039
$source =~ s/\.ui$//;
1042
if (-f "$makefileDir/$source.ui") {
1043
$sourcedir = '$(srcdir)/';
1046
if (!$uiFiles{$source}) {
1048
$dep_lines .= "$source.$cxxsuffix: $sourcedir$source.ui $source.h $source.moc\n";
1049
$dep_lines .= "\trm -f $source.$cxxsuffix\n";
1050
if (!$kdeopts{"qtonly"}) {
1051
$dep_lines .= "\techo '#include <klocale.h>' > $source.$cxxsuffix\n";
1052
$dep_lines .= "\t\$(UIC) -tr \${UIC_TR} -i $source.h $sourcedir$source.ui | sed -e \"s,i18n( \\\"\\\" ),QString::null,g\" | sed -e \"s,QT_KDE_I18N( \\\"\\\"\\, \\\"\\\" ),QString::null,g\" >> $source.$cxxsuffix || rm -f $source.$cxxsuffix\n";
1054
$dep_lines .= "\t\$(UIC) -i $source.h $sourcedir$source.ui > $source.$cxxsuffix || rm -f $source.$cxxsuffix\n";
1056
$dep_lines .= "\techo '#include \"$source.moc\"' >> $source.$cxxsuffix\n\n";
1057
$dep_lines .= "$source.h: $sourcedir$source.ui\n";
1058
$dep_lines .= "\t\$(UIC) -o $source.h $sourcedir$source.ui\n\n";
1059
$dep_lines .= "$source.moc: $source.h\n";
1060
$dep_lines .= "\t\$(MOC) $source.h -o $source.moc\n";
1062
$uiFiles{$source} = 1;
1063
$depedmocs{$program} .= " $source.moc";
1064
$globalmocs{$source} = "\035$source.h\035$source.cpp";
1067
if ($program =~ /_la$/) {
1068
$realObjs{$program} .= " $source.lo";
1070
$realObjs{$program} .= " $source.\$(OBJEXT)";
1072
$sources{$program} .= " $source.$cxxsuffix";
1073
$sources_changed{$program} = 1;
1074
$important{$program} .= "$source.h ";
1075
$ui_output .= "\\\n\t$source.$cxxsuffix $source.h $source.moc ";
1076
push(@cleanfiles, "$source.$cxxsuffix");
1077
push(@cleanfiles, "source.h");
1078
push(@cleanfiles, "$source.moc");
1079
$dep_files .= " \$(DEPDIR)/$source.P" if($dep_files !~/$source.P/ );
1083
appendLines($dep_lines);
1089
my $lookup = '([^\s]*)_ICON\s*=\s*([^\n]*)';
1093
while ($MakefileData =~ /\n$lookup/og) {
1096
$destdir = "kde_icondir";
1098
$destdir = $1 . "dir";
1100
my $iconauto = ($2 =~ /AUTO\s*$/);
1102
if ( ! $iconauto ) {
1103
my @_appnames = split(" ", $2);
1104
print STDOUT "KDE_ICON processing <@_appnames>\n" if ($verbose);
1105
foreach $appname (@_appnames) {
1106
push(@appnames, quotemeta($appname));
1109
print STDOUT "KDE_ICON processing <AUTO>\n" if ($verbose);
1113
opendir (THISDIR, ".");
1114
foreach $entry (readdir(THISDIR)) {
1115
next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
1116
next if (! -f $entry);
1119
push(@files, $entry)
1120
if ($entry =~ /\.xpm/ || $entry =~ /\.png/);
1122
foreach $appname (@appnames) {
1123
push(@files, $entry)
1124
if ($entry =~ /-$appname\.xpm/ || $entry =~ /-$appname\.png/);
1130
my %directories = ();
1132
foreach $file (@files) {
1133
my $newfile = $file;
1135
$prefix =~ s/\.(png|xpm)$//;
1136
my $appname = $prefix;
1137
$appname =~ s/^[^-]+-// if ($appname =~ /-/) ;
1138
$appname =~ s/^[^-]+-// if ($appname =~ /-/) ;
1139
$appname = quotemeta($appname);
1140
$prefix =~ s/$appname$//;
1143
$prefix = 'lo16-app' if ($prefix eq 'mini');
1144
$prefix = 'lo32-app' if ($prefix eq 'lo');
1145
$prefix = 'hi48-app' if ($prefix eq 'large');
1146
$prefix .= '-app' if ($prefix =~ m/^...$/);
1149
$type =~ s/^.*-([^-]+)$/$1/;
1150
$prefix =~ s/^(.*)-[^-]+$/$1/;
1154
'action' => 'actions',
1156
'device' => 'devices',
1157
'filesys' => 'filesystems',
1158
'mime' => 'mimetypes'
1161
if (! defined $type_hash{$type} ) {
1162
print STDERR "unknown icon type $type in $printname ($file)\n";
1168
'los' => 'locolor/16x16',
1169
'lom' => 'locolor/32x32',
1170
'him' => 'hicolor/32x32',
1171
'hil' => 'hicolor/48x48',
1172
'lo16' => 'locolor/16x16',
1173
'lo22' => 'locolor/22x22',
1174
'lo32' => 'locolor/32x32',
1175
'hi16' => 'hicolor/16x16',
1176
'hi22' => 'hicolor/22x22',
1177
'hi32' => 'hicolor/32x32',
1178
'hi48' => 'hicolor/48x48',
1179
'hi64' => 'hicolor/64x64',
1180
'hisc' => 'hicolor/scalable'
1183
$newfile =~ s@.*-($appname\.(png|xpm?))@$1@;
1185
if (! defined $dir_hash{$prefix}) {
1186
print STDERR "unknown icon prefix $prefix in $printname\n";
1190
my $dir = $dir_hash{$prefix} . "/" . $type_hash{$type};
1191
if ($newfile =~ /-[^\.]/) {
1193
$tmp =~ s/^([^-]+)-.*$/$1/;
1194
$dir = $dir . "/" . $tmp;
1195
$newfile =~ s/^[^-]+-//;
1198
if (!defined $directories{$dir}) {
1199
$install .= "\t\$(mkinstalldirs) \$(DESTDIR)\$($destdir)/$dir\n";
1200
$directories{$dir} = 1;
1203
$install .= "\t\$(INSTALL_DATA) \$(srcdir)/$file \$(DESTDIR)\$($destdir)/$dir/$newfile\n";
1204
$uninstall .= "\t-rm -f \$(DESTDIR)\$($destdir)/$dir/$newfile\n";
1209
if (length($install)) {
1210
$target_adds{"install-data-am"} .= "install-kde-icons ";
1211
$target_adds{"uninstall-am"} .= "uninstall-kde-icons ";
1212
appendLines("install-kde-icons:\n" . $install . "\nuninstall-kde-icons:\n" . $uninstall);
1216
sub handle_POFILES($$)
1218
my @pofiles = split(" ", $_[0]);
1221
# Build rules for creating the gmo files
1223
my $allgmofiles = "";
1224
my $pofileLine = "POFILES =";
1225
foreach $pofile (@pofiles)
1227
$pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1228
$tmp .= "$1.gmo: $pofile\n";
1229
$tmp .= "\trm -f $1.gmo; \$(GMSGFMT) -o $1.gmo \$(srcdir)/$pofile\n";
1230
$tmp .= "\ttest ! -f $1.gmo || touch $1.gmo\n";
1231
$allgmofiles .= " $1.gmo";
1232
$pofileLine .= " $1.po";
1235
my $lookup = 'POFILES\s*=([^\n]*)';
1236
if ($MakefileData !~ /\n$lookup/o) {
1237
appendLines("$pofileLine\nGMOFILES =$allgmofiles");
1239
substituteLine ($lookup, "$pofileLine\nGMOFILES =$allgmofiles");
1244
# Add the "clean" rule so that the maintainer-clean does something
1245
appendLines ("clean-nls:\n\t-rm -f $allgmofiles\n");
1247
$target_adds{"maintainer-clean"} .= "clean-nls ";
1249
$lookup = 'DISTFILES\s*=\s*(.*)';
1250
if ($MakefileData =~ /\n$lookup\n/o) {
1251
$tmp = "DISTFILES = \$(GMOFILES) \$(POFILES) $1";
1252
substituteLine ($lookup, $tmp);
1256
$target_adds{"install-data-am"} .= "install-nls ";
1258
$tmp = "install-nls:\n";
1260
$tmp .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES\n";
1262
$tmp .= "\t\@for base in ";
1263
foreach $pofile (@pofiles)
1265
$pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1269
$tmp .= "; do \\\n";
1271
$tmp .= "\t echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n";
1272
$tmp .= "\t test ! -f \$\$base.gmo || \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n"
1274
$tmp .= "\t echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
1275
$tmp .= "\t \$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES ; \\\n";
1276
$tmp .= "\t test ! -f \$\$base.gmo || \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
1278
$tmp .= "\tdone\n\n";
1281
$target_adds{"uninstall"} .= "uninstall-nls ";
1283
$tmp = "uninstall-nls:\n";
1284
foreach $pofile (@pofiles)
1286
$pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1288
$tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/$1.mo\n";
1290
$tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$1/LC_MESSAGES/\$(PACKAGE).mo\n";
1295
$target_adds{"all"} .= "all-nls ";
1297
$tmp = "all-nls: \$(GMOFILES)\n";
1301
$target_adds{"distdir"} .= "distdir-nls ";
1303
$tmp = "distdir-nls:\$(GMOFILES)\n";
1304
$tmp .= "\tfor file in \$(POFILES); do \\\n";
1305
$tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n";
1307
$tmp .= "\tfor file in \$(GMOFILES); do \\\n";
1308
$tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n";
1314
appendLines("merge:\n\t\$(MAKE) -f \$(top_srcdir)/admin/Makefile.common package-merge POFILES=\"\${POFILES}\" PACKAGE=\${PACKAGE}\n\n");
1319
#-----------------------------------------------------------------------------
1321
# Returns 0 if the line was processed - 1 otherwise.
1322
# Errors are logged in the global $errorflags
1325
my $lookup = 'POFILES\s*=([^\n]*)';
1326
return 1 if ($MakefileData !~ /\n$lookup/o);
1327
print STDOUT "POFILES processing <$1>\n" if ($verbose);
1331
# make sure these are all gone.
1332
if ($MakefileData =~ /\n\.po\.gmo:\n/)
1334
print STDERR "Warning: Found old .po.gmo rules in $printname. New po rules not added\n";
1338
# Either find the pofiles in the directory (AUTO) or use
1339
# only the specified po files.
1341
if ($tmp =~ /^\s*AUTO\s*$/)
1343
opendir (THISDIR, ".");
1344
next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^#.*#$/);
1345
$pofiles = join(" ", grep(/\.po$/, readdir(THISDIR)));
1347
print STDOUT "pofiles found = $pofiles\n" if ($verbose);
1348
if (-f "charset" && -f "kdelibs.po") {
1357
return 1 if (!$pofiles); # Nothing to do
1359
handle_POFILES($pofiles, $kdelang);
1364
sub helper_LOCALINSTALL($)
1366
my $lookup = "\n" . $_[0] . ":";
1367
if ($MakefileData =~ /($lookup)/) {
1369
my $install = $MakefileData;
1370
$install =~ s/\n/\035/g;
1371
$install =~ s/.*\035$_[0]:[^\035]*\035//;
1373
while (! $emptyline) {
1374
if ($install =~ /([^\035]*)\035(.*)/) {
1377
if ($line !~ /^\s*$/ && $line !~ /^(\@.*\@)*\t/) {
1380
replaceDestDir($line);
1390
sub tag_LOCALINSTALL ()
1392
helper_LOCALINSTALL('install-exec-local');
1393
helper_LOCALINSTALL('install-data-local');
1394
helper_LOCALINSTALL('uninstall-local');
1399
sub replaceDestDir($) {
1400
local $line = $_[0];
1402
if ( $line =~ /^\s*(\@.*\@)*\s*\$\(mkinstalldirs\)/
1403
|| $line =~ /^\s*(\@.*\@)*\s*\$\(INSTALL\S*\)/
1404
|| $line =~ /^\s*(\@.*\@)*\s*(-?rm.*) \S*$/)
1406
$line =~ s/^(.*) ([^\s]*)\s*$/$1 \$(DESTDIR)$2/ if ($line !~ /\$\(DESTDIR\)/);
1409
if ($line ne $_[0]) {
1410
$_[0] = quotemeta $_[0];
1411
substituteLine($_[0], $line);
1415
#---------------------------------------------------------------------------
1416
sub tag_CLOSURE () {
1417
return if ($program !~ /_la$/);
1419
my $lookup = quotemeta($realname{$program}) . ":.*?\n\t.*?\\((.*?)\\) .*\n";
1420
$MakefileData =~ m/$lookup/;
1421
return if ($1 !~ /CXXLINK/);
1423
if ($MakefileData !~ /\n$program\_LDFLAGS\s*=.*-no-undefined/ &&
1424
$MakefileData !~ /\n$program\_LDFLAGS\s*=.*KDE_PLUGIN/ ) {
1425
print STDERR "Report: $program contains undefined in $printname\n" if ($program =~ /^lib/ && $dryrun);
1428
my $closure = $realname{$program} . ".closure";
1429
my $lines = "$closure: \$($program\_OBJECTS) \$($program\_DEPENDENCIES)\n";
1430
$lines .= "\t\@echo \"int main() {return 0;}\" > $program\_closure.$cxxsuffix\n";
1431
$lines .= "\t\@\$\(LTCXXCOMPILE\) -c $program\_closure.$cxxsuffix\n";
1432
$lines .= "\t\@\$\(CXXLINK\) $program\_closure.lo \$($program\_LDFLAGS) \$($program\_OBJECTS) \$($program\_LIBADD) \$(LIBS)\n";
1433
$lines .= "\t\@rm -f $program\_closure.* $closure\n";
1434
$lines .= "\t\@echo \"timestamp\" > $closure\n";
1436
appendLines($lines);
1437
$lookup = $realname{$program} . ": (.*)";
1438
if ($MakefileData =~ /\n$lookup\n/) {
1439
$lines = "\@KDE_USE_CLOSURE_TRUE@". $realname{$program} . ": $closure $1";
1440
$lines .= "\n\@KDE_USE_CLOSURE_FALSE@" . $realname{$program} . ": $1";
1441
substituteLine($lookup, $lines);
1443
$closure_output .= " $closure";
1447
my %foundfiles = ();
1448
opendir (THISDIR, ".");
1449
foreach $entry (readdir(THISDIR)) {
1450
next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile$$/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
1451
next if (! -f $entry);
1452
next if ($entry =~ /\.moc/ || $entry =~ /\.lo$/ || $entry =~ /\.la$/ || $entry =~ /\.o/);
1453
$foundfiles{$entry} = 1;
1457
my @marks = ("EXTRA_DIST", "DIST_COMMON", '\S*_SOURCES', '\S*_HEADERS', 'MAINTAINERCLEANFILES', 'CLEANFILES', 'DISTCLEANFILES', '\S*_OBJECTS');
1458
foreach $mark (@marks) {
1459
while ($MakefileData =~ /\n($mark)\s*=\s*([^\n]*)/g) {
1460
foreach $file (split('[\034\s]', $2)) {
1462
$foundfiles{$file} = 0 if (defined $foundfiles{$file});
1466
my @files = ("Makefile", "config.cache", "config.log", "stamp-h",
1467
"stamp-h1", "stamp-h1", "config.h", "Makefile", "config.status", "config.h", "libtool");
1468
foreach $file (@files) {
1469
$foundfiles{$file} = 0 if (defined $foundfiles{$file});
1473
foreach $file (keys %foundfiles) {
1474
if ($foundfiles{$file} == 1) {
1475
$KDE_DIST .= "$file ";
1479
print "KDE_DIST $printname $KDE_DIST\n" if ($verbose);
1481
my $lookup = "DISTFILES *=(.*)";
1482
if ($MakefileData =~ /\n$lookup\n/o) {
1483
substituteLine($lookup, "KDE_DIST=$KDE_DIST\n\nDISTFILES=$1 \$(KDE_DIST)\n");
1488
#-----------------------------------------------------------------------------
1489
# Returns 0 if the line was processed - 1 otherwise.
1490
# Errors are logged in the global $errorflags
1493
# if ($MakefileData =~ /\nSUBDIRS\s*=/) { # subdirs
1494
# $MakefileData =~ /\n(.*-recursive:\s*)\n/;
1495
# my $orig_rules = $1;
1496
# my $rules = $orig_rules;
1497
# $rules =~ s/:\s*$//;
1498
# substituteLine($orig_rules, "$rules docs-recursive:");
1499
# appendLines("docs: docs-recursive docs-am\n");
1501
# appendLines("docs: docs-am\n");
1503
$target_adds{"all"} .= "docs-am ";
1505
my $lookup = 'KDE_DOCS\s*=\s*([^\n]*)';
1506
goto nodocs if ($MakefileData !~ /\n$lookup/o);
1507
print STDOUT "KDE_DOCS processing <$1>\n" if ($verbose);
1511
# Either find the files in the directory (AUTO) or use
1512
# only the specified po files.
1515
$appname =~ s/^(\S*)\s*.*$/$1/;
1516
if ($appname =~ /AUTO/) {
1517
$appname = basename($makefileDir);
1518
if ("$appname" eq "en") {
1519
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";
1526
opendir (THISDIR, ".");
1527
foreach $entry (readdir(THISDIR)) {
1528
next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
1529
next if (! -f $entry);
1530
$files .= "$entry ";
1533
print STDOUT "docfiles found = $files\n" if ($verbose);
1538
$tmp =~ s/^\S*\s*-\s*//;
1541
goto nodocs if (!$files); # Nothing to do
1543
if ($files =~ /(^| )index\.docbook($| )/) {
1546
my $lookup = 'MEINPROC\s*=';
1547
if ($MakefileData !~ /\n($lookup)/) {
1548
$lines = "MEINPROC=/\$(kde_bindir)/meinproc\n";
1550
$lookup = 'KDE_XSL_STYLESHEET\s*=';
1551
if ($MakefileData !~ /\n($lookup)/) {
1552
$lines .= "KDE_XSL_STYLESHEET=/\$(kde_datadir)/ksgmltools2/customization/kde-chunk.xsl\n";
1554
$lookup = '\nindex.cache.bz2:';
1555
if ($MakefileData !~ /\n($lookup)/) {
1556
$lines .= "index.cache.bz2: \$(srcdir)/index.docbook \$(KDE_XSL_STYLESHEET) $files\n";
1557
$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";
1561
$lines .= "docs-am: index.cache.bz2\n";
1563
$lines .= "install-docs: docs-am install-nls\n";
1564
$lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n";
1565
$lines .= "\t\@if test -f index.cache.bz2; then \\\n";
1566
$lines .= "\techo \$(INSTALL_DATA) index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n";
1567
$lines .= "\t\$(INSTALL_DATA) index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n";
1569
$lines .= "\t-rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n";
1570
$lines .= "\t\$(LN_S) \$(kde_libs_htmldir)/$kdelang/common \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n";
1573
$lines .= "uninstall-docs:\n";
1574
$lines .= "\t-rm -rf \$(kde_htmldir)/$kdelang/$appname\n";
1576
$lines .= "clean-docs:\n";
1577
$lines .= "\t-rm -f index.cache.bz2\n";
1579
$target_adds{"install-data-am"} .= "install-docs ";
1580
$target_adds{"uninstall"} .= "uninstall-docs ";
1581
$target_adds{"clean-am"} .= "clean-docs ";
1582
appendLines ($lines);
1584
appendLines("docs-am: $files\n");
1587
$target_adds{"install-data-am"} .= "install-nls";
1588
$target_adds{"uninstall"} .= "uninstall-nls ";
1590
$tmp = "install-nls:\n";
1591
$tmp .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n";
1592
$tmp .= "\t\@for base in $files; do \\\n";
1593
$tmp .= "\t echo \$(INSTALL_DATA) \$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1594
$tmp .= "\t \$(INSTALL_DATA) \$(srcdir)/\$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1596
if ($appname eq 'common') {
1597
$tmp .= "\t\@echo \"merging common and language specific dir\" ;\\\n";
1598
$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";
1599
$tmp .= "\t\@com_files=`cd \$(kde_htmldir)/en/common && echo *` ;\\\n";
1600
$tmp .= "\tcd \$(DESTDIR)\$(kde_htmldir)/$kdelang/common ;\\\n";
1601
$tmp .= "\tif test -n \"\$\$com_files\"; then for p in \$\$com_files ; do \\\n";
1602
$tmp .= "\t case \" $files \" in \\\n";
1603
$tmp .= "\t *\" \$\$p \"*) ;; \\\n";
1604
$tmp .= "\t *) test ! -e \$\$p && echo \$(LN_S) ../../en/common/\$\$p \$(DESTDIR)\$(kde_htmldir)/$kdelang/common/\$\$p && \$(LN_S) ../../en/common/\$\$p \$\$p ;; \\\n";
1605
$tmp .= "\t esac ; \\\n";
1606
$tmp .= "\tdone ; fi ; true\n";
1609
$tmp .= "uninstall-nls:\n";
1610
$tmp .= "\tfor base in $files; do \\\n";
1611
$tmp .= "\t rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1612
$tmp .= "\tdone\n\n";
1615
$target_adds{"distdir"} .= "distdir-nls ";
1617
$tmp = "distdir-nls:\n";
1618
$tmp .= "\tfor file in $files; do \\\n";
1619
$tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n";
1627
appendLines("docs-am:\n");
1631
#-----------------------------------------------------------------------------
1632
# Find headers in any of the source directories specified previously, that
1633
# are candidates for "moc-ing".
1634
sub findMocCandidates ()
1636
foreach $dir (@headerdirs)
1639
opendir (SRCDIR, "$dir");
1640
@hFiles = grep { /.+\.$hExt$/o } readdir(SRCDIR);
1642
foreach $hf (@hFiles)
1644
$hf =~ /(.*)\.[^\.]*$/; # Find name minus extension
1645
next if ($uiFiles{$1});
1646
open (HFIN, "$dir/$hf") || die "Could not open $dir/$hf: $!\n";
1649
$hfsize = tell(HFIN);
1651
read HFIN, $hfData, $hfsize;
1653
# push (@list, $hf) if(index($hfData, "Q_OBJECT") >= 0); ### fast but doesn't handle //Q_OBJECT
1654
if ( $hfData =~ /{([^}]*)Q_OBJECT/s ) { ## handle " { friend class blah; Q_OBJECT "
1655
push (@list, $hf) unless $1 =~ m://[^\n]*Q_OBJECT[^\n]*$:s; ## handle "// Q_OBJECT"
1658
# The assoc array of root of headerfile and header filename
1659
foreach $hFile (@list)
1661
$hFile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1664
print STDERR "Warning: Multiple header files found for $1\n";
1665
next; # Use the first one
1667
$mocFiles{$1} = "$dir\035$hFile"; # Add relative dir
1674
#-----------------------------------------------------------------------------
1676
# The programmer has specified a moc list. Prune out the moc candidates
1677
# list that we found based on looking at the header files. This generates
1678
# a warning if the programmer gets the list wrong, but this doesn't have
1680
sub pruneMocCandidates ($)
1683
local @mocList = split(' ', @_[0]);
1685
foreach $mocname (@mocList)
1687
$mocname =~ s/\.moc$//;
1688
if ($mocFiles{$mocname})
1690
$prunedMoc{$mocname} = $mocFiles{$mocname};
1694
my $print = $makefileDir;
1695
$print =~ s/^\Q$topdir\E\\//;
1696
# They specified a moc file but we can't find a header that
1697
# will generate this moc file. That's possible fatal!
1698
print STDERR "Warning: No moc-able header file for $print/$mocname\n";
1703
%mocFiles = %prunedMoc;
1706
#-----------------------------------------------------------------------------
1708
# Finds the cpp files (If they exist).
1709
# The cpp files get appended to the header file separated by \035
1710
sub checkMocCandidates ()
1713
my $cpp2moc; # which c++ file includes which .moc files
1714
my $moc2cpp; # which moc file is included by which c++ files
1716
return unless (keys %mocFiles);
1717
opendir(THISDIR, ".") || return;
1718
@cppFiles = grep { /.+\.$cppExt$/o && !/.+\.moc\.$cppExt$/o
1719
&& !/.+\.all_$cppExt\.$cppExt$/o } readdir(THISDIR);
1721
return unless (@cppFiles);
1722
my $files = join (" ", @cppFiles);
1725
foreach $cxxf (@cppFiles)
1727
open (CXXFIN, $cxxf) || die "Could not open $cxxf: $!\n";
1729
my $cxxfsize = tell(CXXFIN);
1731
read CXXFIN, $cxxfData, $cxxfsize;
1733
while(($cxxfData =~ m/^[ \t]*\#include\s*[<\"](.*\.moc)[>\"]/gm)) {
1734
$cpp2moc->{$cxxf}->{$1} = 1;
1735
$moc2cpp->{$1}->{$cxxf} = 1;
1738
foreach my $mocFile (keys (%mocFiles))
1740
@cppFiles = keys %{$moc2cpp->{"$mocFile.moc"}};
1741
if (@cppFiles == 1) {
1742
$mocFiles{$mocFile} .= "\035" . $cppFiles[0];
1743
push(@deped, $mocFile);
1744
} elsif (@cppFiles == 0) {
1745
push (@newObs, $mocFile); # Produce new object file
1746
next if ($haveAutomocTag); # This is expected...
1747
# But this is an error we can deal with - let them know
1749
"Warning: No c++ file that includes $mocFile.moc\n";
1751
# We can't decide which file to use, so it's fatal. Although as a
1752
# guess we could use the mocFile.cpp file if it's in the list???
1754
"Error: Multiple c++ files that include $mocFile.moc\n";
1755
print STDERR "\t",join ("\t", @cppFiles),"\n";
1757
delete $mocFiles{$mocFile};
1758
# Let's continue and see what happens - They have been told!
1763
#-----------------------------------------------------------------------------
1765
# Add the rules for generating moc source from header files
1766
# For Automoc output *.moc.cpp but normally we'll output *.moc
1767
# (We must compile *.moc.cpp separately. *.moc files are included
1768
# in the appropriate *.cpp file by the programmer)
1774
foreach $mocFile (keys (%mocFiles))
1777
($dir, $hFile, $cppFile) = split ("\035", $mocFiles{$mocFile}, 3);
1778
$dir =~ s#^\.#\$(srcdir)#;
1779
if (defined ($cppFile))
1781
$target_adds{"\$(srcdir)/$cppFile"} .= "$mocFile.moc ";
1782
appendLines ("$mocFile.moc: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile.moc\n");
1783
$cleanMoc .= " $mocFile.moc";
1787
appendLines ("$mocFile$mocExt: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile$mocExt\n");
1788
$cleanMoc .= " $mocFile$mocExt";
1793
sub make_meta_classes ()
1795
return if ($kdeopts{"qtonly"});
1799
my $moc_class_headers = "";
1800
foreach $program (@programs) {
1802
my @progsources = split(/[\s\034]+/, $sources{$program});
1803
my @depmocs = split(' ', $depedmocs{$program});
1804
my %shash = (), %mhash = ();
1805
@shash{@progsources} = 1; # we are only interested in the existence
1806
@mhash{@depmocs} = 1;
1808
print STDOUT "program=$program\n" if ($verbose);
1809
print STDOUT "psources=[".join(' ', keys %shash)."]\n" if ($verbose);
1810
print STDOUT "depmocs=[".join(' ', keys %mhash)."]\n" if ($verbose);
1811
print STDOUT "globalmocs=[".join(' ', keys(%globalmocs))."]\n" if ($verbose);
1812
foreach my $mocFile (keys (%globalmocs))
1815
($dir, $hFile, $cppFile) = split ("\035", $globalmocs{$mocFile}, 3);
1816
$dir =~ s#^\.#\$(srcdir)#;
1817
if (defined ($cppFile))
1819
$mocs .= " $mocFile.moc" if exists $shash{$cppFile};
1823
# Bah. This is the case, if no C++ file includes the .moc
1824
# file. We make a .moc.cpp file for that. Unfortunately this
1825
# is not included in the %sources hash, but rather is mentioned
1826
# in %depedmocs. If the user wants to use AUTO he can't just
1827
# use an unspecific METAINCLUDES. Instead he must use
1828
# program_METAINCLUDES. Anyway, it's not working real nicely.
1829
# E.g. Its not clear what happens if user specifies two
1830
# METAINCLUDES=AUTO in the same Makefile.am.
1831
$mocs .= " $mocFile.moc.$cxxsuffix"
1832
if exists $mhash{$mocFile.".moc.$cxxsuffix"};
1836
print STDOUT "==> mocs=[".$mocs."]\n" if ($verbose);
1837
my $sourcename = $program."_meta_unload";
1838
my $ext = ($program =~ /_la$/) ? ".lo" : ".o";
1839
my $srcfile = $sourcename.".$cxxsuffix";
1840
my $objfile = $sourcename.$ext;
1841
$moc_class_headers .= " $srcfile";
1843
$appl = "$srcfile: $mocs\n";
1844
$appl .= "\t\@echo 'creating $srcfile'\n";
1845
$appl .= "\t\@-rm -f $srcfile\n";
1846
$appl .= "\t\@if test \${kde_qtver} = 2; then \\\n";
1847
$appl .= "\t\techo 'static const char * _metalist_$program\[\] = {' > $srcfile ;\\\n";
1848
$appl .= "\t\tcat $mocs | grep 'char.*className' | ";
1849
$appl .= "sed -e 's/.*[^A-Za-z0-9_:]\\([A-Za-z0-9_:]*\\)::className.*\$\$/\\\"\\1\\\",/' | sort | uniq >> $srcfile ;\\\n";
1850
$appl .= "\t\techo '0};' >> $srcfile ;\\\n";
1851
$appl .= "\t\techo '#include <kunload.h>' >> $srcfile ;\\\n";
1852
$appl .= "\t\techo '_UNLOAD($program)' >> $srcfile ;\\\n";
1853
$appl .= "\telse echo > $srcfile; fi\n";
1856
$realObjs{$program} .= " \034" . $objfile . " ";
1857
$sources{$program} .= " $srcfile";
1858
$sources_changed{$program} = 1;
1859
$dep_files .= " \$(DEPDIR)/$sourcename.P" if($dep_files !~/$sourcename.P/);
1860
appendLines ($appl);
1862
print STDOUT "\n" if $verbose;
1864
if ($moc_class_headers) {
1865
appendLines ("$cleantarget-moc-classes:\n\t-rm -f $moc_class_headers\n");
1866
$target_adds{"$cleantarget-am"} .= "$cleantarget-moc-classes ";
1870
#-----------------------------------------------------------------------------
1872
sub updateMakefile ()
1874
return if ($dryrun);
1876
open (FILEOUT, "> $makefile")
1877
|| die "Could not create $makefile: $!\n";
1879
print FILEOUT "\# $progId - " . '$Revision: 2 $ ' . "\n";
1880
$MakefileData =~ s/\034/\\\n/g; # Restore continuation lines
1881
print FILEOUT $MakefileData;
1885
#-----------------------------------------------------------------------------
1887
# The given line needs to be removed from the makefile
1888
# Do this by adding the special "removed line" comment at the line start.
1891
my ($lookup, $old) = @_;
1893
$old =~ s/\034/\\\n#>- /g; # Fix continuation lines
1894
$MakefileData =~ s/\n$lookup/\n#>\- $old/;
1897
#-----------------------------------------------------------------------------
1899
# Replaces the old line with the new line
1900
# old line(s) are retained but tagged as removed. The new line(s) have the
1901
# "added" tag placed before it.
1902
sub substituteLine ($$)
1904
my ($lookup, $new) = @_;
1906
if ($MakefileData =~ /\n($lookup)/) {
1908
$old =~ s/\034/\\\n#>\- /g; # Fix continuation lines
1909
$new =~ s/\034/\\\n/g;
1910
my $newCount = ($new =~ tr/\n//) + 1;
1911
$MakefileData =~ s/\n$lookup/\n#>- $old\n#>\+ $newCount\n$new/;
1913
print STDERR "Warning: substitution of \"$lookup\" in $printname failed\n";
1917
#-----------------------------------------------------------------------------
1919
# Slap new lines on the back of the file.
1923
$new =~ s/\034/\\\n/g; # Fix continuation lines
1924
my $newCount = ($new =~ tr/\n//) + 1;
1925
$MakefileData .= "\n#>\+ $newCount\n$new";
1928
#-----------------------------------------------------------------------------
1930
# Restore the Makefile.in to the state it was before we fiddled with it
1931
sub restoreMakefile ()
1933
$MakefileData =~ s/# $progId[^\n\034]*[\n\034]*//g;
1934
# Restore removed lines
1935
$MakefileData =~ s/([\n\034])#>\- /$1/g;
1936
# Remove added lines
1937
while ($MakefileData =~ /[\n\034]#>\+ ([^\n\034]*)/)
1940
my $removeLines = "";
1941
while ($newCount--) {
1942
$removeLines .= "[^\n\034]*([\n\034]|)";
1944
$MakefileData =~ s/[\n\034]#>\+.*[\n\034]$removeLines/\n/;
1948
#-----------------------------------------------------------------------------