This repository has been archived by the owner on Dec 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
am_edit
2445 lines (2113 loc) · 86.7 KB
/
am_edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl -w
# Expands the specialised KDE tags in Makefile.in to (hopefully) valid
# make syntax.
# When called without file parameters, we work recursively on all Makefile.in
# in and below the current subdirectory. When called with file parameters,
# only those Makefile.in are changed.
# The currently supported tags are
#
# {program}_METASOURCES
# where you have a choice of two styles
# {program}_METASOURCES = name1.moc name2.moc ... [\]
# {program}_METASOURCES = AUTO
# The second style requires other tags as well.
#
# To install icons :
# KDE_ICON = iconname iconname2 ...
# KDE_ICON = AUTO
#
# For documentation :
# http://developer.kde.org/documentation/other/developer-faq.html
#
# and more new tags TBD!
#
# The concept (and base code) for this program came from automoc,
# supplied by the following
#
# Matthias Ettrich <[email protected]> (The originator)
# Kalle Dalheimer <[email protected]> (The original implementator)
# Harri Porten <[email protected]>
# Alex Zepeda <[email protected]>
# David Faure <[email protected]>
# Stephan Kulow <[email protected]>
# Dirk Mueller <[email protected]>
use Cwd;
use File::Find;
use File::Basename;
# Prototype the functions
sub initialise ();
sub processMakefile ($);
sub updateMakefile ();
sub restoreMakefile ();
sub removeLine ($$);
sub appendLines ($);
sub substituteLine ($$);
sub findMocCandidates ();
sub pruneMocCandidates ($);
sub checkMocCandidates ();
sub addMocRules ();
sub findKcfgFile($);
sub tag_AUTOMAKE ();
sub tag_META_INCLUDES ();
sub tag_METASOURCES ();
sub tag_POFILES ();
sub tag_DOCFILES ();
sub tag_LOCALINSTALL();
sub tag_IDLFILES();
sub tag_UIFILES();
sub tag_KCFGFILES();
sub tag_SUBDIRS();
sub tag_ICON();
sub tag_CLOSURE();
sub tag_NO_UNDEFINED();
sub tag_NMCHECK();
sub tag_DIST();
sub tag_KDEINIT();
# Some global globals...
$verbose = 0; # a debug flag
$thisProg = "$0"; # This programs name
$topdir = cwd(); # The current directory
@makefiles = (); # Contains all the files we'll process
@foreignfiles = ();
$start = (times)[0]; # some stats for testing - comment out for release
$version = "v0.2";
$errorflag = 0;
$cppExt = "(cpp|cc|cxx|C|c\\+\\+)";
$hExt = "(h|H|hh|hxx|hpp|h\\+\\+)";
$progId = "KDE tags expanded automatically by " . basename($thisProg);
$automkCall = "\n";
$printname = ""; # used to display the directory the Makefile is in
$use_final = 1; # create code for --enable-final
$cleantarget = "clean";
$dryrun = 0;
$pathoption = 0;
$foreign_libtool = 0;
while (defined ($ARGV[0]))
{
$_ = shift;
if (/^--version$/)
{
print STDOUT "\n";
print STDOUT basename($thisProg), " $version\n",
"This is really free software, unencumbered by the GPL.\n",
"You can do anything you like with it except sueing me.\n",
"Copyright 1998 Kalle Dalheimer <kalle\@kde.org>\n",
"Concept, design and unnecessary questions about perl\n",
" by Matthias Ettrich <ettrich\@kde.org>\n\n",
"Making it useful by Stephan Kulow <coolo\@kde.org> and\n",
"Harri Porten <porten\@kde.org>\n",
"Updated (Feb-1999), John Birch <jb.nz\@writeme.com>\n",
"Fixes and Improvements by Dirk Mueller <mueller\@kde.org>\n",
"Current Maintainer Stephan Kulow\n\n";
exit 0;
}
elsif (/^--verbose$|^-v$/)
{
$verbose = 1; # Oh is there a problem...?
}
elsif (/^(?:-p|--path=)(.+)$/)
{
my $p = $1;
$thisProg = $p . "/". basename($thisProg);
warn ("$thisProg doesn't exist\n") if (!(-f $thisProg));
$thisProg .= " -p".$p;
$pathoption=1;
}
elsif (/^--help$|^-h$/)
{
print STDOUT "Usage $thisProg [OPTION] ... [dir/Makefile.in]...\n",
"\n",
"Patches dir/Makefile.in generated by automake\n",
"(where dir can be an absolute or relative directory name)\n",
"\n",
" -v, --verbose verbosely list files processed\n",
" -h, --help print this help, then exit\n",
" --version print version number, then exit\n",
" -p, --path= use the path to am_edit if the path\n",
" called from is not the one to be used\n",
" --no-final don't patch for --enable-final\n";
exit 0;
}
elsif (/^--no-final$/)
{
$use_final = 0;
$thisProg .= " --no-final";
}
elsif (/^--foreign-libtool$/)
{
$foreign_libtool = 1;
$thisProg .= " --foreign-libtool";
}
elsif (/^-n$/)
{
$dryrun = 1;
}
else
{
# user selects what input files to check
# add full path if relative path is given
$_ = cwd()."/".$_ if (! /^\//);
print "User wants $_\n" if ($verbose);
push (@makefiles, $_);
}
}
if ($thisProg =~ /^\// && !$pathoption )
{
print STDERR "Illegal full pathname call performed...\n",
"The call to \"$thisProg\"\nwould be inserted in some Makefile.in.\n",
"Please use option --path.\n";
exit 1;
}
# Only scan for files when the user hasn't entered data
if (!@makefiles)
{
print STDOUT "Scanning for Makefile.in\n" if ($verbose);
find (\&add_makefile, cwd());
#chdir('$topdir');
} else {
print STDOUT "Using input files specified by user\n" if ($verbose);
}
foreach $makefile (sort(@makefiles))
{
processMakefile ($makefile);
last if ($errorflag);
}
# Just some debug statistics - comment out for release as it uses printf.
printf STDOUT "Time %.2f CPU sec\n", (times)[0] - $start if ($verbose);
exit $errorflag; # causes make to fail if erroflag is set
#-----------------------------------------------------------------------------
# In conjunction with the "find" call, this builds the list of input files
sub add_makefile ()
{
push (@makefiles, $File::Find::name) if (/Makefile.in$/);
}
#-----------------------------------------------------------------------------
# Processes a single make file
# The parameter contains the full path name of the Makefile.in to use
sub processMakefile ($)
{
# some useful globals for the subroutines called here
local ($makefile) = @_;
local @headerdirs = ('.');
local $haveAutomocTag = 0;
local $MakefileData = "";
local $cxxsuffix = "KKK";
local @programs = (); # lists the names of programs and libraries
local $program = "";
local @kdeinits = (); # lists the kdeinit targets
local %realObjs = (); # lists the objects compiled into $program
local %sources = (); # lists the sources used for $program
local %finalObjs = (); # lists the objects compiled when final
local %realname = (); # the binary name of program variable
local %idlfiles = (); # lists the idl files used for $program
local %globalmocs = ();# list of all mocfiles (in %mocFiles format)
local %important = (); # list of files to be generated asap
local %uiFiles = ();
local %kcfgFiles = ();
local $allidls = "";
local $idl_output = "";# lists all idl generated files for cleantarget
local $ui_output = "";# lists all uic generated files for cleantarget
local $kcfg_output = "";# lists all kcfg generated files for cleantarget
local %dependmocs = ();
local $metasourceTags = 0;
local $dep_files = "";
local $dep_finals = "";
local %target_adds = (); # the targets to add
local %rule_adds = ();
local $kdelang = "";
local @cleanfiles = ();
local $cleanMoc = "";
local $closure_output = "";
local %varcontent = ();
$makefileDir = dirname($makefile);
chdir ($makefileDir);
$printname = $makefile;
$printname =~ s/^\Q$topdir\E\///;
$makefile = basename($makefile);
print STDOUT "Processing makefile $printname\n" if ($verbose);
# Setup and see if we need to do this.
return if (!initialise());
tag_AUTOMAKE (); # Allows a "make" to redo the Makefile.in
tag_META_INCLUDES (); # Supplies directories for src locations
foreach $program (@programs) {
$sources_changed{$program} = 0;
$dependmocs{$program} = "";
$important{$program} = "";
tag_IDLFILES(); # Sorts out idl rules
tag_NO_UNDEFINED();
tag_CLOSURE();
tag_NMCHECK();
tag_UIFILES(); # Sorts out ui rules
tag_KCFGFILES(); # Sorts out kcfg rules
tag_METASOURCES (); # Sorts out the moc rules
if ($sources_changed{$program}) {
my $lookup = $program . '_SOURCES\s*=[ \t]*(.*)';
if($program =~ /libkdeinit_(.*)/) {
my $prog = $1;
substituteLine($prog . '_SOURCES\s*=[ \t]*(.*)',
"${prog}_SOURCES = ${prog}_dummy.$cxxsuffix\n" .
"libkdeinit_${prog}_SOURCES = " . $sources{$program});
$sources{$prog} = "${prog}_dummy.$cxxsuffix";
}
else {
substituteLine($lookup, "$program\_SOURCES=" . $sources{$program});
}
}
if ($important{$program}) {
local %source_dict = ();
for $source (split(/[\034\s]+/, $sources{$program})) {
$source_dict{$source} = 1;
}
for $source (@cleanfiles) {
$source_dict{$source} = 0;
}
for $source (keys %source_dict) {
next if (!$source);
if ($source_dict{$source}) {
# sanity check
if (! -f $source) {
print STDERR "Error: $source is listed in a _SOURCE line in $printname, but doesn't exist yet. Put it in DISTCLEANFILES!\n";
} else {
$target_adds{"\$(srcdir)/$source"} .= $important{$program};
}
}
}
}
}
if ($cleanMoc) {
# Always add dist clean tag
# Add extra *.moc.cpp files created for USE_AUTOMOC because they
# aren't included in the normal *.moc clean rules.
appendLines ("$cleantarget-metasources:\n\t-rm -f $cleanMoc\n");
$target_adds{"$cleantarget-am"} .= "$cleantarget-metasources ";
}
tag_DIST() unless ($kdeopts{"noautodist"});
if ($idl_output) {
appendLines ("$cleantarget-idl:\n\t-rm -f $idl_output\n");
$target_adds{"$cleantarget-am"} .= "$cleantarget-idl ";
}
if ($ui_output) {
appendLines ("$cleantarget-ui:\n\t-rm -f $ui_output\n");
$target_adds{"$cleantarget-am"} .= "$cleantarget-ui ";
}
if ($kcfg_output) {
appendLines ("$cleantarget-kcfg:\n\t-rm -f $kcfg_output\n");
$target_adds{"$cleantarget-am"} .= "$cleantarget-kcfg ";
}
if ($closure_output) {
appendLines ("$cleantarget-closures:\n\t-rm -f $closure_output\n");
$target_adds{"$cleantarget-am"} .= "$cleantarget-closures ";
}
if ($MakefileData =~ /\nKDE_LANG\s*=\s*(\S*)\s*\n/) {
$kdelang = '$(KDE_LANG)'
} else {
$kdelang = '';
}
tag_POFILES (); # language rules for po directory
tag_DOCFILES (); # language rules for doc directories
tag_LOCALINSTALL(); # add $(DESTDIR) before all kde_ dirs
tag_ICON();
tag_SUBDIRS();
my $tmp = "force-reedit:\n";
$tmp .= "\t$automkCall\n\tcd \$(top_srcdir) && perl $thisProg $printname\n\n";
appendLines($tmp);
make_bcheck_target();
make_meta_classes();
tag_COMPILE_FIRST();
tag_FINAL() if (!$kdeopts{"nofinal"});
my $final_lines = "final:\n\t\$(MAKE) ";
my $final_install_lines = "final-install:\n\t\$(MAKE) ";
my $nofinal_lines = "no-final:\n\t\$(MAKE) ";
my $nofinal_install_lines = "no-final-install:\n\t\$(MAKE) ";
foreach $program (@programs) {
my $lookup = $program . '_OBJECTS\s*=[ \t]*.*';
my $new = "";
my @list = split(/[\034\s]+/, $realObjs{$program});
if (!$kdeopts{"nofinal"} && @list > 1 && $finalObjs{$program}) {
$new .= "$program\_final\_OBJECTS = " . $finalObjs{$program};
$new .= "\n$program\_nofinal\_OBJECTS = " . $realObjs{$program};
$new .= "\n\@KDE_USE_FINAL_FALSE\@$program\_OBJECTS = \$($program\_nofinal\_OBJECTS)";
$new .= "\n\@KDE_USE_FINAL_TRUE\@$program\_OBJECTS = \$($program\_final\_OBJECTS)";
$final_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" ";
$final_install_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" ";
$nofinal_lines .= "$program\_OBJECTS=\"\$($program\_nofinal\_OBJECTS)\" ";
$nofinal_install_lines .= "$program\_OBJECTS=\"\$($program\_nofinal_OBJECTS)\" ";
} else {
$new = "$program\_OBJECTS = " . $realObjs{$program};
}
if($MakefileData =~ m/\n$lookup/) {
substituteLine ($lookup, $new);
}
else {
appendLines("$new\n");
}
}
appendLines($final_lines . "all-am\n");
appendLines($final_install_lines . "install-am\n");
appendLines($nofinal_lines . "all-am\n");
appendLines($nofinal_install_lines . "install-am\n");
my $lookup = '(\@\S+\@)?DEP_FILES\s*=[ \t]*(.*)';
if ($MakefileData =~ /\n$lookup/) {
my $condition = $1;
my $depfiles = $2;
my $workfiles;
if ($dep_finals) {
# Add the conditions on every line, since
# there may be line continuations in the list.
$workfiles = "$dep_files $dep_finals $depfiles";
$workfiles =~ s/\034/\034$condition\@KDE_USE_FINAL_TRUE\@\t/g;
$lines = "$condition\@KDE_USE_FINAL_TRUE\@DEP_FILES = $workfiles\n";
$workfiles = "$dep_files $depfiles";
$workfiles =~ s/\034/\034$condition\@KDE_USE_FINAL_FALSE\@\t/g;
$lines .= "$condition\@KDE_USE_FINAL_FALSE\@DEP_FILES = $workfiles";
} else {
$workfiles = "$dep_files $depfiles";
$workfiles =~ s/\034/\034$condition\t/g;
$lines = $condition . "DEP_FILES = $workfiles";
}
substituteLine($lookup, $lines);
}
# new recursive targets
$target_adds{ "nmcheck" } .= ""; # always create nmcheck target
$target_adds{ "nmcheck-am" } .= "nmcheck";
$lookup = 'RECURSIVE_TARGETS\s*=[ \t]*(.*)';
if ($MakefileData =~ /\n$lookup/) {
substituteLine($lookup, "RECURSIVE_TARGETS = $1 nmcheck-recursive bcheck-recursive");
}
$cvs_lines = "kde-rpo-clean:\n";
$cvs_lines .= "\t-rm -f *.rpo\n";
appendLines($cvs_lines);
$target_adds{"clean"} .= "kde-rpo-clean ";
my %target_dels = ("install-data-am" => "");
# some strange people like to do a install-exec, and expect that also
# all modules are installed. automake doesn't know this, so we need to move
# this here from install-data to install-exec.
if ($MakefileData =~ m/\nkde_module_LTLIBRARIES\s*=/) {
# $target_adds{"install-exec-am"} .= "install-kde_moduleLTLIBRARIES ";
# don't use $target_adds here because we need to append the dependency, not
# prepend it. Fixes #44342 , when a module depends on a lib in the same dir
# and libtool needs it during relinking upon install (Simon)
my $lookup = "install-exec-am:([^\n]*)";
if($MakefileData =~ /\n$lookup\n/) {
substituteLine("$lookup", "install-exec-am: $1 install-kde_moduleLTLIBRARIES");
}
$target_dels{"install-data-am"} .= "install-kde_moduleLTLIBRARIES ";
$target_adds{"install-data-am"} .= " ";
}
my $lines = "";
foreach $add (keys %target_adds) {
my $lookup = quotemeta($add) . ':([^\n]*)';
if ($MakefileData =~ /\n$lookup\n/) {
my $newlines = $1;
my $oldlines = $lookup;
if (defined $target_dels{$add}) {
foreach $del (split(' ', $target_dels{$add})) {
$newlines =~ s/\s*$del\s*/ /g;
}
}
substituteLine($oldlines, "$add: " . $target_adds{$add} . $newlines);
} else {
$lines .= "$add: " . $target_adds{$add} . "\n";
}
}
appendLines($lines) if ($lines);
$lines = join("\n", values %rule_adds);
appendLines($lines) if ($lines);
my $found = 1;
while ($found) {
if ($MakefileData =~ m/\n(.*)\$\(CXXFLAGS\)(.*)\n/) {
my $stuff_before = $1;
my $stuff_after = $2;
my $lookup = quotemeta("$1\$(CXXFLAGS)$2");
my $replacement = "$1\$(KCXXFLAGS)$2";
$MakefileData =~ s/$lookup/$replacement/;
$lookup =~ s/\\\$\\\(CXXFLAGS\\\)/\\\$\\\(KCXXFLAGS\\\)/;
$replacement = "$stuff_before\$(KCXXFLAGS) \$(KDE_CXXFLAGS)$stuff_after";
next if ($stuff_before =~ /\$\(KDE_CXXFLAGS\)/ or $stuff_after =~ /\$\(KDE_CXXFLAGS\)/);
substituteLine($lookup, $replacement);
} else {
$found = 0;
}
}
if($foreign_libtool == 0) {
$lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=link) (\$\(CXXLD\).*\$\(KCXXFLAGS\))';
if ($MakefileData =~ m/$lookup/ ) {
$MakefileData =~ s/$lookup/$1 --tag=CXX $2/;
}
$lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=compile)\s+(\$\(CXX\)\s+)';
if ($MakefileData =~ m/$lookup/ ) {
$MakefileData =~ s/$lookup/$1 --tag=CXX $2/;
}
}
$MakefileData =~ s/\$\(KCXXFLAGS\)/\$\(CXXFLAGS\)/g;
$lookup = '(.*)cp -pr \$\$/\$\$file \$\(distdir\)/\$\$file(.*)';
if ($MakefileData =~ m/\n$lookup\n/) {
substituteLine($lookup, "$1cp -pr \$\$d/\$\$file \$(distdir)/\$\$file$2");
}
# Always update the Makefile.in
updateMakefile ();
return;
}
#-----------------------------------------------------------------------------
# Beware: This procedure is not complete. E.g. it also parses lines
# containing a '=' in rules (for instance setting shell vars). For our
# usage this us enough, though.
sub read_variables ()
{
while ($MakefileData =~ /\n\s*(\S+)\s*=([^\n]*)/g) {
$varcontent{$1} = $2;
}
}
# Check to see whether we should process this make file.
# This is where we look for tags that we need to process.
# A small amount of initialising on the tags is also done here.
# And of course we open and/or create the needed make files.
sub initialise ()
{
if (! -r "Makefile.am") {
print STDOUT "found Makefile.in without Makefile.am\n" if ($verbose);
return 0;
}
# Checking for files to process...
open (FILEIN, $makefile) || die "Can't open $makefileDir/$makefile: $!\n";
# perl bug in 5.8.0: in utf8 mode it badly screws up
binmode(FILEIN, ":bytes") if ($] >= 5.008);
# Read the file
# stat(FILEIN)[7] might look more elegant, but is slower as it
# requires stat'ing the file
seek(FILEIN, 0, 2);
my $fsize = tell(FILEIN);
seek(FILEIN, 0, 0);
read FILEIN, $MakefileData, $fsize;
close FILEIN;
print "DOS CRLF within $makefileDir/$makefile!\n" if($MakefileData =~ y/\r//d);
# Remove the line continuations, but keep them marked
# Note: we lose the trailing spaces but that's ok.
# Don't mangle line-leading spaces (usually tabs)
# since they're important.
$MakefileData =~ s/\\\s*\n/\034/g;
# If we've processed the file before...
restoreMakefile () if ($MakefileData =~ /$progId/);
foreach $dir (@foreignfiles) {
if (substr($makefileDir,0,length($dir)) eq $dir) {
return 0;
}
}
%kdeopts = ();
$kdeopts{"foreign"} = 0;
$kdeopts{"qtonly"} = 0;
$kdeopts{"noautodist"} = 0;
$kdeopts{"foreign-libtool"} = $foreign_libtool;
$kdeopts{"nofinal"} = !$use_final; # default
read_variables();
if ($MakefileData =~ /\nKDE_OPTIONS\s*=[ \t]*([^\n]*)\n/) {
my $kde_options_str = $1;
local @kde_options = split(/[\034\s]+/, $kde_options_str);
if (grep(/^foreign$/, @kde_options)) {
push(@foreignfiles, $makefileDir . "/");
return 0; # don't touch me
}
for $opt (@kde_options) {
if (!defined $kdeopts{$opt}) {
print STDERR "Warning: unknown option $opt in $printname\n";
} else {
$kdeopts{$opt} = 1;
}
}
}
# Look for the tags that mean we should process this file.
$metasourceTags = 0;
$metasourceTags++ while ($MakefileData =~ /\n[^=\#]*METASOURCES\s*=/g);
my $pofileTag = 0;
$pofileTag++ while ($MakefileData =~ /\nPOFILES\s*=/g);
if ($pofileTag > 1)
{
print STDERR "Error: Only one POFILES tag allowed\n";
$errorflag = 1;
}
while ($MakefileData =~ /\n\.SUFFIXES:([^\n]+)\n/g) {
my $suffixes_str = $1;
my @list=split(' ', $suffixes_str);
foreach $ext (@list) {
if ($ext =~ /^\.$cppExt$/) {
$cxxsuffix = $ext;
$cxxsuffix =~ s/\.//g;
print STDOUT "will use suffix $cxxsuffix\n" if ($verbose);
last;
}
}
}
tag_KDEINIT();
while ($MakefileData =~ /\n(\S*)_OBJECTS\s*=[\034 \t]*([^\n]*)\n/g) {
my $program = $1;
my $objs = $2; # safe them
my $ocv = 0;
my @objlist = split(/[\034\s]+/, $objs);
foreach $obj (@objlist) {
if ($obj =~ /(\S*)\$\((\S+)\)/ ) {
my $pre = $1;
my $variable = $2;
if ($pre eq '' && exists($varcontent{$variable})) {
my @addlist = split(/[\034\s]+/, $varcontent{$variable});
push(@objlist, @addlist);
} elsif ($variable !~ 'OBJEXT' && $variable !~ /am__objects_\d+/ ) {
$ocv = 1;
}
}
}
next if ($ocv);
next if ($program =~ /^am_libkdeinit_/);
$program =~ s/^am_// if ($program =~ /^am_/);
my $sourceprogram = $program;
$sourceprogram =~ s/\@am_/\@/ if($sourceprogram =~ /^.*\@am_.+/);
print STDOUT "found program $program\n" if ($verbose);
push(@programs, $program);
$realObjs{$program} = $objs;
if ($MakefileData =~ /\n$sourceprogram\_SOURCES\s*=[ \t]*(.*)\n/) {
$sources{$program} = $1;
}
else {
$sources{$program} = "";
print STDERR "found program with no _SOURCES: $program\n";
}
my $realprogram = $program;
$realprogram =~ s/_/./g; # unmask to regexp
if ($MakefileData =~ /\n($realprogram)(\$\(EXEEXT\)?)?:.*\$\($program\_OBJECTS\)/) {
$realname{$program} = $1;
} else {
# not standard Makefile - nothing to worry about
$realname{$program} = "";
}
}
my $lookup = 'DEPDIR\s*=.*';
if ($MakefileData !~ /\n$lookup/) {
$lookup = 'bindir\s*=[ \t]*.*';
substituteLine($lookup, "DEPDIR = .deps\n$1") if ($MakefileData =~ /\n($lookup)/);
}
my @marks = ('MAINTAINERCLEANFILES', 'CLEANFILES', 'DISTCLEANFILES');
foreach $mark (@marks) {
while ($MakefileData =~ /\n($mark)\s*=[ \t]*([^\n]*)/g) {
my $clean_str = $2;
foreach $file (split('[\034\s]+', $clean_str)) {
$file =~ s/\.\///;
push(@cleanfiles, $file);
}
}
}
my $localTag = 0;
$localTag++ if ($MakefileData =~ /\ninstall-\S+-local:/);
return (!$errorflag);
}
#-----------------------------------------------------------------------------
# Gets the list of user defined directories - relative to $srcdir - where
# header files could be located.
sub tag_META_INCLUDES ()
{
my $lookup = '[^=\n]*META_INCLUDES\s*=[ \t]*(.*)';
return 1 if ($MakefileData !~ /($lookup)\n/);
print STDOUT "META_INCLUDE processing <$1>\n" if ($verbose);
my $headerStr = $2;
removeLine ($lookup, $1);
my @headerlist = split(/[\034\s]+/, $headerStr);
foreach $dir (@headerlist)
{
$dir =~ s#\$\(srcdir\)#.#;
if (! -d $dir)
{
print STDERR "Warning: $dir can't be found. ",
"Must be a relative path to \$(srcdir)\n";
}
else
{
push (@headerdirs, $dir);
}
}
return 0;
}
#-----------------------------------------------------------------------------
sub tag_FINAL()
{
my @final_names = ();
foreach $program (@programs) {
if ($sources{$program} =~ /\(/) {
print STDOUT "found ( in $program\_SOURCES. skipping\n" if ($verbose);
next;
}
my $mocs = ""; # Moc files (in this program)
my $moc_cpp_added = 0; # If we added some .moc.cpp files, due to
# no other .cpp file including the .moc one.
my @progsources = split(/[\034\s]+/, $sources{$program});
my %shash = ();
@shash{@progsources} = 1; # we are only interested in the existence
my %sourcelist = ();
my %extradeps = ();
foreach $source (@progsources) {
my $suffix = $source;
$suffix =~ s/^.*\.([^\.]+)$/$1/;
$sourcelist{$suffix} .= "$source ";
}
foreach my $mocFile (keys (%globalmocs))
{
my ($dir, $hFile, $cppFile) = split ("\035", $globalmocs{$mocFile}, 3);
if (defined ($cppFile)) {
$mocs .= " $mocFile.moc" if exists $shash{$cppFile};
} else {
$sourcelist{$cxxsuffix} .= "$mocFile.moc.$cxxsuffix ";
$moc_cpp_added = 1;
}
}
# scan for extra given dependencies and add them to our target
while ($MakefileData =~ /\n\s*(\S+)\.(?:lo|o)\s*:([^\n]*)/g) {
$extradeps{$1} = $2;
}
foreach $suffix (keys %sourcelist) {
# See if this file contains c++ code. (i.e., just check the file's suffix against c++ extensions)
my $suffix_is_cxx = 0;
if($suffix =~ /($cppExt)$/) {
$cxxsuffix = $1;
$suffix_is_cxx = 1;
}
my $mocfiles_in = ($suffix eq $cxxsuffix) && $moc_cpp_added;
my @sourcelist = split(/[\034\s]+/, $sourcelist{$suffix});
if ((@sourcelist == 1 && !$mocfiles_in) || $suffix_is_cxx != 1 ) {
# we support IDL on our own
if ($suffix eq "skel" || $suffix =~ /^stub/
|| $suffix =~ /^signals/ # obsolete, remove in KDE-4
|| $suffix eq "h" || $suffix eq "ui"
|| $suffix eq "kcfgc" ) {
next;
}
foreach $file (@sourcelist) {
$file =~ s/\Q$suffix\E$//;
$finalObjs{$program} .= $file;
if ($program =~ /_la$/) {
$finalObjs{$program} .= "lo ";
} else {
$finalObjs{$program} .= "o ";
}
}
next; # suffix
}
my $source_deps = "";
foreach $source (@sourcelist) {
if (-f $source) {
$source_deps .= " \$(srcdir)/$source";
} else {
$source_deps .= " $source";
}
my $plainsource = $source;
$plainsource =~ s/\.$cppExt$//;
$source_deps .= " " . $extradeps{$plainsource} if (exists($extradeps{$plainsource}));
}
$handling = "$program.all_$suffix.$suffix: \$(srcdir)/Makefile.in" . $source_deps . " " . join(' ', $mocs) . "\n";
$handling .= "\t\@echo 'creating $program.all_$suffix.$suffix ...'; \\\n";
$handling .= "\trm -f $program.all_$suffix.files $program.all_$suffix.final; \\\n";
$handling .= "\techo \"#define KDE_USE_FINAL 1\" >> $program.all_$suffix.final; \\\n";
$handling .= "\tfor file in " . $sourcelist{$suffix} . "; do \\\n";
$handling .= "\t echo \"#include \\\"\$\$file\\\"\" >> $program.all_$suffix.files; \\\n";
$handling .= "\t test ! -f \$\(srcdir\)/\$\$file || egrep '^#pragma +implementation' \$\(srcdir\)/\$\$file >> $program.all_$suffix.final; \\\n";
$handling .= "\tdone; \\\n";
$handling .= "\tcat $program.all_$suffix.final $program.all_$suffix.files > $program.all_$suffix.$suffix; \\\n";
$handling .= "\trm -f $program.all_$suffix.final $program.all_$suffix.files\n";
appendLines($handling);
push(@final_names, "$program.all_$suffix.$suffix");
my $finalObj = "$program.all_$suffix.";
if ($program =~ /_la$/) {
$finalObj .= "lo";
} else {
$finalObj .= "o";
}
$finalObjs{$program} .= $finalObj . " ";
}
}
if (!$kdeopts{"nofinal"} && @final_names >= 1) {
# add clean-final target
my $lines = "$cleantarget-final:\n";
$lines .= "\t-rm -f " . join(' ', @final_names) . "\n" if (@final_names);
appendLines($lines);
$target_adds{"$cleantarget-am"} .= "$cleantarget-final ";
foreach $finalfile (@final_names) {
$finalfile =~ s/\.[^.]*$/.P/;
$dep_finals .= " \$(DEPDIR)/$finalfile";
}
}
}
sub tag_KDEINIT()
{
my @progs = ();
my $ltlibs = "";
my $lookup = 'kdeinit_LTLIBRARIES\s*=[ \t]*(.*)';
if ($MakefileData =~ m/\n$lookup/) {
@kdeinits = split(/[\034\s]+/, $1);
my $lines = "";
foreach my $kdeinit (@kdeinits) {
if ($kdeinit =~ m/\.la$/) {
$kdeinit =~ s/\.la$//;
push(@progs, $kdeinit);
$lines .= "\n${kdeinit}.la.$cxxsuffix:\n";
$lines .= "\techo 'extern \"C\" int kdemain(int argc, char* argv[]);' > ${kdeinit}.la.$cxxsuffix; \\\n";
$lines .= "\techo 'int main(int argc, char* argv[]) { return kdemain(argc,argv); }' >> ${kdeinit}.la.$cxxsuffix\n";
$lines .= "\n${kdeinit}_dummy.$cxxsuffix:\n";
$lines .= "\techo '#include <kdemacros.h>' > ${kdeinit}_dummy.$cxxsuffix; \\\n";
$lines .= "\techo 'extern \"C\" int kdemain(int argc, char* argv[]);' >> ${kdeinit}_dummy.$cxxsuffix; \\\n";
$lines .= "\techo 'extern \"C\" KDE_EXPORT int kdeinitmain(int argc, char* argv[]) { return kdemain(argc,argv); }' >> ${kdeinit}_dummy.$cxxsuffix\n";
push(@cleanfiles, "${kdeinit}.la.$cxxsuffix");
push(@cleanfiles, "${kdeinit}_dummy.$cxxsuffix");
# add dependency
$dep_files .= " \$(DEPDIR)/${kdeinit}.la.Po" if($dep_files !~/${kdeinit}.la.Po/ );
$dep_files .= " \$(DEPDIR)/${kdeinit}_dummy.Plo" if($dep_files !~/${kdeinit}_dummy.Plo/ );
# make library
$lookup = $kdeinit . '_la_LIBADD\s*=[ \t]*(.*)';
if($MakefileData =~ m/\n$lookup/) {
my $libadd = $1;
substituteLine($lookup, "${kdeinit}_la_LIBADD = libkdeinit_${kdeinit}.la");
appendLines("libkdeinit_${kdeinit}_la_LIBADD = $libadd\n");
}
appendLines("libkdeinit_${kdeinit}_la_LDFLAGS = -no-undefined -avoid-version \$(all_libraries)\n");
# add library dependencies
$lookup = $kdeinit . '_la_DEPENDENCIES\s*=[ \t]*(.*)';
if($MakefileData =~ m/\n$lookup/) {
my $libdeps = $1;
substituteLine($lookup, "${kdeinit}_la_DEPENDENCIES = libkdeinit_${kdeinit}.la");
appendLines("libkdeinit_${kdeinit}_la_DEPENDENCIES = $libdeps\n");
}
# make library objects
$lookup = "am_${kdeinit}_la_OBJECTS" . '\s*=[ \t]*(.*)';
if($MakefileData =~ m/\n$lookup/) {
my $libobjects = $1;
substituteLine($lookup, "am_${kdeinit}_la_OBJECTS = ${kdeinit}_dummy.lo");
appendLines("am_libkdeinit_${kdeinit}_la_OBJECTS = $libobjects\n");
my $prog = "libkdeinit_${kdeinit}_la";
push(@programs, $prog);
$realObjs{$prog} = $libobjects;
$realname{$prog} = "libkdeinit_${kdeinit}.la";
}
$target_adds{"libkdeinit_${kdeinit}.la"} = "\$(libkdeinit_${kdeinit}_la_OBJECTS) \$(libkdeinit_${kdeinit}_la_DEPENDENCIES)\n" .
"\t\$(CXXLINK) -rpath \$(libdir) \$(libkdeinit_${kdeinit}_la_LDFLAGS) ".
"\$(libkdeinit_${kdeinit}_la_OBJECTS) " .
"\$(libkdeinit_${kdeinit}_la_LIBADD) " .
"\$(LIBS)\n";
# make libkdeinit sources
$lookup = $kdeinit . '_la_SOURCES\s*=[ \t]*(.*)';
if($MakefileData =~ m/\n$lookup/) {
my $srces = $1;
$sources_changed{"libkdeinit_${kdeinit}_la"} = 1;
$sources{"libkdeinit_${kdeinit}_la"} = $srces;
}
# make libkdeinit metasources
$lookup = $kdeinit . '_la_METASOURCES\s*=[ \t]*(.*)';
substituteLine($lookup, "libkdeinit_${kdeinit}_la_METASOURCES = $1")
if($MakefileData =~ m/\n$lookup/);
=cut
# make binary sources
$lookup = $kdeinit. '_SOURCES\s*=[ \t]*(.*)';
if($MakefileData =~ m/\n$lookup/) {
substituteLine($lookup, "${kdeinit}_SOURCES = ${kdeinit}.la.$cxxsuffix");
$lookup = 'SOURCES\s*=[ \t]*(.*)';
if($MakefileData =~ m/\n$lookup/) {
my $srces = $1;
$srces =~ s/\b$kdeinit\.c\b/\$(${kdeinit}_SOURCES)/;
$srces =~ s/\$\(${kdeinit}_la_SOURCES\)/\$(libkdeinit_${kdeinit}_la_SOURCES)/;
substituteLine($lookup, "SOURCES = $srces");
}
$lookup = 'DIST_SOURCES\s*=[ \t](.*)';
if($MakefileData =~ m/\n$lookup/) {
my $srces = $1;
$srces =~ s/\b$kdeinit\.c\b/\$(${kdeinit}_SOURCES)/;
$srces =~ s/\$\(${kdeinit}_la_SOURCES\)/\$(libkdeinit_${kdeinit}_la_SOURCES)/;
substituteLine($lookup, "DIST_SOURCES = $srces");
}
}
# make binary objects / libs
$lookup = $kdeinit . '_OBJECTS\s*=[ \t]*.*';
if($MakefileData =~ m/\n$lookup/) {
$realObjs{$kdeinit} = "${kdeinit}.la.\$(OBJEXT)";
substituteLine("${kdeinit}_LDFLAGS\\s*=.*", "${kdeinit}_LDFLAGS = \$(all_libraries)");
substituteLine("${kdeinit}_LDADD\\s*=.*", "${kdeinit}_LDADD = libkdeinit_${kdeinit}.la");
substituteLine("${kdeinit}_DEPENDENCIES\\s*=.*", "${kdeinit}_DEPENDENCIES = libkdeinit_${kdeinit}.la");
}
=cut
# add binary
push(@programs, $kdeinit);
$realObjs{$kdeinit} = "${kdeinit}.la.\$(OBJEXT)";
$realname{$kdeinit} = $kdeinit;
$sources{$kdeinit} = "${kdeinit}.la.$cxxsuffix";
$lines .= "${kdeinit}_LDFLAGS = \$(KDE_RPATH) -no-undefined \$(all_libraries)\n";
$lines .= "${kdeinit}_LDADD = libkdeinit_${kdeinit}.la\n";
$lines .= "${kdeinit}_DEPENDENCIES = libkdeinit_${kdeinit}.la\n";
$target_adds{"${kdeinit}\$(EXEEXT)"} =
"\$(${kdeinit}_OBJECTS) \$(${kdeinit}_DEPENDENCIES)\n" .
"\t\@rm -f ${kdeinit}\$(EXEEXT)\n" .
"\t\$(CXXLINK) \$(${kdeinit}_LDFLAGS) \$(${kdeinit}_OBJECTS) \$(${kdeinit}_LDADD) \$(LIBS)\n";
$ltlibs .= " libkdeinit_${kdeinit}.la";
}
}
appendLines($lines);
# add libkdeinit target
$lookup = 'lib_LTLIBRARIES\s*=[ \t]*(.*)';
if($MakefileData =~ m/\n$lookup/) {
substituteLine($lookup, "lib_LTLIBRARIES = $1 $ltlibs");
}
else {
print STDERR
"Error: lib_LTLIBRARIES missing in $printname (required for kdeinit_LTLIBRARIES).\n";
$errorflag = 1;
}
}
if($#progs >= 0) {
if($MakefileData !~ m/\nbin_PROGRAMS\s*=/) {
print STDERR "Error: bin_PROGRAMS missing in $printname (required for kdeinit_LTLIBRARIES).\n";
$errorflag = 1;
}
else {