check-sources.pl revision ec5347e2c775f027573ce5648b910361aa926c01
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Copyright (C) 2000, 2001 Internet Software Consortium.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Permission to use, copy, modify, and/or distribute this software for any
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# purpose with or without fee is hereby granted, provided that the above
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# copyright notice and this permission notice appear in all copies.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# PERFORMANCE OF THIS SOFTWARE.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# $Id: check-sources.pl,v 1.9 2007/06/18 23:47:57 tbox Exp $
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Rudimentary, primarily for use by the developers.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# This just evolved with no serious attempt at making it
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# bulletproof or foolproof. Or pretty even. Probably would
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# have done it differently if it were actually designed as opposed
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# to just growing as a multi-tentacled thing as various messages
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# were either added or selectively silenced.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (-d $::a) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (-d $::b) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return ($::a cmp $::b);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return (-1);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt } elsif (-d $::b) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return ($::a cmp $::b);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt my $newdir = $predir ne "" ? "$predir/$dir" : $dir;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt print "================> $newdir\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt unless (chdir("$dir")) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt print "cd $newdir: $1\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt print "opendir $predir/$dir: $!\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt next if $entry =~ /^\.\.?$/;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt next if $entry !~ /\.o$/;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt chdir("..") or
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt die "major malfunction: can't chdir to parent dir: $!\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt print "================> $predir\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt my ($config_h, $cpp_if, $prefix, $elided, $comment, $prefix_extend, $body);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt unless ($objfile =~ /\.o$/) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt print "$0: skipping non-object file $objfile\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt print "$savesource exists, skipping\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt unless (-f $file) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt print "$file does not exist, skipping\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # Note that only '#include <...>' is checked, not '#include "..."'.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # 1 23 4 5 6 78
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (m%(\A\Q$prefix\E((.*\n)*?))(\#include\s+(<.*?>)(.*)\n)((.*\n)*)%) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if ($@ ne "") {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt print "$file processing failed: $@\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt print STDERR "$file checking $elided\n" if $debug;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt print "$file should include <config.h> before any other\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # Always required.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # Can mark in the header file when a #include should stay even
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # though it might not appear that way otherwise.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt next if $comment =~ /require|provide|extend|define|contract|explicit/i;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt print "$file elided $elided, compiling\n" if $debug;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (! defined($cpp_if)) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt print "$file has CPP #if(def), doublecheck elision recommendations.\n"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt print "$file does not need $elided\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt print "$file prefer <isc/string.h> to <string.h>\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt } continue {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt unless ($obj =~ /\.o$/) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt warn "$obj: not a .o object file\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt $0 =~ s%.*/%%;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt die "$0: run from top of bind9 source tree, after configure has run\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt print "========================\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt print "building initial objects\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt print "========================\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt die "make all failed, couldn't be sure all objects were generated.\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt unless (system("cd bin/tests && make -k all_tests") == 0) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt warn "make all_tests failed, but pressging on anyway\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt================================================================
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntWARNING: Since this script only removes one header at a time,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntprograms might compile fine without the header because another
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntheader provides the required information. If that header is
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntalso recommend for removal, then removing both of them could
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntlead to a program that does *not* compile fine. So the only
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntway to be sure is to take them all out and then recompile to
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntSimilar, this program is quite ignorant when it comes to CPP
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#if/#ifdef. It might well be that a header file does not
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntappear to be necessary because the code that depends on it
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntis not being compiled. To prevent this program from complaining
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntabout such includes in later runs, put a "Required for ..."
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt================================================================
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # XXX gcc-specific
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # Disable builtin memcmp/memcpy/strcmp/strcpy/etc. When they are
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # available, gcc won't warn about the lack of a prototype in a header