On 3/28/06, Alexander Neundorf <[EMAIL PROTECTED]> wrote:
> Maybe somebody could write a script which checks which compiler definitions
> are used in which files ?

Here's a really ugly perl script that traverses a set of directories and
pulls out HAVE_* symbols from .h/.c/.cpp files and then prints out what
files they occur in.  Call it like this

% find-config-symbols.pl kdelibs

Here's sample output run against the dcop directory:

% find-source-files.pl dcop
HAVE_CONFIG_H
  dcop/dcopserver_shutdown.c
  dcop/dcopserver_shutdown_win.cpp
HAVE_LIMITS_H
  dcop/dcopserver.cpp
HAVE_MKSTEMPS
  dcop/dcopserver.cpp
HAVE_SYS_PARAM_H
  dcop/dcopserver.cpp
HAVE_SYS_SELECT_H
  dcop/dcopserver_shutdown.c
HAVE_SYS_STAT_H
  dcop/dcopserver.cpp
HAVE_SYS_TYPES_H
  dcop/KDE-ICE/Xtrans.h
  dcop/dcopserver_shutdown.c
  dcop/dcopserver_shutdown_win.cpp

Hope this is useful.  Note that running it against all of kdelibs
will probably take a long time (10-20 minutes, I'd estimate).

Cheers,
Tanner

--
Tanner Lovelace
clubjuggler at gmail dot com
http://wtl.wayfarer.org/
(fieldless) In fess two roundels in pale, a billet fesswise and an
increscent, all sable.
#! /usr/bin/perl -w
    eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
        if 0; #$running_under_some_shell

use strict;
use File::Find ();

my $DEBUG = 0;

# Set the variable $File::Find::dont_use_nlink if you're using AFS,
# since AFS cheats.

# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name   = *File::Find::name;
*dir    = *File::Find::dir;
*prune  = *File::Find::prune;

sub wanted;
sub doexec ($@);


use Cwd ();
my $cwd = Cwd::cwd();

my %config_hash;

# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, @ARGV);

foreach my $key (sort keys %config_hash) {
    print $key ."\n";
    # remove duplicates
    my %seen = ();
    my @filelist = grep { ! $seen{$_} ++ } @{$config_hash{$key}};
    foreach my $file (sort @filelist) {
	print "  $file\n";
    }
}
exit;


sub wanted {
    /^(.*\.h|.*\.c|.*\.cpp)$/s &&
    doexec(0, 'grep','\#if.*HAVE_',"{}");
}


sub doexec ($@) {
    my $ok = shift;
    my @command = @_; # copy so we don't try to s/// aliases to constants
    for my $word (@command)
        { $word =~ s#{}#$name#g }
    if ($ok) {
        my $old = select(STDOUT);
        $| = 1;
        print "@command";
        select($old);
        return 0 unless <STDIN> =~ /^y/;
    }
    chdir $cwd; #sigh
    my $command = "@command";
    my @lines = `$command`;
    if (@lines) {
	foreach my $line (@lines) {
	    # Extract symbol
	    $line =~ /.*(HAVE[_A-Z]*)/;
	    print "Adding $name to $1\n" if $DEBUG;
	    push @{$config_hash{$1}}, $name;
	}
    }
    chdir $File::Find::dir;
    return !$?;
}



_______________________________________________
Kde-buildsystem mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kde-buildsystem

Reply via email to