#!/bin/sh

OPTS=
TEMP=obj/check-c-lib.c
mkdir -p obj || exit 1

CC="$*"
if [ "$CC" = "" ] ; then
  CC=cc
fi
CC="$CC -o /dev/null $TEMP"

cat >$TEMP << EOF
int main() {
  return 0;
}
EOF
$CC 1>/dev/null 2>&1
if [ "$?" != 0 ] ; then
  # Not GCC ?
  exit 0
fi

cat >$TEMP << EOF
#include <stdlib.h>
int main() {
  return *canonicalize_file_name("");
}
EOF
$CC 1>/dev/null 2>&1
if [ "$?" = 0 ] ; then
  OPTS="$OPTS -DUSE_canonicalize_file_name=1"
else
  OPTS="$OPTS -DUSE_canonicalize_file_name=0"
fi

cat >$TEMP << EOF
#include <sys/ptrace.h>
int main() {
  enum __ptrace_request cmd = (enum __ptrace_request)0;
  return cmd != 0;
}
EOF
$CC 1>/dev/null 2>&1
if [ "$?" = 0 ] ; then
  OPTS="$OPTS -DUSE_enum_ptrace_request=1"
else
  OPTS="$OPTS -DUSE_enum_ptrace_request=0"
fi

cat >$TEMP << EOF
#include <string.h>
int main() {
  char buf[256];
  strlcpy(buf, "", sizeof(buf));
  strlcat(buf, "", sizeof(buf));
  return 0;
}
EOF
$CC 1>/dev/null 2>&1
if [ "$?" = 0 ] ; then
  OPTS="$OPTS -DUSE_strlcpy_strlcat=1"
else
  OPTS="$OPTS -DUSE_strlcpy_strlcat=0"
fi

echo $OPTS