diff options
author | Robert Mustacchi <rm@joyent.com> | 2011-07-01 15:29:28 -0700 |
---|---|---|
committer | Robert Mustacchi <rm@joyent.com> | 2011-07-01 15:29:28 -0700 |
commit | be4035d30b9f278490b61ab83d4d80386f3932bd (patch) | |
tree | aac1c400f2c91cb41591fb63adcdbedc6a8c49f5 /tools | |
parent | 33afe2f37503804996aaf48f846030094d9b851b (diff) | |
download | illumos-kvm-be4035d30b9f278490b61ab83d4d80386f3932bd.tar.gz |
HVM-463 Want tool to check header files
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/hdrchk | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tools/hdrchk b/tools/hdrchk new file mode 100755 index 0000000..0c8f7c5 --- /dev/null +++ b/tools/hdrchk @@ -0,0 +1,52 @@ +#!/bin/bash +# +# This checks that each header file can be compiled on its own. +# + +sh_cc= +sh_dir= +sh_base=${0##*/} +sh_tmpfile=/tmp/$sh_base-$USER.$$.c +sh_outfile=$sh_tmpfile.out + +cd ${0%/*} +sh_dir=${PWD%/*} + +function fail +{ + local msg="$*" + [[ -z "$msg" ]] && msg="failed" + echo "$sh_base: $msg" >&2 + exit 1 +} + +function check_file +{ + local file res + file=$1 + + cat > $sh_tmpfile <<EOF +#include "$sh_dir/$file" + +int +main(void) +{ + return (0); +} +EOF + [[ $? -eq 0 ]] || fail "can't write to temporary file" + $sh_cc -o $sh_outfile $sh_tmpfile + res=$? + rm $sh_tmpfile $sh_outfile + [[ $? -eq 0 ]] || fail "$file is not clean" +} + +if [[ $# -lt 2 ]]; then + echo "$sh_base: <compiler> <file 0> [file 1] [file n]" +fi +sh_cc=$1 +shift + +for file in "$@"; do + check_file $file +done |