1178476Sjb#
2178476Sjb# CDDL HEADER START
3178476Sjb#
4178476Sjb# The contents of this file are subject to the terms of the
5178476Sjb# Common Development and Distribution License (the "License").
6178476Sjb# You may not use this file except in compliance with the License.
7178476Sjb#
8178476Sjb# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9178476Sjb# or http://www.opensolaris.org/os/licensing.
10178476Sjb# See the License for the specific language governing permissions
11178476Sjb# and limitations under the License.
12178476Sjb#
13178476Sjb# When distributing Covered Code, include this CDDL HEADER in each
14178476Sjb# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15178476Sjb# If applicable, add the following below this CDDL HEADER, with the
16178476Sjb# fields enclosed by brackets "[]" replaced with your own identifying
17178476Sjb# information: Portions Copyright [yyyy] [name of copyright owner]
18178476Sjb#
19178476Sjb# CDDL HEADER END
20178476Sjb#
21178476Sjb
22178476Sjb#
23178476Sjb# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24178476Sjb# Use is subject to license terms.
25178476Sjb#
26178476Sjb# ident	"%Z%%M%	%I%	%E% SMI"
27178476Sjb
28178476Sjbif [ $# != 1 ]; then
29178476Sjb	echo expected one argument: '<'dtrace-path'>'
30178476Sjb	exit 2
31178476Sjbfi
32178476Sjb
33178476Sjbdtrace=$1
34211545SrpauloCC=/usr/bin/gcc
35178476SjbCFLAGS=
36178476Sjb
37178476Sjbdoit()
38178476Sjb{
39178476Sjb	file=$1
40178476Sjb	ofile=$2
41178476Sjb	errfile=$3
42178476Sjb	cfile=${TMPDIR:-/tmp}/inc.$$.$file.c
43178476Sjb	cofile=${TMPDIR:-/tmp}/inc.$$.$file
44178476Sjb	cat > $cfile <<EOF
45178476Sjb#include <sys/$file>
46178476Sjbvoid
47178476Sjbmain()
48178476Sjb{}
49178476SjbEOF
50178476Sjb	if $CC $CFLAGS -o $cofile $cfile >/dev/null 2>&1; then
51178476Sjb		$dtrace -xerrtags -C -s /dev/stdin \
52178476Sjb		    >/dev/null 2>$errfile <<EOF
53178476Sjb#include <sys/$file>
54178476SjbBEGIN
55178476Sjb{
56178476Sjb	exit(0);
57178476Sjb}
58178476SjbEOF
59178476Sjb		if [ $? -ne 0 ]; then
60178476Sjb			echo $inc failed: `cat $errfile | head -1` > $ofile
61178476Sjb		else
62178476Sjb			echo $inc succeeded > $ofile
63178476Sjb		fi
64178476Sjb		rm -f $errfile
65178476Sjb	fi
66178476Sjb
67178476Sjb	rm -f $cofile $cfile 2>/dev/null
68178476Sjb}
69178476Sjb
70178476Sjbif [ ! -x $CC ]; then
71178476Sjb	echo "$0: bad compiler: $CC" >& 2
72178476Sjb	exit 1
73178476Sjbfi
74178476Sjb
75178476Sjbconcurrency=`psrinfo | wc -l`
76178476Sjblet concurrency=concurrency*4
77178476Sjblet i=0
78178476Sjb
79178476Sjbfiles=/usr/include/sys/*.h
80178476Sjb
81178476Sjb#
82178476Sjb# There are a few files in /usr/include/sys that are known to be bad -- usually
83178476Sjb# because they include static globals (!) or function bodies (!!) in the header
84178476Sjb# file.  Hopefully these remain sufficiently few that the O(#files * #badfiles)
85178476Sjb# algorithm, below, doesn't become a problem.  (And yes, writing scripts in
86178476Sjb# something other than ksh1888 would probably be a good idea.)  If this script
87178476Sjb# becomes a problem, kindly fix it by reducing the number of bad files!  (That
88178476Sjb# is, fix it by fixing the broken file, not the broken script.)
89178476Sjb#
90178476Sjbbadfiles="ctype.h eri_msg.h ser_sync.h sbpro.h neti.h hook_event.h \
91178476Sjb    bootconf.h bootstat.h dtrace.h dumphdr.h exacct_impl.h fasttrap.h \
92178476Sjb    kobj.h kobj_impl.h ksyms.h lockstat.h smedia.h stat.h utsname.h"
93178476Sjb
94178476Sjbfor inc in $files; do
95178476Sjb	file=`basename $inc`
96178476Sjb	for bad in $badfiles; do
97178476Sjb		if [ "$file" = "$bad" ]; then
98178476Sjb			continue 2 
99178476Sjb		fi
100178476Sjb	done
101178476Sjb
102178476Sjb	ofile=${TMPDIR:-/tmp}/inc.$file.$$.out
103178476Sjb	errfile=${TMPDIR:-/tmp}/inc.$file.$$.err
104178476Sjb	doit $file $ofile $errfile &
105178476Sjb	let i=i+1
106178476Sjb
107178476Sjb	if [ $i -eq $concurrency ]; then
108178476Sjb		#
109178476Sjb		# This isn't optimal -- it creates a highly fluctuating load
110178476Sjb		# as we wait for all work to complete -- but it's an easy
111178476Sjb		# way of parallelizing work.
112178476Sjb		#
113178476Sjb		wait
114178476Sjb		let i=0
115178476Sjb	fi
116178476Sjbdone
117178476Sjb
118178476Sjbwait
119178476Sjb
120178476Sjbbigofile=${TMPDIR:-/tmp}/inc.$$.out
121178476Sjb
122178476Sjbfor inc in $files; do
123178476Sjb	file=`basename $inc`
124178476Sjb	ofile=${TMPDIR:-/tmp}/inc.$file.$$.out
125178476Sjb
126178476Sjb	if [ -f $ofile ]; then
127178476Sjb		cat $ofile >> $bigofile
128178476Sjb		rm $ofile
129178476Sjb	fi
130178476Sjbdone
131178476Sjb
132178476Sjbstatus=$(grep "failed:" $bigofile | wc -l)
133178476Sjbcat $bigofile
134178476Sjbrm -f $bigofile
135178476Sjbexit $status
136