mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Doug Maxey <dwm@maxeymade.com>
To: Josh Boyer <jdub@us.ibm.com>
Cc: "Jörn Engel" <joern@infradead.org>, linux-kernel@vger.kernel.org
Subject: Re: Missing #include <config.h>
Date: Tue, 13 Sep 2005 11:22:21 -0500	[thread overview]
Message-ID: <200509131622.j8DGMLwF029752@falcon30.maxeymade.com> (raw)
In-Reply-To: <1126620753.3209.3.camel@windu.rchland.ibm.com>

[-- Attachment #1: Type: text/plain, Size: 1387 bytes --]


On Tue, 13 Sep 2005 09:12:33 CDT, Josh Boyer wrote:
>On Tue, 2005-09-13 at 14:56 +0100, Jörn Engel wrote:
>> After spending some hours last night and this morning hunting a bug,
>> I've found that a different include order made a difference.  Some
>> files don't work correctly, unless config.h is included before.
>> 
>> Here is a very stupid bug checker for the problem class:
>> $ rgrep CONFIG include/ | cut -d: -f1 | sort -u > g1
>> $ rgrep CONFIG include/ | cut -d: -f1 | sort -u | xargs grep "config.h" | cut -d: -f1 | sort -u > g2
>> $ diff -u g1 g2 | grep ^- > g3
>
>Your checker doesn't quite test for nested includes.  E.g. if foo.h
>includes bar.h, and bar.h includes config.h, then foo.h doesn't need to
>include config.h explicitly.
>
>For a more concrete example, take include/asm-i386/kprobes.h from your
>list.  That includes linux/types.h, which includes linux/config.h.
>
>Making a tool that takes that into account could be interesting.
>
>josh
>
>-
>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at  http://www.tux.org/lkml/
>

Going Way Back - there was a perl script floating around last century 
named 'inctree' that did what he was looking for...

++doug


[-- Attachment #2: inctree --]
[-- Type: text/plain , Size: 5088 bytes --]

#!/usr/local/bin/perl
# $Id: inctree,v 1.1.1.1 2001/11/16 17:16:36 dwm Exp $
# $Header: /cvs/local/share/inctree,v 1.1.1.1 2001/11/16 17:16:36 dwm Exp $
# $Log: inctree,v $
# Revision 1.1.1.1  2001/11/16 17:16:36  dwm
# after rome burned.
#
# Revision 1.1  2001/11/16 17:16:36  dwm
# .
#
# Revision 1.10  1998-06-11 09:35:42-05  dwm
# *** empty log message ***
#
# Revision 1.9  1998-06-11 09:32:20-05  dwm
# *** empty log message ***
#
# Revision 1.8  1996-06-20 11:09:00-05  dwm
# *** empty log message ***
#
# Revision 1.7  1996-06-20 11:06:47-05  dwm
# sucks on AIX build tree.
#
# Revision 1.6  1996-06-20 08:39:46-05  dwm
# *** empty log message ***
#
# Revision 1.5  1996-06-20 08:34:11-05  dwm
# fix for using other compiler.
#
# Revision 1.4  1995-06-07 20:15:35-0500  dwm
# now we exclude the -c, -f*, and -M* compiler flags.
#
# Revision 1.3  1994-06-08 22:46:37-0500  dwm
# added support for C++
#
# Revision 1.2  1993/07/16  04:06:56  dwm
# Zthe -? neeeded a \.
#
# Revision 1.1  1993/07/16  03:51:35  dwm
# Initial revision
#

require 5.004;

# 'inctree' created 93/07/09 11:40 to validate/print the #includes
# for files.
# from the camel book, p274
#################################
############ GLOBALS ############
#################################
( $prog = $0 ) =~  s#.*/##o ; $0 = join(' ', $prog, @ARGV) ;
$CPP = $ENV{'CPP'} || 'gcc -E' ;
$shiftwidth = 4 ;

#################################
########## SUBROUTINES ##########
#################################
sub usage
{
    print STDERR @_ if @_ ;
    print STDERR <<"EOU" ;
usage: $prog [-d] [-D...] [-I...] [-l] [-m/pattern/] file...

 $prog runs the C preprocessor (default $CPP) on the specified files,
 passing along any -D or -I switches, then processes the output of
 cpp into a tree of who included what.  Files included more than
 once are marked DUPLICATE.

 flags:
 -C...  preprocessor definition (default $CPP_name).
 -D...	defines for the preprocessor.
 -I...  dirs to search for the #include files.
 -d	prints debugging info.
 -h|-?	print this message.
 -l	prints the line numbers of the include statements.
 -m/../	outputs any lines including the pattern specified.
 -s\d	sets shiftwidth (default $shiftwidth).
EOU
    exit 1 ;
}

#################################
############   MAIN  ############
#################################
# require 'getopts.pl' ;
# &Getopts('dD:I:lm:') || &usage ;
while ( $ARGV[0] =~ /^-/ )
{
    $_ = shift ;
    if (/^-C(.*)/)
    {
	$opt_cpp = ( $1 ? $1 : shift ) ;
    }
    elsif (/^-([DU])(.*)/)
    {
	$defines .= " -$1" . ($2 ? $2 : shift );
    }
    elsif (/^-I(.*)/)
    {
	$includes .= " -I" . ($1 ? $1 : shift );
    }
    elsif (/^-m(.*)/)
    {
	push(@pats, $1 ? $1 : shift );
    }
    elsif ( /^-d/ )
    {
	$debug++ ;
    }
    elsif ( /^-l/ )
    {
	$lines++ ;
    }
    elsif (/^-s(.*)/)
    {
	$shiftwidth = ( $1 ? $1 : shift ) ;
    }
    elsif (/^-h|^-\?/)
    {
	&usage ;
    }
     # other compiler flags
    elsif (/^-g(.*)|^-O(.*)|^-traditional|^-c|^-f(.*)|^-M(.*)/)
    {
	next ;
    }
    elsif (/^-v$/ )
    {
	$verbose = $_ ;
    }
    else
    {
	push (@ccopts, $_);
	#&usage("Unrecognized switch $_\n") ;
    }

}

print STDERR "$defines\n" if $debug ;
print STDERR "$includes\n" if $debug ;

 # build a subroutine to scan for patterns
if ( @pats )
{
    $sub = "sub pats ()\n{\n" ;
    foreach $pat ( @pats )
    {
	$sub .= "    print '>>>>>>> ',\$_ if m$pat;\n" ;
    }
    $sub .= "}\n" ;
    print STDERR $sub if $debug ;
    eval $sub ;
    die $@ if $@ ;
    ++$pats ;
}

 # process each file.
foreach $file (@ARGV)
{
    if (length $opt_cpp)
    {
	$CPP_name = $opt_cpp;
    }
    elsif ($file =~ /.C$|.cc$/) {
	$CPP_name = "g++ -E" ;
    }
    else {
	$CPP_name = $CPP ;
    }

    $ccopts = join (" ", @ccopts);
    $pipecmd = "$CPP_name $verbose $ccopts $defines $includes $file|" ;
    open(CPP,$pipecmd)
	|| die "Can't run $pipecmd: $!\n" ;
    $line = 2 ;

    while (<CPP>)
    {
	++$line ;
	pats () if $pats ;	# avoid expensive call if we can.
	next unless /^#/ ;
	next unless /^# \d/ ;
	(undef, $newline, $filename) = split ;
	$filename =~ s/\"//g ;

	 # now figure out if it's push, pop, or neither.
        if ($stack[$#stack] eq $filename)
        {
	    $line = $newline - 1 ;
	    next ;
        }

        if ($stack[$#stack - 1] eq $filename)	# Leaving file.
        {
	    $indent -= $shiftwidth ;
	    $line = pop(@lines) - 1 ;
	    pop(@stack) ;
        }
        else					# New file.
        {
	    printf "%6d ", $line -2 if $lines ;
	    push(@lines, $line) ;
	    $line = $newline ;
	    print "\t" x ($indent / 8), ' ' x ($indent % 8),
		$filename ;
	    print "  DUPLICATE" if $seen{$filename}++ ;
	    print "\n" ;
	    $indent += $shiftwidth ;
	    push(@stack, $filename) ;
        }
    }
    close CPP ;
    $indent = 0 ;
    %seen = () ;
    print "\n\n" ;
    $line = 0 ;
}
exit 0

  parent reply	other threads:[~2005-09-13 16:22 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-13 13:56 Jörn Engel
2005-09-13 14:08 ` Russell King
2005-09-13 14:12   ` Christoph Hellwig
2005-09-13 17:57     ` Geert Uytterhoeven
2005-09-13 18:02       ` Russell King
2005-09-13 14:50   ` [PATCH] Permanently fix kernel configuration include mess (was: Missing #include <config.h>) Russell King
2005-09-13 16:59     ` Joern Engel
2005-09-13 18:04       ` Russell King
2005-09-13 19:10         ` [PATCH] Permanently fix kernel configuration include mess Brian Gerst
2005-09-13 19:33           ` Josh Boyer
2005-09-13 20:10             ` Alexey Dobriyan
2005-09-14  8:39     ` [PATCH] Permanently fix kernel configuration include mess (was: Missing #include <config.h>) Andrew Morton
2005-09-14  8:48       ` Russell King
2005-09-14 13:48       ` Sergey Vlasov
2005-09-14 14:02       ` Christoph Hellwig
2005-09-14 17:04       ` Sam Ravnborg
2005-09-13 14:12 ` Missing #include <config.h> Josh Boyer
2005-09-13 14:28   ` Russell King
2005-09-13 14:40     ` Josh Boyer
2005-09-13 16:22   ` Doug Maxey [this message]
2005-09-13 17:55 ` Geert Uytterhoeven

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200509131622.j8DGMLwF029752@falcon30.maxeymade.com \
    --to=dwm@maxeymade.com \
    --cc=jdub@us.ibm.com \
    --cc=joern@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome