#!/bin/sh

CXX="$1"
if [ -z "$CXX" ]; then
    echo >&2 "CXX not specified"
    exit 1
fi
shift # The rest of arguments are CFLAGS of some sort.

cat <<END >conftest.cc
#include <unistd.h>
int main()
{
    fdatasync(1);
    return 0;
}
END

if $CXX "$@" -c conftest.cc >/dev/null 2>/dev/null; then
    FDATASYNC="#define CRAWL_HAVE_FDATASYNC"
else
    FDATASYNC="#undef CRAWL_HAVE_FDATASYNC"
fi
rm -f conftest.cc conftest.o

cat <<END >conftest.cc
#include <string.h>
int main()
{
    const char *src = "hello";
    char dst[10];
    strlcpy(dst, src, sizeof(dst));
    return 0;
}
END

if $CXX "$@" -c conftest.cc >/dev/null 2>/dev/null; then
    STRLCPY="#define CRAWL_HAVE_STRLCPY"
else
    STRLCPY="#undef CRAWL_HAVE_STRLCPY"
fi
rm -f conftest.cc conftest.o

cat <<END >config.h
// Generated by util/configure

$FDATASYNC
$STRLCPY
END
