9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence#! /usr/bin/perl -ws
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Copyright (C) 2000, 2001, 2004, 2007, 2012, 2016 Internet Systems Consortium, Inc. ("ISC")
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# file, You can obtain one at http://mozilla.org/MPL/2.0/.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews
ea94d370123a5892f6c47a97f21d1b28d44bb168Tinderbox User# $Id$
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence# Rudimentary, primarily for use by the developers.
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence# This just evolved with no serious attempt at making it
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence# bulletproof or foolproof. Or pretty even. Probably would
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence# have done it differently if it were actually designed as opposed
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence# to just growing as a multi-tentacled thing as various messages
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence# were either added or selectively silenced.
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence# XXX many warnings should not be made unless the header will be a public file
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrenceuse strict;
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrenceuse vars qw($debug $isc_includes $dns_includes $lwres_includes
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence $omapi_includes);
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence$isc_includes = "-Ilib/isc/include -Ilib/isc/unix/include " .
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence "-Ilib/isc/pthreads/include";
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence$dns_includes = "-Ilib/dns/include -Ilib/dns/sec/dst/include";
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence$lwres_includes = "-Ilib/lwres/include";
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence$omapi_includes = "-Ilib/omapi/include";
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence$0 =~ s%.*/%%;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrencedie "Usage: $0 [-debug] headerfile ...\n" unless @ARGV > 0;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrenceunless (-f 'configure.in') {
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence die "$0: run from top of bind9 source tree\n";
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence}
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrenceundef $/;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrencemy @files = @ARGV;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence# Outer loop runs once for each file.
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrencefor (<>) {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence my ($file, $tmpfile, $objfile);
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence $file = shift @files;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence unless ($file =~ /\.h$/) {
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence print "$0: skipping non-header file $file\n";
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence next;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence die "$0: $file: no such file\n" unless -f $file;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence # header file fragments; ignore
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence # XXX rdatastruct itself is moderately tricky.
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence next if $file =~ m%/rdatastruct(pre|suf)\.h$%;
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence # From external sources; ignore.
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence next if $file =~ m%lib/dns/sec/(dnssafe|openssl)%m;
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence # Totally wrong platform; ignore.
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence next if $file =~ m%lib/isc/win32%;
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence ($tmpfile = $file) =~ s%(.*/)?%/tmp/%;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence $tmpfile =~ s/\.h$/.c/;
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence ($objfile = $tmpfile) =~ s/\.c$/\.o/;;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence $file =~ m%(.*/)?(.*)/(.*)\.h%;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence my $symbol = uc "\Q$2_$3_H\E";
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence $symbol =~ s/\\-/_/g;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence if (! m%^\#ifndef\ $symbol\n
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence \#define\ $symbol\ 1\n
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence (.*\n)+
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence \#endif\ /\*\ $symbol\ \*/\n
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence \n*\Z%mx) {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence print "$file has non-conforming wrapper for symbol $symbol\n"
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence unless $file =~ m%confparser_p\.h%;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence my $nocomment = '^(?!\s+/?\*)';
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence my $lib = $file =~ /lwres/ ? "lwres" : "isc";
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence # check use of macros without having included proper header for them.
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence if (/^(\U$lib\E_LANG_(BEGIN|END)DECLS)$/m &&
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence ! m%^#include <$lib/lang\.h>$%m) {
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence print "$file has $1 without <$lib/lang.h>\n";
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence if (/$nocomment.*ISC_EVENTCLASS_/m && ! m%^#include <isc/eventclass\.h>%m) {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence print "$file has ISC_EVENTCLASS_ without <isc/eventclass.h>\n"
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence unless $file =~ m%isc/eventclass.h%;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence if (/$nocomment.*ISC_RESULTCLASS_/m &&
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence ! m%^#include <isc/resultclass\.h>%m) {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence print "$file has ISC_RESULTCLASS_ without <isc/resultclass.h>\n"
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence unless $file =~ m%isc/resultclass.h%;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence if (/$nocomment.*ISC_(TRUE|FALSE|TF)\W/m &&
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence ! m%^#include <isc/(types|boolean).h>%m) {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence print "$file has ISC_TRUE/FALSE/TF without <isc/(boolean|types).h>\n"
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence unless $file =~ m%isc/boolean.h%;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence if (/$nocomment.*ISC_PLATFORM_/m &&
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence ! m%^#include <isc/platform.h>%m) {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence print "$file has ISC_PLATFORM_ without <isc/platform.h>\n"
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence unless $file =~ m%isc/platform.h%;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence if ($file !~ m%isc/magic\.h$% && $lib ne "lwres") {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence print "$file has ISC_MAGIC_VALID without <isc/magic.h>\n"
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence if /$nocomment.*ISC_MAGIC_VALID/m && ! m%^#include <isc/magic.h>%m;
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence print "$file could use ISC_MAGIC_VALID\n" if /^$nocomment.*->magic ==/m;
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence }
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence if (/$nocomment.*(ISC|DNS|DST)_R_/m &&
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence ! m%^#include <\L$1\E/result.h>%m) {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence print "$file has $1_R_ without <\L$1\E/result.h>\n"
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence unless $file =~ m%\L$1\E/result.h%m;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence if (/^$nocomment(?!#define)[a-z].*([a-zA-Z0-9]\([^;]*\);)/m &&
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence ! m%^#include <$lib/lang.h>%m) {
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence print "$file has declarations without <$lib/lang.h>\n";
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence }
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence #
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence # First see whether it can be compiled without any additional includes.
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence # Only bother doing this for files that will be installed as public
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence # headers (thus weeding out, for example, all of the dns/rdata/*/*.h)
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence #
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence if ($file =~ m%/include/% && system("cp $file $tmpfile") == 0) {
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence if (compile($file, $tmpfile, $objfile) != 0) {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence print "$file does not compile stand-alone\n";
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence my $prefix = '';
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence my ($elided, $comment, $prefix_extend, $body);
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence while (1) {
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence eval {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence # 1 23 4 5 6 78
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence if (m%(\A\Q$prefix\E((.*\n)*?))(\#include .*(<.*?>)(.*)\n)((.*\n)*)%) {
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence $elided = $5;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence $prefix_extend = $2 . $4;
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence $comment = $6;
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence $body = $1 . $7;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence } else {
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence $elided = ""; # stop processing this file.
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence };
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence if ($@ ne "") {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence print "$file processing failed: $@\n";
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence last;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence last if $elided eq "";
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence print STDERR "$file checking $elided\n" if $debug;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence # Can mark in the header file when a #include should stay even
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence # though it might not appear that way otherwise.
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence next if $comment =~ /require|provide|extend|define|contract|ensure/i;
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence #
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence # Special exceptions.
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence # XXXDCL some of these should be perhaps generalized (ie, look for
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence # ISC_(LINK|LIST)_ when using <isc/list.h>.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence #
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence if (($file =~ m%isc/log\.h$% && $elided eq "<syslog.h>") ||
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence ($file =~ m%isc/print\.h$% && $elided =~ /^<std(arg|def)\.h>$/) ||
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence ($file =~ m%isc/string\.h$% && $elided eq "<string.h>") ||
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence ($file =~ m%isc/types\.h$% &&
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence $elided =~ m%^<isc/(boolean|int|offset)\.h>$%) ||
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence ($file =~ m%isc/netdb\.h$% &&
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence $elided =~ m%^<(netdb|isc/net)\.h>$%)) {
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence next;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence if ($elided =~ m%^<(isc|dns|dst)/result.h>$%) {
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence my $dir = $1;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence if (! /$nocomment.*\U$dir\E_R_/m) {
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence unless ($dir eq "isc" && /$nocomment.*isc_result_t/m) {
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence # No {foo}_R_, but it is acceptable to include isc/result.h for
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence # isc_result_t ... but not both isc/result.h and isc/types.h.
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence # The later check will determine isc/result.h to be redundant,
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence # so only the ISC_R_ aspect has to be pointed out.
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence print "$file has <$dir/result.h> without \U$dir\E_R_\n";
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence next;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence } else {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence # There is an {foo}_R_; this is a necessary include.
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence next;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence if ($elided eq "<$lib/lang.h>") {
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence if (! /^\U$lib\E_LANG_BEGINDECLS$/m) {
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence print "$file includes <$lib/lang.h> but " .
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence "has no \U$lib\E_LANG_BEGINDECLS\n";
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence } elsif (! /^\U$lib\E_LANG_ENDDECLS$/m) {
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence print "$file has \U$lib\E_LANG_BEGINDECLS but " .
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence "has no \U$lib\E_LANG_ENDDECLS\n";
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence } elsif (! /^$nocomment(?!#define)[a-z].*([a-zA-Z0-9]\()/m) {
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence print "$file has <$lib/lang.h> apparently not function declarations\n";
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence next;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence if ($elided eq "<isc/eventclass.h>") {
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence if (! /$nocomment.*ISC_EVENTCLASS_/m) {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence print "$file has <isc/eventclass.h> without ISC_EVENTCLASS_\n";
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence next;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence if ($elided eq "<isc/resultclass.h>") {
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence if (! /$nocomment.*ISC_RESULTCLASS_/m) {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence print "$file has <isc/resultclass.h> without ISC_RESULTCLASS_\n";
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence next;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence if ($elided =~ "<(isc|dns)/types.h>") {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence my $dir = $1;
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence if (! /^$nocomment.*$dir\_\S+\_t\s/m) {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence print "$file has <$dir/types.h> but apparently no $dir\_*_t uses\n";
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence } elsif ($dir ne "isc" && m%^#include <isc/types.h>%m) {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence print "$file has <$dir/types.h> and redundant <isc/types.h>\n";
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence # ... otherwise the types.h file is needed for the relevant _t types
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence # it defines, even if this header file accidentally picks it up by
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence # including another header that itself included types.h.
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence # So skip the elision test in any event.
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence # XXX would be good to test for files that need types.h but don't
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence # include it.
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence next;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence if ($elided eq "<isc/boolean.h>") {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence next if /^$nocomment.*ISC_(TRUE|FALSE|TF)\W/m;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence if ($elided eq "<isc/platform.h>") {
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence if (! /^$nocomment.*ISC_PLATFORM_/m) {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence print "$file has <isc/platform.h> but no ISC_PLATFORM_\n";
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence }
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence next;
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence }
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence if ($elided eq "<isc/magic.h>") {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence if (! /^$nocomment.*ISC_MAGIC_VALID/m) {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence print "$file has <isc/magic.h> but no ISC_MAGIC_VALID\n";
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence next;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence open(TMP, "> $tmpfile");
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence print TMP "$body";
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence close(TMP);
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence print "$file elided $elided, compiling\n" if $debug;
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence if (compile($file, $tmpfile, $objfile) == 0) {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence print "$file does not need $elided\n";
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence }
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence } continue {
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence $prefix .= $prefix_extend;
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence }
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence}
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrencesub
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrencecompile() {
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence my ($original, $source, $objfile) = @_;
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence my $includes;
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence my $stderr = $debug ? "" : "2>/dev/null";
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence if ($original =~ m%lib/(isc|tests)/%) {
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence $includes = $isc_includes;
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence } elsif ($original =~ m%lib/dns/%) {
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence $includes = "$isc_includes $dns_includes";
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence } elsif ($original =~ m%lib/lwres/%) {
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence $includes = $lwres_includes;
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence } elsif ($original =~ m%lib/omapi/%) {
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence $includes = "$isc_includes $dns_includes $omapi_includes";
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence } else {
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence $includes = "";
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence }
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence
0978cb57f3ef18a63748699a5b1dd607866f6107David Lawrence system("cc $includes -c $source -o $objfile $stderr");
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence unlink($source, $objfile);
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence
595babf6279b0f07895c42fd1b74a5f437ccacefDavid Lawrence return ($?);
9bb05852fed91ff3913601b7ed8e43e711aa9094David Lawrence}