MODULES="compiler likewise"
SUBDIRS="include common"

configure()
{
    mk_config_header include/config.h

    lw_define_feature_macros

    mk_define _LARGEFILE_SOURCE 1
    mk_define _FILE_OFFSET_BITS 64
    
    mk_define STDC_HEADERS 1

    mk_check_headers \
        stdlib.h unistd.h sys/types.h sys/mman.h \
        getopt.h sys/select.h sys/time.h standards.h \
        stdint.h inttypes.h string.h strings.h sys/types.h \
        dlfcn.h limits.h stdbool.h sys/param.h sys/wait.h \
        setjmp.h sys/ipc.h sys/shm.h sys/mman.h fcntl.h sys/fcntl.h \
        grp.h stdarg.h syslog.h stddef.h

    mk_check_types \
        HEADERDEPS="stdbool.h sys/wait.h signal.h stdlib.h" \
        comparison_fn_t bool Bool sig_atomic_t
   
    mk_check_sizeofs \
        HEADERDEPS="stdlib.h" \
        off_t size_t ssize_t

    mk_check_libraries dl

    mk_check_functions \
        HEADERDEPS="sys/mman.h unistd.h" \
        mmap pread pwrite

    mk_check_functions \
        HEADERDEPS="stdlib.h" \
        setenv unsetenv strtoul strtoull mkdtemp

    mk_check_functions \
        HEADERDEPS="unistd.h" \
        seteuid setegid ftruncate

    mk_check_functions \
        HEADERDEPS="string.h" \
        strerror strdup memmove strlcpy strlcat strndup strnlen \
        strcasestr strtok_r memset

    mk_check_functions \
        HEADERDEPS="strings.h" \
        bzero

    mk_check_functions \
        HEADERDEPS="time.h" \
        mktime timegm strptime

    mk_check_functions \
        HEADERDEPS="stdio.h" \
        setlinebuf 

    mk_check_functions \
        HEADERDEPS="sys/types.h grp.h unistd.h" \
        initgroups

    mk_check_functions \
        HEADERDEPS="dlfcn.h" \
        LIBDEPS="$LIB_DL" \
        dlerror dlopen dlsym dlclose

    mk_check_functions \
        HEADERDEPS="sys/socket.h" \
        socketpair

    mk_check_functions \
        HEADERDEPS="stdarg.h stdio.h" \
        vasprintf snprintf vsnprintf asprintf

    mk_check_functions \
        HEADERDEPS="stdarg.h syslog.h" \
        vsyslog

    mk_check_functions \
        HEADERDEPS="stdarg.h" \
        va_copy __va_copy

    # We need to declare if we have C99-compliant vsnprintf or
    # not, but we can't actually try running a program as
    # that is not cross-compiling-friendly.  This hard-coded
    # list of operating systems with good implementations is
    # barely preferable.
    case "$MK_HOST_OS:$MK_HOST_DISTRO_VERSION" in
        linux:*|darwin:*)
            mk_define HAVE_C99_VSNPRINTF 1
            ;;
    esac
}
