Debian Codegraph @

admin/automoc

raw
1 #! /usr/bin/perl
2
3 # Changes Makefile.in to work correctly with moc files. When called
4 # without parameters, automoc works recursively on all Makefile.in in
5 # and below the current subdirectory. When called with parameters,
6 # only these Makefile.in are changed.
7 #
8 # 1998-07-23 Harri Porten <[email protected]>
9 # * small bugfixes for MOCSOURCES
10 # 1998-11-08 Alex Zepeda <[email protected]>
11 # * tweak it so it will run from a "common" directory.
12 # 1998-11-11 Harri Porten <[email protected]> & David Faure <[email protected]>
13 # * bug fix for invocation with arguments
14 # 1998-11-16 Harri Porten <[email protected]>
15 # * take care of "ar" object files, too.
16 # (as proposed by Martin Vogt <[email protected]>)
17
18 use Cwd;
19 use File::Find;
20 use File::Basename;
21
22 if ( 0 ne 0 )
23 {
24 print "\n\n";
25 print "*********************************************\n";
26 print "automoc - Software that makes even more sense\n";
27 print "*********************************************\n\n";
28 print "Welcome to the wonderful world of automoc!\n";
29 print "This is really free software, unencumbered by the GPL.\n";
30 print "You can do anything you like with it except sueing me.\n";
31 print "Copyright 1998 Kalle Dalheimer <kalle\@kde.org>\n";
32 print "Concept, design and unnecessary questions about Perl by Matthias Ettrich <ettrich\@kde.org>\n\n";
33 }
34
35 if( @ARGV == 0 )
36 {
37
38 find( \&process_makefile1, cwd() );
39 }
40 else
41 {
42 $curdir = cwd();
43 while( @ARGV )
44 {
45 chdir( dirname( $ARGV[0] ) );
46 process_makefile( basename( $ARGV[0] ) );
47 chdir( $curdir );
48 shift @ARGV;
49 }
50 }
51
52 sub process_makefile1()
53 {
54 if( $_ ne "Makefile.in" )
55 {
56 return;
57 }
58 else
59 {
60 process_makefile( $File::Find::name );
61 }
62 }
63
64
65 sub process_makefile()
66 {
67 ( $filename ) = @_;
68
69 # print STDERR "Processing $filename\n";
70
71 # search for USE_AUTOMOC
72 @search_use_automoc = `grep USE_AUTOMOC $filename`;
73 return if( @search_use_automoc == 0 );
74
75 # find the name of the program
76 $search_use_automoc[0] =~ /^([^_]*)_/;
77 $programname = $1;
78
79 open( FILEIN, "$filename" ) or die "Could not open $filename: $!\n";
80 open( FILEOUT, ">$filename" . ".tmp" ) or die "Could not open $filename: $!\n";
81
82 @mocable_files = `grep -l Q_OBJECT *.h 2> /dev/null`;
83
84 foreach $mocable_file (@mocable_files) {
85 $thisfile = $mocable_file;
86 $thisfile =~ s/\.h//;
87 push @mocnames, $thisfile;
88 $thisfile = $mocable_file;
89 $thisfile =~ s/\.h/\.moc\.cpp/;
90 push @mocsources, $thisfile;
91 }
92
93 $objectline = $programname . "_OBJECTS";
94 $libobjectline = $programname . "_la_OBJECTS";
95 $arobjectline = $programname . "_a_OBJECTS";
96 while( <FILEIN> )
97 {
98 if( /(.*_METASOURCES\s*=\s*)(USE_AUTOMOC)/ )
99 {
100 print FILEOUT "$1 ";
101 foreach $mocsource (@mocsources) {
102 chomp $mocsource;
103 print FILEOUT $mocsource . " ";
104 }
105 print FILEOUT "\n";
106 }
107 elsif( /^$objectline/ or /^$libobjectline/ or
108 /^$arobjectline/ ) # look for programs and libraries
109 {
110 chomp $_;
111 $line = $_;
112 $idx = rindex( $line, "\\");
113 $morelines = 0;
114 # Found a backslash in the line
115 if($idx > 0) {
116 $line = substr( $line, 0, idx-1);
117 $morelines = 1;
118 }
119 print FILEOUT "$line ";
120 foreach $mocname (@mocnames) {
121 chomp $mocname;
122 if( /^$objectline/ or /^$arobjectline/ ) {
123 print FILEOUT $mocname . ".moc.o ";
124 }
125 elsif( /^$libobjectline/ ) {
126 print FILEOUT $mocname . ".moc.lo ";
127 }
128 }
129 if($morelines) {
130 print FILEOUT "\\";
131 }
132 print FILEOUT "\n";
133 }
134 elsif( m+cd \$\(top_srcdir\) \&\& \$\(AUTOMAKE\)+ )
135 {
136 print FILEOUT $_;
137 print FILEOUT "\tperl \$(top_builddir)/admin/automoc " . cwd() . "/Makefile.in\n";
138 }
139 else
140 {
141 print FILEOUT $_;
142 }
143 }
144
145 print FILEOUT "\n\n";
146 foreach $file (@mocnames) {
147 chomp $file;
148 print FILEOUT "$file.moc.cpp: $file.h\n";
149 print FILEOUT "\t\$(MOC) $file.h -o $file.moc.cpp\n\n"
150 }
151
152 $new = $filename;
153 $old = $filename . ".tmp";
154 rename $old, $new;
155 undef @mocsources;
156 undef @mocnames;
157 }
158
159