Warning, /sdk/kde-dev-scripts/includemocs is written in an unsupported language. File is not indexed.
0001 #! /usr/bin/env perl
0002
0003 use strict;
0004 use Cwd;
0005 use File::Find;
0006
0007 my $qmake_mode=0;
0008 $qmake_mode = 1 if (`ls -1 *.pro 2>/dev/null`);
0009 # qmake-like naming also applied to kde frameworks 5, i.e. anything using cmake-automoc
0010 $qmake_mode = 1 if (defined $ARGV[0] && $ARGV[0] eq '-cmake');
0011
0012 my %dir2files=();
0013 my $cppExt=" cpp cc cxx C c++ ";
0014 my $cppFiles="*.cpp *.cc *.cxx *.C *.c++";
0015
0016 sub collectthing()
0017 {
0018 if (/\.([^.]+)$/) {
0019 my $ext=$1;
0020 if (" h H hh hxx h++ " =~ / $ext /) {
0021 my $line=`grep -l '^[{ \t]*Q_OBJECT' $_ 2> /dev/null`;
0022 chomp($line);
0023 if ($line) {
0024 $dir2files{$File::Find::dir}->{headers}->{$_} = 1;
0025 }
0026 } elsif ($cppExt =~ / $ext /) {
0027 $dir2files{$File::Find::dir}->{sources}->{$_} = 1;
0028 }
0029 }
0030 }
0031
0032 sub checkdir($)
0033 {
0034 my ($dir)=@_;
0035 chdir($dir);
0036 my $hdrs=$dir2files{$dir}->{headers};
0037 my $srcs=$dir2files{$dir}->{sources};
0038 foreach my $h (keys %$hdrs) {
0039 (my $name=$h) =~ s/\.[^.]+$//;
0040 my $mocfile = "$name.moc";
0041 $mocfile = "moc_$name.cpp" if ($qmake_mode);
0042 my @answer = `grep -l "^#include[ ]*.$mocfile." $cppFiles 2> /dev/null`;
0043 if (@answer == 0) {
0044 my $s;
0045 foreach my $e (split(/\s+/, $cppExt)) {
0046 if (exists $srcs->{$name.".".$e}) {
0047 $s=$dir."/".$name.".".$e; last;
0048 }
0049 }
0050 if ($s) {
0051 print "echo >> $s ;\n";
0052 print "echo '#include \"$mocfile\"' >> $s ;\n";
0053 } else {
0054 print "echo \"can't guess a C++ file for $dir/$h\" ;\n";
0055 }
0056 }
0057 }
0058 }
0059
0060 find (\&collectthing, cwd());
0061
0062 foreach my $k (keys %dir2files) {
0063 print STDERR "Directory $k:\n headers=[";
0064 print STDERR join(", ", keys %{$dir2files{$k}->{headers}});
0065 print STDERR "]\n sources=[";
0066 print STDERR join(", ", keys %{$dir2files{$k}->{sources}});
0067 print STDERR "]\n";
0068 checkdir($k);
0069 }
0070
0071 =head1 NAME
0072
0073 includemocs -- handle mocifyable headers, whose .moc file is nowhere included.
0074
0075 =head1 SYNOPSIS
0076
0077 includemocs
0078
0079 =head1 DESCRIPTION
0080
0081 Header files declaring a QObject descendant have to be run through moc to
0082 produce a .moc file. This .moc file has to be compiled, for which two
0083 possibilities exists: compile it separately, or #include it in the C++ file
0084 implementing that above mentioned class. The latter is more efficient in term
0085 of compilation speed.
0086
0087 This script searches in the current directory and its subdirs for header files
0088 declaring a QObject descendant class. If it finds some, it looks, if there is
0089 a C++ file containing an '#include' for the generated .moc file. If thats not
0090 the case, it tries to guess into which C++ file that '#include' is placed best
0091 (based on the filename). If it fails to guess a proper place, it mentions
0092 that.
0093
0094 On stdout commands are ouput, suitable for a shell, which, when
0095 evaluated, add the suggested '#include' at the end of the files.
0096
0097 On stderr some informational messages are printed.
0098
0099 =head1 EXAMPLES
0100
0101 cd kdebase ; includemocs
0102 cd kdebase ; `eval includemocs 2> /dev/null`
0103
0104 =head1 AUTHOR
0105
0106 Michael Matz <matz@ifh.de>
0107
0108 =cut
0109