#!/bin/sh
#
# Kernel API Tester by Pawel Rozanski
# kat <kernelbuilddir> <outfile> <test1> [ .... <testn> ]
#
# Tries to run gcc on test files & generate output file which contains selected
# definitions from test files
#
if [ -z "${CC}" ]; then CC=gcc; fi
echo -n "KAT will test if C compiler works..."
echo "main(){}" | ${CC} -x c - -o /dev/null
if [ $? -ne 0 ]; then
  echo "${CC}" failed
  echo "Please set CC to working compiler or set it to empty (for default gcc)"
  exit 1
fi
echo "ok"
TEST="${CC} -S -pipe -Werror-implicit-function-declaration -DMODULE -D__KERNEL__ -I${1}/include -I${1}/include/asm/mach-default -o /dev/null"
OUT=${2}
echo "/* Generated by Kernel API Tester */" > ${OUT}
shift 2
for i in $@; do
  echo -n "Checking ${i}... "
  ${TEST} ${i} 2> /dev/null
  if [ $? -eq 0 ]; then
    echo "true"
    sed '/\/\/T/!d;s/^\/\/T//' ${i} >> ${OUT}
  else
    echo "false"
    sed '/\/\/F/!d;s/^\/\/F//' ${i} >> ${OUT}
  fi
done
