You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

200 lines
6.9 KiB

AC_INIT([utun],[2.0.0],[https://github.com/anomalyco/utun3/issues])
AC_CONFIG_SRCDIR([src/utun.c])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
# === ОБЯЗАТЕЛЬНО для правильного определения host ===
AC_CANONICAL_HOST
AC_CANONICAL_BUILD
# Required programs
AC_PROG_CC
AC_PROG_RANLIB
AM_PROG_AR
AM_INIT_AUTOMAKE([foreign subdir-objects -Wall])
AC_PROG_INSTALL
AC_PROG_MAKE_SET
# Option to use OpenSSL
AC_ARG_WITH([openssl],
AS_HELP_STRING([--with-openssl], [Use OpenSSL for cryptography (default: yes)]),
[with_openssl=$withval],
[with_openssl=yes])
if test "x$with_openssl" = "xyes"; then
# MSYS2 OpenSSL paths (для Windows)
case "$host" in
*mingw* | *msys* | *cygwin* | *win*)
if test -d "/c/msys64/ucrt64/include/openssl"; then
OPENSSL_CFLAGS="-I/c/msys64/ucrt64/include"
OPENSSL_LIBS="-L/c/msys64/ucrt64/lib -lcrypto"
AC_MSG_NOTICE([Using MSYS2 UCRT64 OpenSSL])
elif test -d "/ucrt64/include/openssl"; then
OPENSSL_CFLAGS="-I/ucrt64/include"
OPENSSL_LIBS="-L/ucrt64/lib -lcrypto"
AC_MSG_NOTICE([Using MSYS2 UCRT64 OpenSSL])
elif test -d "/mingw64/include/openssl"; then
OPENSSL_CFLAGS="-I/mingw64/include"
OPENSSL_LIBS="-L/mingw64/lib -lcrypto"
AC_MSG_NOTICE([Using MSYS2 MINGW64 OpenSSL])
fi
CFLAGS="$CFLAGS $OPENSSL_CFLAGS"
LDFLAGS="$LDFLAGS $OPENSSL_LIBS"
;;
esac
save_LIBS="$LIBS"
LIBS="-lcrypto $LIBS"
AC_CHECK_LIB([crypto], [SHA256_Init],
[AC_DEFINE([USE_OPENSSL], [1], [Define to use OpenSSL for cryptography])],
[AC_MSG_ERROR([OpenSSL crypto library required. Use --without-openssl to use TinyCrypt.])])
LIBS="$save_LIBS"
fi
AM_CONDITIONAL([USE_OPENSSL], [test "x$with_openssl" = "xyes"])
# ==================== HARDENING ====================
AC_ARG_ENABLE([hardening],
AS_HELP_STRING([--enable-hardening], [Enable compiler security hardening (FORTIFY, stack protector, PIE, RELRO)]),
[enable_hardening=$enableval],
[enable_hardening=no])
if test "x$enable_hardening" = "xyes"; then
HARDEN_CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong -fstack-clash-protection -Wformat=2 -Wformat-overflow=2 -fPIE"
HARDEN_LDFLAGS="-Wl,-z,relro -Wl,-z,now -pie"
CFLAGS="$CFLAGS $HARDEN_CFLAGS"
LDFLAGS="$LDFLAGS $HARDEN_LDFLAGS"
AC_MSG_NOTICE([Hardening flags enabled: $HARDEN_CFLAGS])
fi
# ==================== НАДЁЖНЫЙ ДЕТЕКТ WINDOWS ====================
AC_MSG_CHECKING([for Windows])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#ifndef _WIN32
#error "Not Windows"
#endif
]], [[ return 0; ]])],
[os_windows=yes],
[os_windows=no])
AC_MSG_RESULT([$os_windows])
AM_CONDITIONAL([OS_WINDOWS], [test "x$os_windows" = "xyes"])
# ==================== DETECT FREEBSD ====================
AC_MSG_CHECKING([for FreeBSD])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#ifndef __FreeBSD__
#error "Not FreeBSD"
#endif
]], [[ return 0; ]])],
[os_freebsd=yes],
[os_freebsd=no])
AC_MSG_RESULT([$os_freebsd])
AM_CONDITIONAL([OS_FREEBSD], [test "x$os_freebsd" = "xyes"])
# Set TUN libs based on platform
if test "x$os_windows" = "xyes"; then
TUN_LIBS="-liphlpapi -lws2_32 -ladvapi32 -lbcrypt -ldbghelp"
else
TUN_LIBS=""
fi
AC_SUBST([TUN_LIBS])
# ==================== WHISPER (OPTIONAL) ====================
AC_ARG_WITH([whisper],
AS_HELP_STRING([--with-whisper], [Enable Whisper speech-to-text (requires libwhisper)]),
[with_whisper=$withval],
[with_whisper=no])
if test "x$with_whisper" = "xyes"; then
AC_CHECK_HEADER([whisper.h], [
AC_CHECK_LIB([whisper], [whisper_init_from_file_with_params], [
WHISPER_LIBS="-lwhisper -lggml -lggml-base"
AC_DEFINE([HAVE_WHISPER], [1], [Define to enable Whisper speech-to-text])
AC_MSG_NOTICE([Whisper enabled])
], [
AC_MSG_WARN([libwhisper not found, disabling whisper])
with_whisper=no
])
], [
AC_MSG_WARN([whisper.h not found, disabling whisper])
with_whisper=no
])
fi
AM_CONDITIONAL([HAVE_WHISPER], [test "x$with_whisper" = "xyes"])
AC_SUBST([WHISPER_LIBS])
# ==================== FFMPEG (OPTIONAL) ====================
AC_ARG_WITH([ffmpeg],
AS_HELP_STRING([--with-ffmpeg], [Enable video transcoding (requires FFmpeg libav libraries)]),
[with_ffmpeg=$withval],
[with_ffmpeg=no])
if test "x$with_ffmpeg" = "xyes"; then
save_LIBS="$LIBS"
FFMPEG_LIBS="-lavformat -lavcodec -lavutil -lswscale -lswresample"
LIBS="$FFMPEG_LIBS $LIBS"
AC_CHECK_HEADER([libavformat/avformat.h], [
AC_CHECK_HEADER([libavcodec/avcodec.h], [
AC_CHECK_HEADER([libavutil/imgutils.h], [
AC_CHECK_HEADER([libswscale/swscale.h], [
AC_CHECK_HEADER([libswresample/swresample.h], [
AC_CHECK_LIB([avformat], [avformat_open_input], [
AC_DEFINE([HAVE_FFMPEG], [1], [Define to enable FFmpeg video transcoding])
AC_MSG_NOTICE([FFmpeg enabled])
], [
AC_MSG_WARN([FFmpeg libs not found, disabling ffmpeg])
with_ffmpeg=no
])
], [AC_MSG_WARN([swresample.h not found, disabling ffmpeg]); with_ffmpeg=no])
], [AC_MSG_WARN([swscale.h not found, disabling ffmpeg]); with_ffmpeg=no])
], [AC_MSG_WARN([imgutils.h not found, disabling ffmpeg]); with_ffmpeg=no])
], [AC_MSG_WARN([avcodec.h not found, disabling ffmpeg]); with_ffmpeg=no])
], [AC_MSG_WARN([avformat.h not found, disabling ffmpeg]); with_ffmpeg=no])
LIBS="$save_LIBS"
fi
if test "x$with_ffmpeg" != "xyes"; then
FFMPEG_LIBS=""
FFMPEG_CFLAGS=""
fi
AM_CONDITIONAL([HAVE_FFMPEG], [test "x$with_ffmpeg" = "xyes"])
AC_SUBST([FFMPEG_LIBS])
AC_SUBST([FFMPEG_CFLAGS])
# Checks for header files, typedefs, functions...
AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netinet/in.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h unistd.h])
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T
AC_C_INLINE
AC_FUNC_MALLOC
AC_CHECK_FUNCS([gettimeofday memset socket strchr strdup strerror strstr])
# TUN/TAP (только для Linux)
AC_MSG_CHECKING([for TUN/TAP support])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <linux/if_tun.h>]], [[int fd = open("/dev/net/tun", O_RDWR);]])],
[AC_MSG_RESULT([yes]); AC_DEFINE([HAVE_TUN_TAP], [1], [Define if TUN/TAP is available])],
[AC_MSG_RESULT([no])])
# Output
AC_CONFIG_FILES([Makefile src/Makefile tests/Makefile lib/Makefile lib/libopus/Makefile])
AC_OUTPUT
# Summary
echo "
Configuration summary:
----------------------
Host: ${host}
Windows: ${os_windows}
Prefix: ${prefix}
Compiler: ${CC}
CFLAGS: ${CFLAGS}
"