Change policy about how we handle generated files
[amule.git] / src / utils / scripts / check_defines.pl
blobb0ba530b6e4cd30bf98c58cb501a9e37d478a665
1 #!/usr/bin/perl
4 ## This file is part of the aMule Project
5 ##
6 ## Copyright (c) 2004-2011 Stu Redman ( sturedman@amule.org )
7 ## Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
8 ##
9 ## This program is free software; you can redistribute it and/or
10 ## modify it under the terms of the GNU General Public License
11 ## as published by the Free Software Foundation; either
12 ## version 2 of the License, or (at your option) any later version.
14 ## This program is distributed in the hope that it will be useful,
15 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ## GNU General Public License for more details.
19 ## You should have received a copy of the GNU General Public License
20 ## along with this program; if not, write to the Free Software
21 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 # To speed up compilation we compile some files used in amule, amuled, amulegui
25 # into libs which we link to the apps.
26 # This concept can only work if the files (or their includes) don't use
27 # preprocessor macros used to tell these projects apart.
29 # This script checks for usage of these macros.
30 # It has to be run from the src dir after running configure to build the deps.
33 use warnings;
34 use strict;
35 use Cwd;
37 die 'run from src dir after making dependencies' unless -f '.deps/amule-amule.Po';
39 my %checkedFiles; # key: path value: 0: ok 1: has AMULE_DAEMON 2: has CLIENT_GUI
41 sub checkDeps($$);
43 my @deps;
44 # libmuleappcommon
45 @deps = glob('.deps/libmuleappcommon*.Po');
46 checkDeps(1,1);
47 # libmuleappcore (ignore CLIENT_GUI usage)
48 @deps = glob('.deps/libmuleappcore*.Po');
49 checkDeps(1,0);
50 # libmuleappgui (ignore AMULE_DAEMON usage)
51 @deps = glob('.deps/libmuleappgui*.Po');
52 checkDeps(0,1);
53 # libcommon
54 chdir 'libs/common';
55 @deps = glob('.deps/*.Po');
56 checkDeps(1,1);
57 # libec
58 chdir '../ec/cpp';
59 @deps = glob('.deps/*.Po');
60 checkDeps(1,1);
62 sub checkDeps($$)
64 my $checkAMULE_DAEMON = shift;
65 my $checkCLIENT_GUI = shift;
66 printf("check %d dependencies in %s\n", scalar @deps, getcwd());
67 foreach (@deps) {
68 open(DEP, $_) or die "can't open $_ : $!";
69 my @lines = <DEP>;
70 close DEP;
71 my $line = join(' ', @lines);
72 $line =~ tr/:\\/ /;
73 my @files = split(/\s+/, $line);
74 my $obj = shift @files;
75 my %currentFiles;
76 foreach my $file (@files) {
77 next if $file =~ m-^/usr/-; # skip system and wx includes
78 next if $file =~ m-/wx/-;
79 next if $currentFiles{$file};
80 $currentFiles{$file} = 1;
81 my $status = $checkedFiles{$file};
82 unless (defined $status) {
83 $status = 0;
84 open(SRC, $file) or die "can't open $file : $!";
85 while (<SRC>) {
86 $status |= 1 if /^\s*\#.+AMULE_DAEMON/;
87 $status |= 2 if /^\s*\#.+CLIENT_GUI/;
89 close SRC;
90 $checkedFiles{$file} = $status;
92 print "$obj: AMULE_DAEMON used in $file\n" if $checkAMULE_DAEMON && ($status & 1);
93 print "$obj: CLIENT_GUI used in $file\n" if $checkCLIENT_GUI && ($status & 2);