# Get some constants from the system header files.


# search <symbol> <file>
#
search ()
{
  grep '^#[ 	]*define[ 	]\+'$1'[ 	]' $2 2>/dev/null \
    | sed 's/^#[ 	]*//' | awk '{print $3}'
}

# check <symbol> <default> <files>
#
check ()
{
  sym=$1; shift
  def=$1; shift

  echo -n "checking for $sym..."

  for file in $*
  do
    if [ ! -f $file ]
    then
      continue
    fi

    val=`search $sym $file`

    if [ x$val != x ]
    then
      break
    fi
  done

  if [ x$val = x ]
  then
    echo -n " *** WARNING *** using fallback value"

    val=$def
  fi

  echo " $val"

  eval $sym=$val
}


check AF_INET 2 \
	/usr/include/linux/socket.h \
	/usr/include/sys/socket.h
check SOCK_STREAM 1 \
	/usr/include/linux/socket.h \
	/usr/include/sys/socket.h
check WNOHANG 1 \
	/usr/include/linux/wait.h \
	/usr/include/sys/wait.h
check EINTR 0 \
	/usr/include/asm/errno.h \
	/usr/include/errno.h
