#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.71])
AC_INIT([lcagent], [0.1.0], [bugs@librecast.net])
AC_COPYRIGHT(Copyright (c) 2024-2025 Brett Sheffield <bacs@librecast.net>
See COPYING for license details.
)
AC_CONFIG_SRCDIR([src/])
AC_CONFIG_HEADERS([src/config.h])

# Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_LEX(noyywrap)
AS_IF([test "x$LEX" != xflex], AC_MSG_FAILURE([flex is required]))
AC_PROG_YACC
AC_CHECK_PROG([testrunner], [lctest], [lctest], [maketest])
AC_SUBST([TESTRUNNER],[$testrunner])
AC_CHECK_PROGS([FALSE], [false], [/usr/bin/env false])
AC_CHECK_PROG([ifconfig], [ifconfig], [ifconfig])
AC_SUBST([IFCONFIG],[$ifconfig])
AC_CHECK_PROG([iproute], [ip], [iproute])
AC_SUBST([IPROUTE],[$iproute])
AC_CHECK_PROG([ROUTE], [route], [route])

# Checks for libraries.
AC_CHECK_LIB([lcrq], [rq_init])
AC_CHECK_LIB([librecast], [lc_channel_rq_overhead],,AC_MSG_FAILURE([liblibrecast >= 0.11 is required]))
AC_CHECK_LIB([sodium], [sodium_init],,AC_MSG_FAILURE([libsodium is required]))
AC_SEARCH_LIBS([pthread_create], [pthread])
AC_SEARCH_LIBS([arc4random_uniform], [bsd])

# Checks for header files.
AC_CHECK_HEADERS([sys/ioctl.h])
AC_CHECK_HEADERS([fcntl.h inttypes.h libintl.h netinet/in.h stdint.h sys/file.h sys/param.h sys/socket.h unistd.h],, AC_MSG_FAILURE([required header not found]))
AC_CHECK_HEADERS([librecast/types.h librecast/net.h librecast/crypto.h librecast/key.h],, AC_MSG_FAILURE([required header not found]))

# Checks for typedefs, structures, and compiler characteristics.
AC_C_INLINE
AC_C_RESTRICT
AC_CHECK_TYPES([ptrdiff_t])
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_INT8_T
AC_TYPE_INT16_T
AC_TYPE_INT32_T
AC_TYPE_UID_T
AC_TYPE_UINT8_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T

AC_TYPE_UINT8_T

# Checks for library functions.
AC_CHECK_FUNCS([lc_channel_get_hash])
AC_CHECK_FUNCS([getcwd realpath]) # test/testsync.c
AC_CHECK_FUNCS([arc4random_uniform getpagesize]) # test/testdata.c
AC_CHECK_FUNCS([memset setlocale strdup strerror],, AC_MSG_FAILURE([required function not found]))


AC_CONFIG_FILES([Makefile
		 doc/Makefile
                 man/Makefile
                 src/Makefile
                 test/Makefile
		 ])
AC_OUTPUT
