tst.include.ksh revision 2633:71bab08d24b2
1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9# or http://www.opensolaris.org/os/licensing.
10# See the License for the specific language governing permissions
11# and limitations under the License.
12#
13# When distributing Covered Code, include this CDDL HEADER in each
14# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21
22#
23# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26#pragma ident	"%Z%%M%	%I%	%E% SMI"
27
28CC=/usr/sfw/bin/gcc
29CFLAGS=
30
31doit()
32{
33	file=$1
34	ofile=$2
35	errfile=$3
36	cfile=${TMPDIR:-/tmp}/inc.$$.$file.c
37	cofile=${TMPDIR:-/tmp}/inc.$$.$file
38	cat > $cfile <<EOF
39#include <sys/$file>
40void
41main()
42{}
43EOF
44	if $CC $CFLAGS -o $cofile $cfile >/dev/null 2>&1; then
45		dtrace -xerrtags -C -s /dev/stdin \
46		    >/dev/null 2>$errfile <<EOF
47#include <sys/$file>
48BEGIN
49{
50	exit(0);
51}
52EOF
53		if [ $? -ne 0 ]; then
54			echo $inc failed: `cat $errfile | head -1` > $ofile
55		else
56			echo $inc succeeded > $ofile
57		fi
58		rm -f $errfile
59	fi
60
61	rm -f $cofile $cfile 2>/dev/null
62}
63
64if [ ! -x $CC ]; then
65	echo "$0: bad compiler: $CC" >& 2
66	exit 1
67fi
68
69concurrency=`psrinfo | wc -l`
70let concurrency=concurrency*4
71let i=0
72
73files=/usr/include/sys/*.h
74
75#
76# There are a few files in /usr/include/sys that are known to be bad -- usually
77# because they include static globals (!) or function bodies (!!) in the header
78# file.  Hopefully these remain sufficiently few that the O(#files * #badfiles)
79# algorithm, below, doesn't become a problem.  (And yes, writing scripts in
80# something other than ksh1888 would probably be a good idea.)  If this script
81# becomes a problem, kindly fix it by reducing the number of bad files!  (That
82# is, fix it by fixing the broken file, not the broken script.)
83#
84badfiles="ctype.h eri_msg.h ser_sync.h sbpro.h"
85
86for inc in $files; do
87	file=`basename $inc`
88	for bad in $badfiles; do
89		if [ "$file" = "$bad" ]; then
90			continue 2 
91		fi
92	done
93
94	ofile=${TMPDIR:-/tmp}/inc.$file.$$.out
95	errfile=${TMPDIR:-/tmp}/inc.$file.$$.err
96	doit $file $ofile $errfile &
97	let i=i+1
98
99	if [ $i -eq $concurrency ]; then
100		#
101		# This isn't optimal -- it creates a highly fluctuating load
102		# as we wait for all work to complete -- but it's an easy
103		# way of parallelizing work.
104		#
105		wait
106		let i=0
107	fi
108done
109
110wait
111
112bigofile=${TMPDIR:-/tmp}/inc.$$.out
113
114for inc in $files; do
115	file=`basename $inc`
116	ofile=${TMPDIR:-/tmp}/inc.$file.$$.out
117
118	if [ -f $ofile ]; then
119		cat $ofile >> $bigofile
120		rm $ofile
121	fi
122done
123
124status=$(grep "failed:" $bigofile | wc -l)
125cat $bigofile
126rm -f $bigofile
127exit $status
128