3
# Expands the specilised 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 <garbanzo@hooked.net>
32
# David Faure <faure@kde.org>
33
# Stephan Kulow <coolo@kde.org>
35
# I've puddled around with automoc and produced something different
36
# 1999-02-01 John Birch <jb.nz@writeme.com>
37
# * Rewritten automoc to cater for more than just moc file expansion
38
# Version 0.01 does the same as automoc at this stage.
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();
84
# Some global globals...
85
$verbose = 0; # a debug flag
86
$thisProg = "$0"; # This programs name
87
$topdir = cwd(); # The current directory
88
@makefiles = (); # Contains all the files we'll process
90
$start = (times)[0]; # some stats for testing - comment out for release
93
$cppExt = "*.cpp *.cc *.cxx *.C *.c++"; # used by grep
94
$hExt = "*.h *.H *.hh *.hxx *.h++"; # used by grep
95
$progId = "KDE tags expanded automatically by " . basename($thisProg);
97
$printname = ""; # used to display the directory the Makefile is in
98
$use_final = 1; # create code for --enable-final
99
$cleantarget = "clean";
103
while (defined ($ARGV[0]))
109
print STDOUT basename($thisProg), " $version\n",
110
"This is really free software, unencumbered by the GPL.\n",
111
"You can do anything you like with it except sueing me.\n",
112
"Copyright 1998 Kalle Dalheimer <kalle\@kde.org>\n",
113
"Concept, design and unnecessary questions about perl\n",
114
" by Matthias Ettrich <ettrich\@kde.org>\n\n",
115
"Making it useful by Stephan Kulow <coolo\@kde.org> and\n",
116
"Harri Porten <porten\@kde.org>\n",
117
"Updated (Feb-1999), John Birch <jb.nz\@writeme.com>\n",
118
"Current Maintainer Stephan Kulow\n\n";
121
elsif (/^--verbose$|^-v$/)
123
$verbose = 1; # Oh is there a problem...?
125
elsif (/^-p(.+)$|^--path=(.+)$/)
127
$thisProg = "$1/".basename($thisProg) if($1);
128
$thisProg = "$2/".basename($thisProg) if($2);
129
warn ("$thisProg doesn't exist\n") if (!(-f $thisProg));
132
elsif (/^--help$|^-h$/)
134
print STDOUT "Usage $thisProg [OPTION] ... [dir/Makefile.in]...\n",
136
"Patches dir/Makefile.in generated from automake\n",
137
"(where dir can be a full or relative directory name)",
139
" -v, --verbose verbosely list files processed\n",
140
" -h, --help print this help, then exit\n",
141
" --version print version number, then exit\n",
142
" -p, --path= use the path to am_edit if the path\n",
143
" --no-final don't patch for --enable-final\n",
144
" called from is not the one to be used\n";
148
elsif (/^--no-final$/)
151
$thisProg .= " --no-final";
159
# user selects what input files to check
160
# add full path if relative path is given
161
$_ = cwd()."/".$_ if (! /^\//);
162
print "User wants $_\n" if ($verbose);
163
push (@makefiles, $_);
167
if ($thisProg =~ /^\// && !$pathoption )
169
print STDERR "Illegal full pathname call performed...\n",
170
"The call to \"$thisProg\"\nwould be inserted in some Makefile.in.\n",
171
"Please use option --path.\n";
175
# Only scan for files when the user hasn't entered data
178
print STDOUT "Scanning for Makefile.in\n" if ($verbose);
179
find (\&add_makefile, cwd());
182
print STDOUT "Using user enter input files\n" if ($verbose);
185
foreach $makefile (sort(@makefiles))
187
processMakefile ($makefile);
188
last if ($errorflag);
191
# Just some debug statistics - comment out for release as it uses printf.
192
printf STDOUT "Time %.2f CPU sec\n", (times)[0] - $start if ($verbose);
194
exit $errorflag; # causes make to fail if erroflag is set
196
#-----------------------------------------------------------------------------
198
# In conjunction with the "find" call, this builds the list of input files
201
push (@makefiles, $File::Find::name) if (/Makefile.in$/);
204
#-----------------------------------------------------------------------------
206
# Processes a single make file
207
# The parameter contains the full path name of the Makefile.in to use
208
sub processMakefile ($)
210
# some useful globals for the subroutines called here
211
local ($makefile) = @_;
212
local @headerdirs = ('.');
213
local $haveAutomocTag = 0;
214
local $MakefileData = "";
216
local $cxxsuffix = "KKK";
218
local @programs = (); # lists the names of programs and libraries
221
local %realObjs = (); # lists the objects compiled into $program
222
local %sources = (); # lists the sources used for $program
223
local %finalObjs = (); # lists the objects compiled when final
224
local %realname = (); # the binary name of program variable
225
local %idlfiles = (); # lists the idl files used for $program
226
local %globalmocs = ();# list of all mocfiles (in %mocFiles format)
227
local %important = (); # list of files to be generated asap
231
local $idl_output = "";# lists all idl generated files for cleantarget
232
local $ui_output = "";# lists all uic generated files for cleantarget
233
local $ui_mocs = "";# lists all moc files associated with generated uic files
235
local %depedmocs = ();
237
local $metasourceTags = 0;
238
local $dep_files = "";
239
local $dep_finals = "";
240
local %target_adds = (); # the targets to add
242
local @cleanfiles = ();
243
local $cleanMoc = "";
244
local $closure_output = "";
246
$makefileDir = dirname($makefile);
247
chdir ($makefileDir);
248
$printname = $makefile;
249
$printname =~ s/^\Q$topdir\E\///;
250
$makefile = basename($makefile);
252
print STDOUT "Processing makefile $printname\n" if ($verbose);
254
# Setup and see if we need to do this.
255
return if (!initialise());
257
tag_AUTOMAKE (); # Allows a "make" to redo the Makefile.in
258
tag_META_INCLUDES (); # Supplies directories for src locations
260
foreach $program (@programs) {
261
$sources_changed{$program} = 0;
262
$depedmocs{$program} = "";
263
$important{$program} = "";
264
tag_IDLFILES(); # Sorts out idl rules
265
tag_UIFILES(); # Sorts out ui rules
267
tag_METASOURCES (); # Sorts out the moc rules
268
if ($sources_changed{$program}) {
269
my $lookup = "$program" . '_SOURCES\s*=\s*(.*)';
270
substituteLine($lookup, "$program\_SOURCES=" . $sources{$program});
272
if ($important{$program}) {
273
local %source_dict = ();
274
for $source (split(/[\034\s]+/, $sources{$program})) {
275
$source_dict{$source} = 1;
277
for $source (@cleanfiles) {
278
$source_dict{$source} = 0;
280
for $source (keys %source_dict) {
282
if ($source_dict{$source}) {
285
print STDERR "Error: $source is listed in a _SOURCE line in $printname, but doesn't exist yet. Put it in DISTCLEANFILES!\n";
287
$target_adds{"\$(srcdir)/$source"} .= $important{$program};
294
# Always add dist clean tag
295
# Add extra *.moc.cpp files created for USE_AUTOMOC because they
296
# aren't included in the normal *.moc clean rules.
297
appendLines ("$cleantarget-metasources:\n\t-rm -f $cleanMoc\n");
298
$target_adds{"$cleantarget-am"} .= "$cleantarget-metasources ";
303
appendLines ("$cleantarget-idl:\n\t-rm -f $idl_output\n");
304
$target_adds{"$cleantarget-am"} .= "$cleantarget-idl ";
308
appendLines ("$cleantarget-ui:\n\t-rm -f $ui_output\n");
309
$target_adds{"$cleantarget-am"} .= "$cleantarget-ui ";
312
if ($closure_output) {
313
appendLines ("$cleantarget-closures:\n\t-rm -f $closure_output\n");
314
$target_adds{"$cleantarget-am"} .= "$cleantarget-closures ";
317
if ($MakefileData =~ /\nKDE_LANG\s*=\s*(\S*)\s*\n/) {
318
$kdelang = '$(KDE_LANG)'
323
tag_POFILES (); # language rules for po directory
324
tag_DOCFILES (); # language rules for doc directories
325
tag_TOPLEVEL (); # language rules for po toplevel
326
tag_LOCALINSTALL(); # add $(DESTDIR) before all kde_ dirs
329
my $tmp = "force-reedit:\n";
330
$tmp .= "\t$automkCall\n\tcd \$(top_srcdir) && perl $thisProg $printname\n\n";
334
tag_FINAL() if (!$kdeopts{"nofinal"});
336
my $final_lines = "final:\n\t\$(MAKE) ";
337
my $nofinal_lines = "no-final:\n\t\$(MAKE) ";
339
foreach $program (@programs) {
341
my $lookup = "$program\_OBJECTS.*=[^\n]*";
345
my @list = split(/[\034\s]+/, $realObjs{$program});
347
if (!$kdeopts{"nofinal"} && @list > 1 && $finalObjs{$program}) {
349
$new .= "$program\_final\_OBJECTS = " . $finalObjs{$program};
350
$new .= "\n$program\_nofinal\_OBJECTS = " . $realObjs{$program};
351
$new .= "\n\@KDE_USE_FINAL_FALSE\@$program\_OBJECTS = \$($program\_nofinal\_OBJECTS)";
352
$new .= "\n\@KDE_USE_FINAL_TRUE\@$program\_OBJECTS = \$($program\_final\_OBJECTS)";
354
$final_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" ";
355
$nofinal_lines .= "$program\_OBJECTS=\"\$($program\_nofinal\_OBJECTS)\" ";
357
$new = "$program\_OBJECTS = " . $realObjs{$program};
359
substituteLine ($lookup, $new);
361
appendLines($final_lines . "all-am");
362
appendLines($nofinal_lines . "all-am");
364
my $lookup = 'DEP_FILES\s*=([^\n]*)';
365
if ($MakefileData =~ /\n$lookup\n/) {
369
$lines = "\@KDE_USE_FINAL_TRUE\@DEP_FILES = $dep_files $dep_finals \034\t$depfiles\n";
370
$lines .= "\@KDE_USE_FINAL_FALSE\@DEP_FILES = $dep_files $depfiles\n";
372
$lines = "DEP_FILES = $dep_files $depfiles\n";
375
substituteLine($lookup, $lines);
378
my $cvs_lines = "cvs-clean:\n";
379
$cvs_lines .= "\t\$(MAKE) -f \$(top_srcdir)/admin/Makefile.common cvs-clean\n";
380
appendLines($cvs_lines);
382
$cvs_lines = "kde-rpo-clean:\n";
383
$cvs_lines .= "\t-rm -f *.rpo\n";
384
appendLines($cvs_lines);
385
$target_adds{"clean"} .= "kde-rpo-clean ";
389
foreach $add (keys %target_adds) {
390
my $lookup = quotemeta($add) . ":\s*(.*)";
391
if ($MakefileData =~ /\n$lookup\n/) {
392
substituteLine($lookup, "$add: " . $target_adds{$add} . $1);
394
$lines .= "$add: " . $target_adds{$add} . "\n";
404
if ($MakefileData =~ m/\n(.*)\$\(CXXFLAGS\)(.*)\n/) {
407
my $lookup = quotemeta("$1\$(CXXFLAGS)$2");
408
my $replacement = "$1\$(KCXXFLAGS)$2";
409
$MakefileData =~ s/$lookup/$replacement/;
410
$lookup =~ s/\\\$\\\(CXXFLAGS\\\)/\\\$\\\(KCXXFLAGS\\\)/;
411
$replacement = "$vor\$(KCXXFLAGS) \$(KDE_CXXFLAGS)$nach";
412
substituteLine($lookup, $replacement);
418
$lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=link) (\$\(CXXLD\).*\$\(KCXXFLAGS\))';
420
if ($MakefileData =~ m/$lookup/ ) {
421
$MakefileData =~ s/$lookup/$1 --tag=CXX $2/;
424
$lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=compile) (\$\(CXX\).*\$\(KCXXFLAGS\))';
425
if ($MakefileData =~ m/$lookup/ ) {
426
$MakefileData =~ s/$lookup/$1 --tag=CXX $2/;
429
$MakefileData =~ s/\$\(KCXXFLAGS\)/\$\(CXXFLAGS\)/g;
431
$lookup = '(.*)cp -pr \$\$/\$\$file \$\(distdir\)/\$\$file(.*)';
432
if ($MakefileData =~ m/$lookup/) {
433
substituteLine($lookup, "$1cp -pr \$\$d/\$\$file \$(distdir)/\$\$file$2");
436
# Always update the Makefile.in
441
#-----------------------------------------------------------------------------
443
# Check to see whether we should process this make file.
444
# This is where we look for tags that we need to process.
445
# A small amount of initialising on the tags is also done here.
446
# And of course we open and/or create the needed make files.
449
if (! -r "Makefile.am") {
450
print STDOUT "found Makefile.in without Makefile.am\n" if ($verbose);
454
# Checking for files to process...
455
open (FILEIN, $makefile)
456
|| die "Could not open $makefileDir/$makefile: $!\n";
462
die "DOS-Linefeeds within $makefileDir/$makefile!\n";
467
# Remove the line continuations, but keep them marked
468
# Note: we lose the trailing spaces but that's ok.
469
$MakefileData =~ s/\\\s*\n/\034/g;
471
# If we've processed the file before...
472
restoreMakefile () if ($MakefileData =~ /$progId/);
474
foreach $dir (@foreignfiles) {
475
if (substr($makefileDir,0,length($dir)) eq $dir) {
481
$kdeopts{"foreign"} = 0;
482
$kdeopts{"qtonly"} = 0;
483
$kdeopts{"nofinal"} = !$use_final; # default
485
if ($MakefileData =~ /\nKDE_OPTIONS\s*=\s*([^\n]*)\n/) {
486
local @kde_options = split(/[\s\034]/, $1);
487
if (grep(/^foreign$/, @kde_options)) {
488
push(@foreignfiles, $makefileDir . "/");
489
return 0; # don't touch me
491
for $opt (@kde_options) {
492
if (!defined $kdeopts{$opt}) {
493
print STDERR "Warning: unknown option $opt in $printname\n";
500
# Look for the tags that mean we should process this file.
502
$metasourceTags++ while ($MakefileData =~ /\n[^=\#]*METASOURCES\s*=/g);
505
$pofileTag++ while ($MakefileData =~ /\nPOFILES\s*=/g);
508
print STDERR "Error: Only one POFILES tag allowed\n";
512
while ($MakefileData =~ /\n\.SUFFIXES:([^\n]+)\n/g) {
513
my @list=split(' ', $1);
514
my $extions = " " . $cppExt . " ";
515
foreach $ext (@list) {
516
if ($extions =~ / \*\Q$ext\E /) {
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
print STDOUT "found program $program\n" if ($verbose);
547
push(@programs, $program);
549
$realObjs{$program} = $objs;
551
if ($MakefileData =~ /\n$program\_SOURCES\s*=\s*(.*)\n/) {
552
$sources{$program} = $1;
554
$sources{$program} = "";
555
print STDERR "found program with no _SOURCES: $program\n";
558
my $realprogram = $program;
559
$realprogram =~ s/_/./g; # unmask to regexp
560
if ($MakefileData =~ /\n($realprogram)(\$\(EXEEXT\)?)?:.*\$\($program\_OBJECTS\)/) {
561
$realname{$program} = $1;
563
# not standard Makefile - nothing to worry about
564
$realname{$program} = "";
568
my $lookup = '\nDEPDIR\s*=.*';
569
if ($MakefileData !~ /($lookup)\n/) {
570
$lookup = '\nbindir\s*=.*';
571
if ($MakefileData =~ /($lookup)\n/) {
572
substituteLine ($lookup, "DEPDIR = .deps\n$1");
575
print STDERR "$printname defines DEPDIR. This means you're using automake > 1.4 - this is not supported!\n";
578
my @marks = ('MAINTAINERCLEANFILES', 'CLEANFILES', 'DISTCLEANFILES');
579
foreach $mark (@marks) {
580
while ($MakefileData =~ /\n($mark)\s*=\s*([^\n]*)/g) {
581
foreach $file (split('[\034\s]', $2)) {
583
push(@cleanfiles, $file);
589
$localTag++ if ($MakefileData =~ /\ninstall-\S+-local:/);
591
return (!$errorflag);
594
#-----------------------------------------------------------------------------
596
# Gets the list of user defined directories - relative to $srcdir - where
597
# header files could be located.
598
sub tag_META_INCLUDES ()
600
my $lookup = '[^=\n]*META_INCLUDES\s*=\s*(.*)';
601
return 1 if ($MakefileData !~ /($lookup)\n/);
602
print STDOUT "META_INCLUDE processing <$1>\n" if ($verbose);
605
removeLine ($lookup, $1);
607
$headerStr =~ tr/\034/ /;
608
my @headerlist = split(' ', $headerStr);
610
foreach $dir (@headerlist)
612
$dir =~ s#\$\(srcdir\)#.#;
615
print STDERR "Warning: $dir can't be found. ",
616
"Must be a relative path to \$(srcdir)\n";
620
push (@headerdirs, $dir);
627
#-----------------------------------------------------------------------------
631
my @final_names = ();
633
foreach $program (@programs) {
635
if ($sources{$program} =~ /\(/) {
636
print STDOUT "found ( in $program\_SOURCES. skipping\n" if ($verbose);
642
my @progsources = split(/[\s\034]+/, $sources{$program});
645
foreach $source (@progsources) {
646
my $suffix = $source;
647
$suffix =~ s/^.*\.([^\.]+)$/$1/;
649
if (defined($sourcelist{$suffix})) {
650
$sourcelist{$suffix} .= " " . $source;
652
$sourcelist{$suffix} .= $source;
656
foreach $suffix (keys %sourcelist) {
658
# See if this file contains c++ code. (ie Just check the files suffix against
659
my $suffix_is_cxx = 0;
660
foreach $cxx_suffix (split(' ', $cppExt)) {
661
$cxx_suffix =~ s/^\*\.//;
662
$cxx_suffix = quotemeta($cxx_suffix);
663
if ($suffix =~ $cxx_suffix) {
669
my $mocfiles_in = ($suffix eq $cxxsuffix) &&
670
defined($depedmocs{$program});
672
my @sourcelist = split(/[\s\034]+/, $sourcelist{$suffix});
674
if ((@sourcelist == 1 && !$mocfiles_in) || $suffix_is_cxx != 1 ) {
676
# we support IDL on our own
677
if ($suffix =~ /^skel$/ || $suffix =~ /^stub/ || $suffix =~ /^h$/
678
|| $suffix =~ /^ui$/ ) {
682
foreach $file (@sourcelist) {
684
$file =~ s/\Q$suffix\E$//;
686
$finalObjs{$program} .= $file;
687
if ($program =~ /_la$/) {
688
$finalObjs{$program} .= "lo ";
690
$finalObjs{$program} .= "o ";
696
my $source_deps = "";
697
foreach $source (@sourcelist) {
699
$source_deps .= "\$(srcdir)/$source ";
701
$source_deps .= "$source ";
705
$handling = "$program.all_$suffix.$suffix: \$(srcdir)/Makefile.in " . $source_deps . " ";
708
$handling .= $depedmocs{$program};
709
foreach $mocfile (split(' ', $depedmocs{$program})) {
710
if ($mocfile =~ m/\.$suffix$/) {
711
$mocsources .= " " . $mocfile;
717
$handling .= "\t\@echo 'creating $program.all_$suffix.$suffix ...'; \\\n";
718
$handling .= "\trm -f $program.all_$suffix.files $program.all_$suffix.final; \\\n";
719
$handling .= "\techo \"#define KDE_USE_FINAL 1\" >> $program.all_$suffix.final; \\\n";
720
$handling .= "\tfor file in " . $sourcelist{$suffix} . " $mocsources; do \\\n";
721
$handling .= "\t echo \"#include \\\"\$\$file\\\"\" >> $program.all_$suffix.files; \\\n";
722
$handling .= "\t test ! -f \$\(srcdir\)/\$\$file || egrep '^#pragma +implementation' \$\(srcdir\)/\$\$file >> $program.all_$suffix.final; \\\n";
723
$handling .= "\tdone; \\\n";
724
$handling .= "\tcat $program.all_$suffix.final $program.all_$suffix.files > $program.all_$suffix.$suffix; \\\n";
725
$handling .= "\trm -f $program.all_$suffix.final $program.all_$suffix.files\n";
727
appendLines($handling);
729
push(@final_names, "$program.all_$suffix.$suffix");
730
$finalObjs{$program} .= "$program.all_$suffix.";
731
if ($program =~ /_la$/) {
732
$finalObjs{$program} .= "lo ";
734
$finalObjs{$program} .= "o ";
739
if (!$kdeopts{"nofinal"} && @final_names >= 1) {
740
# add clean-final target
741
my $lines = "$cleantarget-final:\n";
742
$lines .= "\t-rm -f " . join(' ', @final_names) . "\n" if (@final_names);
744
$target_adds{"$cleantarget-am"} .= "$cleantarget-final ";
746
foreach $finalfile (@final_names) {
747
$finalfile =~ s/\.[^.]*$/.P/;
748
$dep_finals .= " \$(DEPDIR)/$finalfile";
753
# Organises the list of headers that we'll use to produce moc files
755
sub tag_METASOURCES ()
757
local @newObs = (); # here we add to create object files
758
local @deped = (); # here we add to create moc files
759
local $mocExt = ".moc";
760
local %mocFiles = ();
768
if ($metasourceTags > 1) {
769
$lookup = $program . '_METASOURCES\s*=\s*(.*)';
770
return 1 if ($MakefileData !~ /\n($lookup)\n/);
773
$lookup = $program . '_METASOURCES\s*=\s*(.*)';
774
if ($MakefileData !~ /\n($lookup)\n/) {
775
$lookup = 'METASOURCES\s*=\s*(.*)';
776
return 1 if ($MakefileData !~ /\n($lookup)\n/);
778
$metasourceTags = 0; # we can use the general target only once
783
print STDOUT "METASOURCE processing <$found>)\n" if ($verbose);
786
$postEqual =~ s/[^=]*=//;
788
removeLine ($lookup, $found);
790
# Always find the header files that could be used to "moc"
791
return 1 if (findMocCandidates ());
793
if ($postEqual =~ /AUTO\s*(\S*)|USE_AUTOMOC\s*(\S*)/)
795
print STDERR "$printname: the argument for AUTO|USE_AUTOMOC is obsolete" if ($+);
796
$mocExt = ".moc.$cxxsuffix";
801
# Not automoc so read the list of files supplied which
802
# should be .moc files.
804
$postEqual =~ tr/\034/ /;
806
# prune out extra headers - This also checks to make sure that
808
pruneMocCandidates ($postEqual);
811
checkMocCandidates ();
814
my $ext = ($program =~ /_la$/) ? ".moc.lo " : ".moc.o ";
815
$realObjs{$program} .= "\034" . join ($ext, @newObs) . $ext;
816
$depedmocs{$program} = join (".moc.$cxxsuffix " , @newObs) . ".moc.$cxxsuffix";
817
foreach $file (@newObs) {
818
$dep_files .= " \$(DEPDIR)/$file.moc.P";
822
$depedmocs{$program} .= " ";
823
$depedmocs{$program} .= join('.moc ', @deped) . ".moc";
824
$depedmocs{$program} .= " ";
827
@globalmocs{keys %mocFiles}=values %mocFiles;
830
#-----------------------------------------------------------------------------
832
# Returns 0 if the line was processed - 1 otherwise.
833
# Errors are logged in the global $errorflags
836
my $lookup = '.*cd \$\(top_srcdir\)\s+&&\s+\$\(AUTOMAKE\)(.*)';
837
return 1 if ($MakefileData !~ /($lookup)/);
838
print STDOUT "AUTOMAKE processing <$1>\n" if ($verbose);
840
my $newLine = $1."\n\tcd \$(top_srcdir) && perl $thisProg $printname";
841
substituteLine ($lookup, $newLine);
846
#-----------------------------------------------------------------------------
850
my $lookup = 'TOPLEVEL_LANG\s*=\s*(\S+)';
851
return 1 if ($MakefileData !~ /\n$lookup\n/);
855
print STDERR "Error: TOPLEVEL_LANG without SUBDIRS = \$(AUTODIRS) in $printname\n";
862
opendir (THISDIR, ".");
863
foreach $entry (readdir(THISDIR)) {
866
next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/ || $entry =~ /.gmo$/);
868
if ($entry =~ /\.po$/) {
869
$pofiles .= "$entry ";
872
push(@restfiles, $entry);
876
print STDOUT "pofiles found = $pofiles\n" if ($verbose);
877
handle_POFILES($pofiles, '$(TOPLEVEL_LANG)') if ($pofiles);
880
$target_adds{"install-data-am"} .= "install-nls-files ";
881
$lines = "install-nls-files:\n";
882
$lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$lang\n";
883
for $file (@restfiles) {
884
$lines .= "\t\$(INSTALL_DATA) \$\(srcdir\)/$file \$(DESTDIR)\$(kde_locale)/$lang/$file\n";
892
#-----------------------------------------------------------------------------
896
if ($MakefileData !~ /\nSUBDIRS\s*=\s*\$\(AUTODIRS\)\s*\n/) {
902
opendir (THISDIR, ".");
903
foreach $entry (readdir(THISDIR)) {
904
next if ($entry eq "CVS" || $entry =~ /^\./);
905
if (-d $entry && -f $entry . "/Makefile.am") {
906
$subdirs .= " $entry";
912
my $lines = "SUBDIRS =$subdirs\n";
913
substituteLine('SUBDIRS\s*=.*', $lines);
919
my @psources = split(/[\034\s]+/, $sources{$program});
923
foreach $source (@psources) {
925
my $skel = ($source =~ m/\.skel$/);
927
if ($source =~ m/\.stub$/ || $skel) {
929
my $qs = quotemeta($source);
930
$sources{$program} =~ s/$qs//;
931
$sources_changed{$program} = 1;
933
print STDOUT "adding IDL file $source\n" if ($verbose);
935
$source =~ s/\.(stub|skel)$//;
940
$sourcename = "$source\_skel";
942
$sourcename = "$source\_stub";
946
if (-f "$makefileDir/$source.h") {
947
$sourcedir = '$(srcdir)/';
949
if ($MakefileData =~ /\n$source\_DIR\s*=\s*(\S+)\n/) {
951
$sourcedir .= "/" if ($sourcedir !~ /\/$/);
955
if ($allidls !~ /$source\_kidl/) {
957
$dep_lines .= "$source.kidl: $sourcedir$source.h \$(DCOPIDL_DEPENDENCIES)\n";
958
$dep_lines .= "\t\$(DCOPIDL) $sourcedir$source.h > $source.kidl || ( rm -f $source.kidl ; /bin/false )\n";
960
$allidls .= $source . "_kidl ";
963
if ($allidls !~ /$sourcename/) {
966
$dep_lines .= "$sourcename.$cxxsuffix: $source.kidl\n";
967
$dep_lines .= "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-stub $source.kidl\n";
969
$target_adds{"$sourcename.$cxxsuffix"} .= "$sourcename.h ";
970
$dep_lines .= "$sourcename.h: $source.kidl\n";
971
$dep_lines .= "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-skel $source.kidl\n";
974
$allidls .= $sourcename . " ";
977
$idlfiles{$program} .= $sourcename . " ";
979
if ($program =~ /_la$/) {
980
$realObjs{$program} .= " $sourcename.lo";
982
$realObjs{$program} .= " $sourcename.\$(OBJEXT)";
984
$sources{$program} .= " $sourcename.$cxxsuffix";
985
$sources_changed{$program} = 1;
986
$important{$program} .= "$sourcename.h " if (!$skel);
987
$idl_output .= "\\\n\t$sourcename.$cxxsuffix $sourcename.h $source.kidl ";
988
push(@cleanfiles, "$sourcename.$cxxsuffix");
989
push(@cleanfiles, "$sourcename.h");
990
push(@cleanfiles, "$sourcename.kidl");
991
$dep_files .= " \$(DEPDIR)/$sourcename.P";
995
appendLines($dep_lines);
999
my $lookup = "($program)";
1000
$lookup .= '(|\$\(EXEEXT\))';
1001
$lookup =~ s/\_/./g;
1002
$lookup .= ":(.*..$program\_OBJECTS..*)";
1003
# $lookup = quotemeta($lookup);
1004
if ($MakefileData =~ /\n$lookup\n/) {
1006
my $line = "$1$2: ";
1007
foreach $file (split(' ', $idlfiles{$program})) {
1008
$line .= "$file.$cxxsuffix ";
1011
substituteLine($lookup, $line);
1013
print STDERR "no built dependency found $lookup\n";
1020
my @psources = split(/[\034\s]+/, $sources{$program});
1024
foreach $source (@psources) {
1026
if ($source =~ m/\.ui$/) {
1028
print STDERR "adding UI file $source\n" if ($verbose);
1030
my $qs = quotemeta($source);
1031
$sources{$program} =~ s/$qs//;
1032
$sources_changed{$program} = 1;
1034
$source =~ s/\.ui$//;
1037
if (-f "$makefileDir/$source.ui") {
1038
$sourcedir = '$(srcdir)/';
1041
if ($alluis !~ /$source/) {
1043
$dep_lines .= "$source.$cxxsuffix: $sourcedir$source.ui $source.h $source.moc\n";
1044
$dep_lines .= "\trm -f $source.$cxxsuffix\n";
1045
if (!$kdeopts{"qtonly"}) {
1046
$dep_lines .= "\techo '#include <klocale.h>' > $source.$cxxsuffix\n";
1047
$dep_lines .= "\t\$(UIC) -tr i18n -i $source.h $sourcedir$source.ui | sed -e \"s,i18n( \\\"\\\" ),QString::null,g\" >> $source.$cxxsuffix || rm -f $source.$cxxsuffix\n";
1049
$dep_lines .= "\t\$(UIC) -i $source.h $sourcedir$source.ui > $source.$cxxsuffix || rm -f $source.$cxxsuffix\n";
1051
$dep_lines .= "\techo '#include \"$source.moc\"' >> $source.$cxxsuffix\n\n";
1052
$dep_lines .= "$source.h: $sourcedir$source.ui\n";
1053
$dep_lines .= "\t\$(UIC) -o $source.h $sourcedir$source.ui\n\n";
1054
$dep_lines .= "$source.moc: $source.h\n";
1055
$dep_lines .= "\t\$(MOC) $source.h -o $source.moc\n";
1057
$alluis .= "$source ";
1058
$ui_mocs .= " $source.moc";
1059
$depedmocs{$program} .= " $source.moc";
1062
if ($program =~ /_la$/) {
1063
$realObjs{$program} .= " $source.lo";
1065
$realObjs{$program} .= " $source.\$(OBJEXT)";
1067
$sources{$program} .= " $source.$cxxsuffix";
1068
$sources_changed{$program} = 1;
1069
$important{$program} .= "$source.h ";
1070
$ui_output .= "\\\n\t$source.$cxxsuffix $source.h $source.moc ";
1071
push(@cleanfiles, "$source.$cxxsuffix");
1072
push(@cleanfiles, "source.h");
1073
push(@cleanfiles, "$source.moc");
1075
$dep_files .= " \$(DEPDIR)/$source.P";
1079
appendLines($dep_lines);
1085
my $lookup = '([^\s]*)_ICON\s*=\s*([^\n]*)';
1089
while ($MakefileData =~ /\n$lookup/g) {
1092
$destdir = "kde_icondir";
1094
$destdir = $1 . "dir";
1096
my $iconauto = ($2 =~ /AUTO\s*$/);
1098
if ( ! $iconauto ) {
1099
my @_appnames = split(" ", $2);
1100
print STDOUT "KDE_ICON processing <@_appnames>\n" if ($verbose);
1101
foreach $appname (@_appnames) {
1102
push(@appnames, quotemeta($appname));
1105
print STDOUT "KDE_ICON processing <AUTO>\n" if ($verbose);
1109
opendir (THISDIR, ".");
1110
foreach $entry (readdir(THISDIR)) {
1111
next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
1112
next if (! -f $entry);
1115
push(@files, $entry)
1116
if ($entry =~ /\.xpm/ || $entry =~ /\.png/);
1118
foreach $appname (@appnames) {
1119
push(@files, $entry)
1120
if ($entry =~ /-$appname\.xpm/ || $entry =~ /-$appname\.png/);
1126
my %directories = ();
1128
foreach $file (@files) {
1129
my $newfile = $file;
1131
$prefix =~ s/\.(png|xpm)$//;
1132
my $appname = $prefix;
1133
$appname =~ s/^[^-]+-// if ($appname =~ /-/) ;
1134
$appname =~ s/^[^-]+-// if ($appname =~ /-/) ;
1135
$appname = quotemeta($appname);
1136
$prefix =~ s/$appname$//;
1139
$prefix = 'lo16-app' if ($prefix eq 'mini');
1140
$prefix = 'lo32-app' if ($prefix eq 'lo');
1141
$prefix = 'hi48-app' if ($prefix eq 'large');
1142
$prefix .= '-app' if ($prefix =~ m/^...$/);
1145
$type =~ s/^.*-([^-]+)$/$1/;
1146
$prefix =~ s/^(.*)-[^-]+$/$1/;
1150
'action' => 'actions',
1152
'device' => 'devices',
1153
'filesys' => 'filesystems',
1154
'mime' => 'mimetypes'
1157
if (! defined $type_hash{$type} ) {
1158
print STDERR "unknown icon type $type in $printname ($file)\n";
1164
'los' => 'locolor/16x16',
1165
'lom' => 'locolor/32x32',
1166
'him' => 'hicolor/32x32',
1167
'hil' => 'hicolor/48x48',
1168
'lo16' => 'locolor/16x16',
1169
'lo22' => 'locolor/22x22',
1170
'lo32' => 'locolor/32x32',
1171
'hi16' => 'hicolor/16x16',
1172
'hi22' => 'hicolor/22x22',
1173
'hi32' => 'hicolor/32x32',
1174
'hi48' => 'hicolor/48x48',
1175
'hisc' => 'hicolor/scalable'
1178
$newfile =~ s@.*-($appname\.(png|xpm?))@$1@;
1180
if (! defined $dir_hash{$prefix}) {
1181
print STDERR "unknown icon prefix $prefix in $printname\n";
1185
my $dir = $dir_hash{$prefix} . "/" . $type_hash{$type};
1186
if ($newfile =~ /-[^\.]/) {
1188
$tmp =~ s/^([^-]+)-.*$/$1/;
1189
$dir = $dir . "/" . $tmp;
1190
$newfile =~ s/^[^-]+-//;
1193
if (!defined $directories{$dir}) {
1194
$install .= "\t\$(mkinstalldirs) \$(DESTDIR)\$($destdir)/$dir\n";
1195
$directories{$dir} = 1;
1198
$install .= "\t\$(INSTALL_DATA) \$(srcdir)/$file \$(DESTDIR)\$($destdir)/$dir/$newfile\n";
1199
$uninstall .= "\t-rm -f \$(DESTDIR)\$($destdir)/$dir/$newfile\n";
1204
if (length($install)) {
1205
$target_adds{"install-data-am"} .= "install-kde-icons ";
1206
$target_adds{"uninstall-am"} .= "uninstall-kde-icons ";
1207
appendLines("install-kde-icons:\n" . $install . "\nuninstall-kde-icons:\n" . $uninstall);
1211
sub handle_POFILES($$)
1213
my @pofiles = split(" ", $_[0]);
1216
# Build rules for creating the gmo files
1218
my $allgmofiles = "";
1219
my $pofileLine = "POFILES =";
1220
foreach $pofile (@pofiles)
1222
$pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1223
$tmp .= "$1.gmo: $pofile\n";
1224
$tmp .= "\trm -f $1.gmo; \$(GMSGFMT) -o $1.gmo \$(srcdir)/$pofile\n";
1225
$tmp .= "\ttest ! -f $1.gmo || touch $1.gmo\n";
1226
$allgmofiles .= " $1.gmo";
1227
$pofileLine .= " $1.po";
1230
my $lookup = 'POFILES\s*=([^\n]*)';
1231
if ($MakefileData !~ /\n$lookup/) {
1232
appendLines("$pofileLine\nGMOFILES =$allgmofiles");
1234
substituteLine ($lookup, "$pofileLine\nGMOFILES =$allgmofiles");
1239
# Add the "clean" rule so that the maintainer-clean does something
1240
appendLines ("clean-nls:\n\t-rm -f $allgmofiles\n");
1242
$target_adds{"maintainer-clean"} .= "clean-nls ";
1244
$lookup = 'DISTFILES\s*=\s*(.*)';
1245
if ($MakefileData =~ /\n$lookup\n/) {
1246
$tmp = "DISTFILES = \$(GMOFILES) \$(POFILES) $1";
1247
substituteLine ($lookup, $tmp);
1251
$target_adds{"install-data-am"} .= "install-nls ";
1253
$tmp = "install-nls:\n";
1254
$tmp .= "install-nls:\n";
1256
$tmp .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES\n";
1258
$tmp .= "\t\@for base in ";
1259
foreach $pofile (@pofiles)
1261
$pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1265
$tmp .= "; do \\\n";
1267
$tmp .= "\t echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n";
1268
$tmp .= "\t test ! -f \$\$base.gmo || \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n"
1270
$tmp .= "\t echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
1271
$tmp .= "\t \$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES ; \\\n";
1272
$tmp .= "\t test ! -f \$\$base.gmo || \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n";
1274
$tmp .= "\tdone\n\n";
1277
$target_adds{"uninstall"} .= "uninstall-nls ";
1279
$tmp = "uninstall-nls:\n";
1280
foreach $pofile (@pofiles)
1282
$pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1284
$tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/$1.mo\n";
1286
$tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$1/LC_MESSAGES/\$(PACKAGE).mo\n";
1291
$target_adds{"all"} .= "all-nls ";
1293
$tmp = "all-nls: \$(GMOFILES)\n";
1297
$target_adds{"distdir"} .= "distdir-nls ";
1299
$tmp = "distdir-nls:\$(GMOFILES)\n";
1300
$tmp .= "\tfor file in \$(POFILES); do \\\n";
1301
$tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n";
1303
$tmp .= "\ttest -z \"\$(GMOFILES)\" || cp \$(GMOFILES) \$(distdir)\n";
1308
appendLines("merge:\n\t\$(MAKE) -f \$(top_srcdir)/admin/Makefile.common package-merge POFILES=\"\${POFILES}\" PACKAGE=\${PACKAGE}\n\n");
1313
#-----------------------------------------------------------------------------
1315
# Returns 0 if the line was processed - 1 otherwise.
1316
# Errors are logged in the global $errorflags
1319
my $lookup = 'POFILES\s*=([^\n]*)';
1320
return 1 if ($MakefileData !~ /\n$lookup/);
1321
print STDOUT "POFILES processing <$1>\n" if ($verbose);
1325
# make sure these are all gone.
1326
if ($MakefileData =~ /\n\.po\.gmo:\n/)
1328
print STDERR "Warning: Found old .po.gmo rules in $printname. New po rules not added\n";
1332
# Either find the pofiles in the directory (AUTO) or use
1333
# only the specified po files.
1335
if ($tmp =~ /^\s*AUTO\s*$/)
1337
opendir (THISDIR, ".");
1338
next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^#.*#$/);
1339
$pofiles = join(" ", grep(/\.po$/, readdir(THISDIR)));
1341
print STDOUT "pofiles found = $pofiles\n" if ($verbose);
1348
return 1 if (!$pofiles); # Nothing to do
1350
handle_POFILES($pofiles, $kdelang);
1355
sub helper_LOCALINSTALL($)
1357
my $lookup = "\n" . $_[0] . ":";
1358
if ($MakefileData =~ /($lookup)/) {
1360
my $install = $MakefileData;
1361
$install =~ s/\n/\035/g;
1362
$install =~ s/.*\035$_[0]:[^\035]*\035//;
1364
while (! $emptyline) {
1365
if ($install =~ /([^\035]*)\035(.*)/) {
1368
if ($line !~ /^\s*$/ && $line !~ /^(\@.*\@)*\t/) {
1371
replaceDestDir($line);
1381
sub tag_LOCALINSTALL ()
1383
helper_LOCALINSTALL('install-exec-local');
1384
helper_LOCALINSTALL('install-data-local');
1385
helper_LOCALINSTALL('uninstall-local');
1390
sub replaceDestDir($) {
1391
local $line = $_[0];
1393
if ( $line =~ /^\s*(\@.*\@)*\s*\$\(mkinstalldirs\)/
1394
|| $line =~ /^\s*(\@.*\@)*\s*\$\(INSTALL\S*\)/
1395
|| $line =~ /^\s*(\@.*\@)*\s*(-?rm.*) \S*$/)
1397
$line =~ s/^(.*) ([^\s]*)\s*$/$1 \$(DESTDIR)$2/ if ($line !~ /\$\(DESTDIR\)/);
1400
if ($line ne $_[0]) {
1401
$_[0] = quotemeta $_[0];
1402
substituteLine($_[0], $line);
1406
#---------------------------------------------------------------------------
1407
sub tag_CLOSURE () {
1408
return if ($program !~ /_la$/);
1410
my $lookup = quotemeta($realname{$program}) . ":.*?\n\t.*?\\((.*?)\\) .*\n";
1411
$MakefileData =~ m/$lookup/;
1412
return if ($1 !~ /CXXLINK/);
1414
if ($MakefileData !~ /\n$program\_LDFLAGS\s*=.*-no-undefined/ &&
1415
$MakefileData !~ /\n$program\_LDFLAGS\s*=.*KDE_PLUGIN/ ) {
1416
print STDERR "Report: $program contains undefined in $printname\n" if ($program =~ /^lib/ && $dryrun);
1419
my $closure = $realname{$program} . ".closure";
1420
my $lines = "$closure: \$($program\_OBJECTS) \$($program\_DEPENDENCIES)\n";
1421
$lines .= "\t\@echo \"int main() {return 0;}\" > $program\_closure.$cxxsuffix\n";
1422
$lines .= "\t\@\$\(LTCXXCOMPILE\) -c $program\_closure.$cxxsuffix\n";
1423
$lines .= "\t\@\$\(CXXLINK\) $program\_closure.lo \$($program\_LDFLAGS) \$($program\_OBJECTS) \$($program\_LIBADD) \$(LIBS)\n";
1424
$lines .= "\t\@rm -f $program\_closure.* $closure\n";
1425
$lines .= "\t\@echo \"timestamp\" > $closure\n";
1427
appendLines($lines);
1428
$lookup = $realname{$program} . ": (.*)";
1429
if ($MakefileData =~ /\n$lookup\n/) {
1430
$lines = "\@KDE_USE_CLOSURE_TRUE@". $realname{$program} . ": $closure $1";
1431
$lines .= "\n\@KDE_USE_CLOSURE_FALSE@" . $realname{$program} . ": $1";
1432
substituteLine($lookup, $lines);
1434
$closure_output .= " $closure";
1438
my %foundfiles = ();
1439
opendir (THISDIR, ".");
1440
foreach $entry (readdir(THISDIR)) {
1441
next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile$$/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
1442
next if (! -f $entry);
1443
next if ($entry =~ /\.moc/ || $entry =~ /\.lo$/ || $entry =~ /\.la$/ || $entry =~ /\.o/);
1444
$foundfiles{$entry} = 1;
1448
my @marks = ("EXTRA_DIST", "DIST_COMMON", '\S*_SOURCES', '\S*_HEADERS', 'MAINTAINERCLEANFILES', 'CLEANFILES', 'DISTCLEANFILES', '\S*_OBJECTS');
1449
foreach $mark (@marks) {
1450
while ($MakefileData =~ /\n($mark)\s*=\s*([^\n]*)/g) {
1451
foreach $file (split('[\034\s]', $2)) {
1453
$foundfiles{$file} = 0 if (defined $foundfiles{$file});
1457
my @files = ("Makefile", "config.cache", "config.log", "stamp-h",
1458
"stamp-h1", "stamp-h1", "config.h", "Makefile", "config.status", "config.h", "libtool");
1459
foreach $file (@files) {
1460
$foundfiles{$file} = 0 if (defined $foundfiles{$file});
1464
foreach $file (keys %foundfiles) {
1465
if ($foundfiles{$file} == 1) {
1466
$KDE_DIST .= "$file ";
1470
print "KDE_DIST $printname $KDE_DIST\n" if ($verbose);
1472
my $lookup = "DISTFILES *=(.*)";
1473
if ($MakefileData =~ /\n$lookup\n/) {
1474
substituteLine($lookup, "KDE_DIST=$KDE_DIST\n\nDISTFILES=$1 \$(KDE_DIST)\n");
1479
#-----------------------------------------------------------------------------
1480
# Returns 0 if the line was processed - 1 otherwise.
1481
# Errors are logged in the global $errorflags
1484
# if ($MakefileData =~ /\nSUBDIRS\s*=/) { # subdirs
1485
# $MakefileData =~ /\n(.*-recursive:\s*)\n/;
1486
# my $orig_rules = $1;
1487
# my $rules = $orig_rules;
1488
# $rules =~ s/:\s*$//;
1489
# substituteLine($orig_rules, "$rules docs-recursive:");
1490
# appendLines("docs: docs-recursive docs-am\n");
1492
# appendLines("docs: docs-am\n");
1494
$target_adds{"all"} .= "docs-am ";
1496
my $lookup = 'KDE_DOCS\s*=\s*([^\n]*)';
1497
goto nodocs if ($MakefileData !~ /\n$lookup/);
1498
print STDOUT "KDE_DOCS processing <$1>\n" if ($verbose);
1504
# Either find the files in the directory (AUTO) or use
1505
# only the specified po files.
1508
$appname =~ s/^(\S*)\s*.*$/$1/;
1509
if ($appname =~ /AUTO/) {
1510
$appname = basename($makefileDir);
1511
if ("$appname" eq "en") {
1512
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";
1519
opendir (THISDIR, ".");
1520
foreach $entry (readdir(THISDIR)) {
1521
next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/);
1522
next if (! -f $entry);
1523
$files .= "$entry ";
1526
print STDOUT "docfiles found = $files\n" if ($verbose);
1531
$tmp =~ s/^\S*\s*-\s*//;
1534
goto nodocs if (!$files); # Nothing to do
1536
if ($files =~ /(^| )index\.docbook($| )/) {
1539
my $lookup = 'KDB2HTML\s*=';
1540
#if ($MakefileData !~ /\n($lookup)/) {
1541
# $lines = "KDB2HTML = \$(SHELL) /\$(kde_bindir)/kdb2html\n";
1543
$lines .= "docs-am: HTML HTML/index.html\n";
1545
$lines .= "HTML:\n";
1546
$lines .= "\ttest -d HTML || mkdir HTML\n";
1548
$lines .= "HTML/index.html: HTML index.docbook\n";
1549
$lines .= "\t\@test -d HTML && rm -r HTML\n";
1550
$lines .= "\t\$(KDB2HTML) \$(srcdir)/index.docbook\n";
1552
$lines .= "install-docs:\n";
1553
$lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n";
1554
$lines .= "\t-\@filelist=\"\" ;\\\n";
1555
$lines .= "\tif test -d HTML; then \\\n";
1556
$lines .= "\t filelist=`(cd HTML && ls -1 * .anchors 2> /dev/null)`; \\\n";
1557
$lines .= "\t dir=HTML; \\\n";
1558
$lines .= "\telse if test -d \$(srcdir)/HTML; then \\\n";
1559
$lines .= "\t filelist=`(cd \$(srcdir)/HTML && ls -1 * .anchors 2> /dev/null)`; \\\n";
1560
$lines .= "\t dir=\"\$(srcdir)/HTML\" ;\\\n";
1561
$lines .= "\tfi ; fi ;\\\n";
1562
$lines .= "\tfor file in \$\$filelist; do if test -f \$\$dir/\$\$file; then \\\n";
1563
$lines .= "\techo \$(INSTALL_DATA) \$\$dir/\$\$file \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$file ;\\\n";
1564
$lines .= "\t\$(INSTALL_DATA) \$\$dir/\$\$file \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$file; \\\n";
1565
$lines .= "\tfi; done\n";
1566
$lines .= "\t-rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n";
1567
$lines .= "\t\$(LN_S) \$(kde_libs_htmldir)/$kdelang/common \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n";
1570
$lines .= "uninstall-docs:\n";
1571
$lines .= "\t-rm -rf \$(kde_htmldir)/$kdelang/$appname\n";
1573
$target_adds{"install-data-am"} .= "install-docs ";
1574
$target_adds{"uninstall"} .= "uninstall-docs ";
1575
appendLines ($lines);
1577
appendLines("docs-am:\n");
1580
$target_adds{"install-data-am"} .= "install-nls";
1581
$target_adds{"uninstall"} .= "uninstall-nls ";
1583
$tmp = "install-nls:\n";
1584
$tmp .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n";
1585
$tmp .= "\t\@for base in $files; do \\\n";
1586
$tmp .= "\t echo \$(INSTALL_DATA) \$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1587
$tmp .= "\t \$(INSTALL_DATA) \$(srcdir)/\$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1589
if ($appname eq 'common') {
1590
$tmp .= "\t\@echo \"merging common and language specific dir\" ;\\\n";
1591
$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";
1592
$tmp .= "\t\@com_files=`cd \$(kde_htmldir)/en/common && echo *` ;\\\n";
1593
$tmp .= "\tcd \$(DESTDIR)\$(kde_htmldir)/$kdelang/common ;\\\n";
1594
$tmp .= "\tif test -n \"\$\$com_files\"; then for p in \$\$com_files ; do \\\n";
1595
$tmp .= "\t case \" $files \" in \\\n";
1596
$tmp .= "\t *\" \$\$p \"*) ;; \\\n";
1597
$tmp .= "\t *) test ! -e \$\$p && echo \$(LN_S) ../../en/common/\$\$p \$(DESTDIR)\$(kde_htmldir)/$kdelang/common/\$\$p && \$(LN_S) ../../en/common/\$\$p \$\$p ;; \\\n";
1598
$tmp .= "\t esac ; \\\n";
1599
$tmp .= "\tdone ; fi ; true\n";
1602
$tmp .= "uninstall-nls:\n";
1603
$tmp .= "\tfor base in $files; do \\\n";
1604
$tmp .= "\t rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n";
1605
$tmp .= "\tdone\n\n";
1608
$target_adds{"distdir"} .= "distdir-nls ";
1610
$tmp = "distdir-nls:\n";
1611
$tmp .= "\tfor file in $files; do \\\n";
1612
$tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n";
1620
appendLines("docs-am:\n");
1624
#-----------------------------------------------------------------------------
1625
# Find headers in any of the source directories specified previously, that
1626
# are candidates for "moc-ing".
1627
sub findMocCandidates ()
1630
foreach $dir (@headerdirs)
1633
@list = `grep -l '^.*Q_OBJECT' $hExt 2> /dev/null`;
1634
chdir ($makefileDir);
1636
# The assoc array of root of headerfile and header filename
1637
foreach $hFile (@list)
1640
$hFile =~ /(.*)\.[^\.]*$/; # Find name minus extension
1643
print STDERR "Warning: Multiple header files found for $1\n";
1644
next; # Use the first one
1646
$mocFiles{$1} = "$dir\035$hFile"; # Add relative dir
1653
#-----------------------------------------------------------------------------
1655
# The programmer has specified a moc list. Prune out the moc candidates
1656
# list that we found based on looking at the header files. This generates
1657
# a warning if the programmer gets the list wrong, but this doesn't have
1659
sub pruneMocCandidates ($)
1662
local @mocList = split(' ', $_[0]);
1664
foreach $mocname (@mocList)
1666
$mocname =~ s/\.moc$//;
1667
if ($mocFiles{$mocname})
1669
$prunedMoc{$mocname} = $mocFiles{$mocname};
1673
my $print = $makefileDir;
1674
$print =~ s/^\Q$topdir\E\\//;
1675
# They specified a moc file but we can't find a header that
1676
# will generate this moc file. That's possible fatal!
1677
print STDERR "Warning: No moc-able header file for $print/$mocname\n";
1682
%mocFiles = %prunedMoc;
1685
#-----------------------------------------------------------------------------
1687
# Finds the cpp files (If they exist).
1688
# The cpp files get appended to the header file separated by \035
1689
sub checkMocCandidates ()
1693
foreach $mocFile (keys (%mocFiles))
1695
# Find corresponding c++ files that includes the moc file
1696
@cppFiles = `echo \`ls -1d $cppExt 2> /dev/null | egrep -v "\.moc\.$cxxsuffix\$" | egrep -v "all_$cxxsuffix\.$cxxsuffix\$"\``;
1699
my $files = join(" ", @cppFiles);
1701
`egrep -l "^[ ]*#include[ ]*.$mocFile\.moc." $files 2>/dev/null`;
1707
$mocFiles{$mocFile} .= "\035" . $cppFiles[0];
1708
push(@deped, $mocFile);
1714
push (@newObs, $mocFile); # Produce new object file
1715
next if ($haveAutomocTag); # This is expected...
1716
# But this is an error we can deal with - let them know
1718
"Warning: No c++ file that includes $mocFile.moc\n";
1723
# We can't decide which file to use, so it's fatal. Although as a
1724
# guess we could use the mocFile.cpp file if it's in the list???
1726
"Error: Multiple c++ files that include $mocFile.moc\n";
1727
print STDERR "\t",join ("\t", @cppFiles),"\n";
1729
delete $mocFiles{$mocFile};
1730
# Let's continue and see what happens - They have been told!
1735
#-----------------------------------------------------------------------------
1737
# Add the rules for generating moc source from header files
1738
# For Automoc output *.moc.cpp but normally we'll output *.moc
1739
# (We must compile *.moc.cpp separately. *.moc files are included
1740
# in the appropriate *.cpp file by the programmer)
1746
foreach $mocFile (keys (%mocFiles))
1749
($dir, $hFile, $cppFile) = split ("\035", $mocFiles{$mocFile}, 3);
1750
$dir =~ s#^\.#\$(srcdir)#;
1751
if (defined ($cppFile))
1753
$target_adds{"\$(srcdir)/$cppFile"} .= "$mocFile.moc ";
1754
appendLines ("$mocFile.moc: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile.moc\n");
1755
$cleanMoc .= " $mocFile.moc";
1759
appendLines ("$mocFile$mocExt: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile$mocExt\n");
1760
$cleanMoc .= " $mocFile$mocExt";
1765
sub make_meta_classes ()
1767
return if ($kdeopts{"qtonly"});
1771
my $moc_class_headers = "";
1773
`grep -l "setMocClasses[ ]*(.*)[ ]*;" $cppExt 2> /dev/null`;
1775
print STDOUT "C++ files with setMocClasses() = [".join(' ', @cppFiles)."]\n"
1777
foreach $program (@programs) {
1779
my @progsources = split(/[\s\034]+/, $sources{$program});
1780
my @depmocs = split(' ', $depedmocs{$program});
1781
my %shash = (), %mhash = ();
1782
@shash{@progsources} = 1; # we are only interested in the existence
1783
@mhash{@depmocs} = 1;
1785
print STDOUT "program=$program\n" if ($verbose);
1786
print STDOUT "psources=[".join(' ', keys %shash)."]\n" if ($verbose);
1787
print STDOUT "depmocs=[".join(' ', keys %mhash)."]\n" if ($verbose);
1788
print STDOUT "globalmocs=[".join(' ', keys(%globalmocs))."]\n" if ($verbose);
1789
foreach my $mocFile (keys (%globalmocs))
1792
($dir, $hFile, $cppFile) = split ("\035", $globalmocs{$mocFile}, 3);
1793
$dir =~ s#^\.#\$(srcdir)#;
1794
if (defined ($cppFile))
1796
#print STDOUT "cpp=$cppFile\n";
1797
$mocs .= " $mocFile.moc" if exists $shash{$cppFile};
1801
# Bah. This is the case, if no C++ file includes the .moc
1802
# file. We make a .moc.cpp file for that. Unfortunately this
1803
# is not included in the %sources hash, but rather is mentioned
1804
# in %depedmocs. If the user wants to use AUTO he can't just
1805
# use an unspecific METAINCLUDES. Instead he must use
1806
# program_METAINCLUDES. Anyway, it's not working real nicely.
1807
# E.g. Its not clear what happens if user specifies two
1808
# METAINCLUDES=AUTO in the same Makefile.am.
1809
$mocs .= " $mocFile.moc.$cxxsuffix"
1810
if exists $mhash{$mocFile.".moc.$cxxsuffix"};
1815
print STDOUT "==> mocs=[".$mocs."]\n" if ($verbose);
1816
my $sourcename = $program."_meta_unload";
1817
my $ext = ($program =~ /_la$/) ? ".lo" : ".o";
1818
my $srcfile = $sourcename.".$cxxsuffix";
1819
my $objfile = $sourcename.$ext;
1820
$moc_class_headers .= " $srcfile";
1822
$appl = "$srcfile: $mocs\n";
1823
$appl .= "\t\@echo 'creating $srcfile'\n";
1824
$appl .= "\t-rm -f $srcfile\n";
1825
$appl .= "\t\@echo 'static const char * _metalist_$program\[\] = {' > $srcfile\n";
1826
$appl .= "\tcat $mocs | grep 'char.*className' | ";
1827
$appl .= "sed -e 's/.*[^A-Za-z0-9_:]\\([A-Za-z0-9_:]*\\)::className.*\$\$/\\\"\\1\\\",/' | sort | uniq >> $srcfile\n";
1828
$appl .= "\t\@echo '0};' >> $srcfile\n";
1829
$appl .= "\t\@echo '#include <kunload.h>' >> $srcfile\n";
1830
$appl .= "\t\@echo '_UNLOAD($program)' >> $srcfile\n";
1833
$realObjs{$program} .= " \034" . $objfile . " ";
1834
$sources{$program} .= " $srcfile";
1835
$sources_changed{$program} = 1;
1836
$dep_files .= " \$(DEPDIR)/$sourcename.P";
1838
# now also add a dependency for the C++ file which includes a
1839
# setMocClasses() call, and is part of this program (if any)
1840
#foreach $cppFile (@cppFiles) {
1841
#print STDOUT "testing $cppFile\n" if $verbose;
1842
#if (exists $shash{$cppFile}) {
1843
# $appl .= "\$(srcdir)/$cppFile: $header\n";
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.237 $ ' . "\n";
1866
$MakefileData =~ s/\034/\\\n/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/g;
1897
$newCount++ while ($new =~ /\n/g);
1899
$MakefileData =~ s/\n$lookup/\n#>- $old\n#>\+ $newCount\n$new/;
1901
print STDERR "Warning: substitution of \"$lookup\" in $printname failed\n";
1905
#-----------------------------------------------------------------------------
1907
# Slap new lines on the back of the file.
1912
$new =~ s/\034/\\\n/g; # Fix continuation lines
1914
$newCount++ while ($new =~ /\n/g);
1916
$MakefileData .= "\n#>\+ $newCount\n$new";
1919
#-----------------------------------------------------------------------------
1921
# Restore the Makefile.in to the state it was before we fiddled with it
1922
sub restoreMakefile ()
1924
$MakefileData =~ s/# $progId[^\n\034]*[\n\034]*//g;
1925
# Restore removed lines
1926
$MakefileData =~ s/([\n\034])#>\- /$1/g;
1927
# Remove added lines
1928
while ($MakefileData =~ /[\n\034]#>\+ ([^\n\034]*)/)
1931
my $removeLines = "";
1932
while ($newCount--) {
1933
$removeLines .= "[^\n\034]*([\n\034]|)";
1935
$MakefileData =~ s/[\n\034]#>\+.*[\n\034]$removeLines/\n/;
1939
#-----------------------------------------------------------------------------