check-sources.pl revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
#
# Copyright (C) 2000, 2001, 2004, 2007, 2012, 2013, 2016 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# $Id$
# Rudimentary, primarily for use by the developers.
# This just evolved with no serious attempt at making it
# bulletproof or foolproof. Or pretty even. Probably would
# have done it differently if it were actually designed as opposed
# to just growing as a multi-tentacled thing as various messages
# were either added or selectively silenced.
use strict;
sub
sortdir() {
if (-d $::a) {
if (-d $::b) {
return ($::a cmp $::b);
} else {
return (-1);
}
} elsif (-d $::b) {
return (1);
} else {
return ($::a cmp $::b);
}
}
sub
do_dir($$) {
print "================> $newdir\n";
unless (chdir("$dir")) {
print "cd $newdir: $1\n";
return;
}
unless (opendir(DIR, ".")) {
print "opendir $predir/$dir: $!\n";
return;
}
next if $entry =~ /^\.\.?$/;
if (-d $entry) {
next;
}
next if $entry !~ /\.o$/;
}
closedir(DIR);
chdir("..") or
die "major malfunction: can't chdir to parent dir: $!\n";
print "================> $predir\n";
}
sub
do_file($) {
my $objfile = $_[0];
unless ($objfile =~ /\.o$/) {
print "$0: skipping non-object file $objfile\n";
return;
}
if (-f $savesource) {
print "$savesource exists, skipping\n";
return;
}
unless (-f $file) {
print "$file does not exist, skipping\n";
return;
}
rename($file, $savesource);
open(SOURCE, "< $savesource");
$_ = join('', <SOURCE>);
close(SOURCE);
$prefix = '';
print "$file begin\n" if $debug;
while (1) {
eval {
# Note that only '#include <...>' is checked, not '#include "..."'.
# 1 23 4 5 6 78
if (m%(\A\Q$prefix\E((.*\n)*?))(\#include\s+(<.*?>)(.*)\n)((.*\n)*)%) {
$elided = $5;
$comment = $6;
} else {
print "$file end\n" if $debug;
}
};
if ($@ ne "") {
print "$file processing failed: $@\n";
last;
}
last if $elided eq "";
if (! $config_h) {
$config_h = 1;
if ($elided ne "<config.h>") {
print "$file should include <config.h> before any other\n";
}
}
# Always required.
next if $elided eq "<config.h>";
# Can mark in the header file when a #include should stay even
# though it might not appear that way otherwise.
next if m%snprintf%m;
}
open(SOURCE, "> $file");
print SOURCE "$body";
close(SOURCE);
print "$file elided $elided, compiling\n" if $debug;
if (! defined($cpp_if)) {
$cpp_if = /^#if/m;
print "$file has CPP #if(def), doublecheck elision recommendations.\n"
if $cpp_if;
}
print "$file does not need $elided\n";
} elsif ($elided eq "<string.h>") {
}
} continue {
$prefix .= $prefix_extend;
}
rename($savesource, $file);
}
sub
compile($) {
my $obj = $_[0];
unless ($obj =~ /\.o$/) {
warn "$obj: not a .o object file\n";
return;
}
open(COMPILE, "make -e $obj 2>&1 >$output |");
print $stderr_lines if $debug;
close(COMPILE);
unlink($obj);
return ($stderr_lines ne "");
}
sub
main() {
$| = 1;
$0 =~ s%.*/%%;
die "Usage: $0 [-debug]\n" if $help;
unless (-f 'configure' && -f 'Makefile') {
die "$0: run from top of bind9 source tree, after configure has run\n";
}
print "========================\n";
print "building initial objects\n";
print "========================\n";
# XXX bleah
unless (system("make") == 0) {
die "make all failed, couldn't be sure all objects were generated.\n";
}
warn "make all_tests failed, but pressing on anyway\n";
}
print <<EOF;
================================================================
#if/#ifdef. It might well be that a header file does not
================================================================
# XXX gcc-specific
# available, gcc won't warn about the lack of a prototype in a header
# file.
}
main();