From 44d39713d52959a900b7300d0ec09f9cc90016e0 Mon Sep 17 00:00:00 2001 From: Jari Sundell Date: Thu, 4 Jun 2026 17:46:47 +0200 Subject: [PATCH] Clean out old cruft in autoconf scripts. --- configure.ac | 12 +-- scripts/checks.m4 | 242 ++-------------------------------------------- scripts/common.m4 | 221 ++++++++++++++++++------------------------ 3 files changed, 101 insertions(+), 374 deletions(-) diff --git a/configure.ac b/configure.ac index 5d835e8e..ffa85f27 100644 --- a/configure.ac +++ b/configure.ac @@ -10,15 +10,9 @@ AM_PROG_AR LT_INIT AC_PROG_CXX - -AC_DEFINE([API_VERSION], [21], [api version]) - -# Filter out unwanted flags added by autoconf on some systems, e.g. MacOS. -TORRENT_REMOVE_UNWANTED(CXX, $CXX, -std=c++11 -std=gnu++11) - AX_CXX_COMPILE_STDCXX(20, noext, mandatory) -AC_SYS_LARGEFILE +AC_DEFINE([API_VERSION], [21], [api version]) RAK_CHECK_CFLAGS RAK_CHECK_CXXFLAGS @@ -26,9 +20,6 @@ RAK_ENABLE_DEBUG RAK_ENABLE_EXTRA_DEBUG RAK_ENABLE_WERROR -TORRENT_ENABLE_ARCH -TORRENT_WITH_SYSROOT - AC_ARG_ENABLE(execinfo, AS_HELP_STRING([--disable-execinfo], [disable libexecinfo [[default=enable]]]), @@ -80,7 +71,6 @@ CFLAGS="$CFLAGS $PTHREAD_CFLAGS $CURSES_CFLAGS $ZLIB_CFLAGS $DEPENDENCIES_CFLAGS CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS $CURSES_CFLAGS $ZLIB_CFLAGS $DEPENDENCIES_CFLAGS" TORRENT_CHECK_CACHELINE -TORRENT_CHECK_POPCOUNT AC_CONFIG_FILES([ Makefile diff --git a/scripts/checks.m4 b/scripts/checks.m4 index 923689ad..9ce90dab 100644 --- a/scripts/checks.m4 +++ b/scripts/checks.m4 @@ -1,48 +1,3 @@ -AC_DEFUN([TORRENT_CHECK_XFS], [ - AC_MSG_CHECKING(for XFS support) - - AC_COMPILE_IFELSE([AC_LANG_SOURCE([ - #include - #include - int main() { - struct xfs_flock64 l; - ioctl(0, XFS_IOC_RESVSP64, &l); - return 0; - } - ])], - [ - AC_DEFINE(USE_XFS, 1, Use XFS filesystem stuff.) - AC_MSG_RESULT(yes) - ], [ - AC_MSG_RESULT(no) - ]) -]) - - -AC_DEFUN([TORRENT_WITHOUT_XFS], [ - AC_ARG_WITH(xfs, - AS_HELP_STRING([--without-xfs],[do not check for XFS filesystem support]), - [ - if test "$withval" = "yes"; then - TORRENT_CHECK_XFS - fi - ], [ - TORRENT_CHECK_XFS - ]) -]) - - -AC_DEFUN([TORRENT_WITH_XFS], [ - AC_ARG_WITH(xfs, - AS_HELP_STRING([--with-xfs],[check for XFS filesystem support]), - [ - if test "$withval" = "yes"; then - TORRENT_CHECK_XFS - fi - ]) -]) - - AC_DEFUN([TORRENT_CHECK_EPOLL], [ AC_MSG_CHECKING(for epoll support) @@ -122,158 +77,9 @@ AC_DEFUN([TORRENT_WITHOUT_KQUEUE], [ ]) -AC_DEFUN([TORRENT_CHECK_FALLOCATE], [ - AC_MSG_CHECKING(for fallocate) - - AC_LINK_IFELSE([AC_LANG_PROGRAM([[#define _GNU_SOURCE - #include - ]], [[ fallocate(0, FALLOC_FL_KEEP_SIZE, 0, 0); return 0; - ]])],[ - AC_DEFINE(USE_FALLOCATE, 1, Linux's fallocate supported.) - AC_MSG_RESULT(yes) - ],[ - AC_MSG_RESULT(no) - ]) -]) - - -AC_DEFUN([TORRENT_CHECK_POSIX_FALLOCATE], [ - AC_MSG_CHECKING(for posix_fallocate) - - AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include - ]], [[ posix_fallocate(0, 0, 0); - ]])],[ - AC_DEFINE(USE_POSIX_FALLOCATE, 1, posix_fallocate supported.) - AC_MSG_RESULT(yes) - ],[ - AC_MSG_RESULT(no) - ]) -]) - - -AC_DEFUN([TORRENT_WITH_POSIX_FALLOCATE], [ - AC_ARG_WITH(posix-fallocate, - AS_HELP_STRING([--with-posix-fallocate],[check for and use posix_fallocate to allocate files]), - [ - if test "$withval" = "yes"; then - TORRENT_CHECK_POSIX_FALLOCATE - fi - ]) -]) - -AC_DEFUN([TORRENT_CHECK_STATVFS], [ - AC_CHECK_HEADERS(sys/vfs.h sys/statvfs.h sys/statfs.h) - - AC_MSG_CHECKING(for statvfs) - - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ - #if HAVE_SYS_VFS_H - #include - #endif - #if HAVE_SYS_STATVFS_H - #include - #endif - #if HAVE_SYS_STATFS_H - #include - #endif - ]], [[ - struct statvfs s; fsblkcnt_t c; - statvfs("", &s); - fstatvfs(0, &s); - ]])],[ - AC_DEFINE(FS_STAT_FD, [fstatvfs(fd, &m_stat) == 0], Function to determine filesystem stats from fd) - AC_DEFINE(FS_STAT_FN, [statvfs(fn, &m_stat) == 0], Function to determine filesystem stats from filename) - AC_DEFINE(FS_STAT_STRUCT, [struct statvfs], Type of second argument to statfs function) - AC_DEFINE(FS_STAT_SIZE_TYPE, [unsigned long], Type of block size member in stat struct) - AC_DEFINE(FS_STAT_COUNT_TYPE, [fsblkcnt_t], Type of block count member in stat struct) - AC_DEFINE(FS_STAT_BLOCK_SIZE, [(m_stat.f_frsize)], Determine the block size) - AC_MSG_RESULT(ok) - have_stat_vfs=yes - ],[ - AC_MSG_RESULT(no) - have_stat_vfs=no - ]) -]) - -AC_DEFUN([TORRENT_CHECK_STATFS], [ - AC_CHECK_HEADERS(sys/statfs.h) - - AC_MSG_CHECKING(for statfs) - - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ - #if HAVE_SYS_STATFS_H - #include - #endif - ]], [[ - struct statfs s; - statfs("", &s); - fstatfs(0, &s); - ]])],[ - AC_DEFINE(FS_STAT_FD, [fstatfs(fd, &m_stat) == 0], Function to determine filesystem stats from fd) - AC_DEFINE(FS_STAT_FN, [statfs(fn, &m_stat) == 0], Function to determine filesystem stats from filename) - AC_DEFINE(FS_STAT_STRUCT, [struct statfs], Type of second argument to statfs function) - AC_DEFINE(FS_STAT_SIZE_TYPE, [long], Type of block size member in stat struct) - AC_DEFINE(FS_STAT_COUNT_TYPE, [long], Type of block count member in stat struct) - AC_DEFINE(FS_STAT_BLOCK_SIZE, [(m_stat.f_bsize)], Determine the block size) - AC_MSG_RESULT(ok) - have_stat_vfs=yes - ],[ - AC_MSG_RESULT(no) - have_stat_vfs=no - ]) -]) - -AC_DEFUN([TORRENT_DISABLED_STATFS], [ - AC_DEFINE(FS_STAT_FD, [(errno = ENOSYS) == 0], Function to determine filesystem stats from fd) - AC_DEFINE(FS_STAT_FN, [(errno = ENOSYS) == 0], Function to determine filesystem stats from filename) - AC_DEFINE(FS_STAT_STRUCT, [struct {blocksize_type f_bsize; blockcount_type f_bavail;}], Type of second argument to statfs function) - AC_DEFINE(FS_STAT_SIZE_TYPE, [int], Type of block size member in stat struct) - AC_DEFINE(FS_STAT_COUNT_TYPE, [int], Type of block count member in stat struct) - AC_DEFINE(FS_STAT_BLOCK_SIZE, [(4096)], Determine the block size) - AC_MSG_RESULT(No filesystem stats available) -]) - -AC_DEFUN([TORRENT_WITHOUT_STATVFS], [ - AC_ARG_WITH(statvfs, - AS_HELP_STRING([--without-statvfs],[don't try to use statvfs to find free diskspace]), - [ - if test "$withval" = "yes"; then - TORRENT_CHECK_STATVFS - else - have_stat_vfs=no - fi - ], - [ - TORRENT_CHECK_STATVFS - ]) -]) - -AC_DEFUN([TORRENT_WITHOUT_STATFS], [ - AC_ARG_WITH(statfs, - AS_HELP_STRING([--without-statfs],[don't try to use statfs to find free diskspace]), - [ - if test "$have_stat_vfs" = "no"; then - if test "$withval" = "yes"; then - TORRENT_CHECK_STATFS - else - TORRENT_DISABLED_STATFS - fi - fi - ], - [ - if test "$have_stat_vfs" = "no"; then - TORRENT_CHECK_STATFS - if test "$have_stat_vfs" = "no"; then - TORRENT_DISABLED_STATFS - fi - fi - ]) -]) - - AC_DEFUN([TORRENT_WITH_ADDRESS_SPACE], [ AC_ARG_WITH(address-space, - AS_HELP_STRING([--with-address-space=MB],[change the default address space size [[default=1024mb]]]), + AS_HELP_STRING([--with-address-space=MB],[change the default address space size [[default=1024mb-or-32768mb]]]), [ if test ! -z $withval -a "$withval" != "yes" -a "$withval" != "no"; then AC_DEFINE_UNQUOTED(DEFAULT_ADDRESS_SPACE_SIZE, [$withval]) @@ -285,53 +91,13 @@ AC_DEFUN([TORRENT_WITH_ADDRESS_SPACE], [ AC_CHECK_SIZEOF(long) if test $ac_cv_sizeof_long = 8; then - AC_DEFINE(DEFAULT_ADDRESS_SPACE_SIZE, 4096, Default address space size.) + AC_DEFINE(DEFAULT_ADDRESS_SPACE_SIZE, 32768, Default address space size.) else AC_DEFINE(DEFAULT_ADDRESS_SPACE_SIZE, 1024, Default address space size.) fi ]) ]) -AC_DEFUN([TORRENT_WITH_FASTCGI], [ - AC_ARG_WITH(fastcgi, - AS_HELP_STRING([--with-fastcgi=PATH],[enable FastCGI RPC support (DO NOT USE)]), - [ - AC_MSG_CHECKING([for FastCGI (DO NOT USE)]) - - if test "$withval" = "no"; then - AC_MSG_RESULT(no) - - elif test "$withval" = "yes"; then - CXXFLAGS="$CXXFLAGS" - LIBS="$LIBS -lfcgi" - - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include - ]], [[ FCGX_Init(); ]])],[ - AC_MSG_RESULT(ok) - ],[ - AC_MSG_RESULT(not found) - AC_MSG_ERROR(Could not compile FastCGI test.) - ]) - - AC_DEFINE(HAVE_FASTCGI, 1, Support for FastCGI.) - - else - CXXFLAGS="$CXXFLAGS -I$withval/include" - LIBS="$LIBS -lfcgi -L$withval/lib" - - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include - ]], [[ FCGX_Init(); ]])],[ - AC_MSG_RESULT(ok) - ],[ - AC_MSG_RESULT(not found) - AC_MSG_ERROR(Could not compile FastCGI test.) - ]) - - AC_DEFINE(HAVE_FASTCGI, 1, Support for FastCGI.) - fi - ]) -]) - AC_DEFUN([TORRENT_WITH_XMLRPC_C], [ AC_MSG_CHECKING(for XMLRPC-C) @@ -374,6 +140,7 @@ AC_DEFUN([TORRENT_WITH_XMLRPC_C], [ ]) ]) + AC_DEFUN([TORRENT_WITH_TINYXML2], [ AC_MSG_CHECKING(for tinyxml2) @@ -387,6 +154,7 @@ AC_DEFUN([TORRENT_WITH_TINYXML2], [ ]) ]) + AC_DEFUN([TORRENT_WITH_LUA], [ AC_ARG_WITH(lua, AS_HELP_STRING([--with-lua],[enable LUA support]), @@ -441,6 +209,7 @@ AC_DEFUN([TORRENT_WITH_INOTIFY], [ AC_LANG_POP(C++) ]) + AC_DEFUN([TORRENT_CHECK_PTHREAD_SETNAME_NP], [ AC_CHECK_HEADERS(pthread.h) @@ -472,6 +241,7 @@ AC_DEFUN([TORRENT_CHECK_PTHREAD_SETNAME_NP], [ ]) ]) + AC_DEFUN([TORRENT_DISABLE_PTHREAD_SETNAME_NP], [ AC_MSG_CHECKING([for pthread_setname_no]) diff --git a/scripts/common.m4 b/scripts/common.m4 index cf3796f6..7ec42099 100644 --- a/scripts/common.m4 +++ b/scripts/common.m4 @@ -1,67 +1,3 @@ -AC_DEFUN([TORRENT_WITH_SYSROOT], [ - AC_ARG_WITH(sysroot, - AS_HELP_STRING([--with-sysroot=PATH], - [compile and link with a specific sysroot]), - [ - AC_MSG_CHECKING(for sysroot) - - if test "$withval" = "no"; then - AC_MSG_RESULT(no) - - elif test "$withval" = "yes"; then - AC_MSG_RESULT(not a path) - AC_MSG_ERROR(The sysroot option must point to a directory, like f.ex "/Developer/SDKs/MacOSX10.4u.sdk".) - else - AC_MSG_RESULT($withval) - - CXXFLAGS="$CXXFLAGS -isysroot $withval" - LDFLAGS="$LDFLAGS -Wl,-syslibroot,$withval" - fi - ]) -]) - - -AC_DEFUN([TORRENT_REMOVE_UNWANTED], -[ - AC_REQUIRE([AC_PROG_GREP]) - values_to_check=`for i in $2; do echo $i; done` - unwanted_values=`for i in $3; do echo $i; done` - if test -z "${unwanted_values}"; then - $1="$2" - else - result=`echo "${values_to_check}" | $GREP -Fvx -- "${unwanted_values}" | $GREP -v '^$'` - # join with spaces, squeeze repeats, and trim trailing space - $1=$(printf '%s\n' "$result" | tr '\n' ' ' | sed 's/ */ /g; s/ *$//') - fi -]) - - -AC_DEFUN([TORRENT_ENABLE_ARCH], [ - AC_ARG_ENABLE(arch, - AS_HELP_STRING([--enable-arch=ARCH], - [comma seprated list of architectures to compile for]), - [ - AC_MSG_CHECKING(for target architectures) - - if test "$enableval" = "yes"; then - AC_MSG_ERROR(no arch supplied) - - elif test "$enableval" = "no"; then - AC_MSG_RESULT(using default) - - else - AC_MSG_RESULT($enableval) - - for i in `IFS=,; echo $enableval`; do - CFLAGS="$CFLAGS -march=$i" - CXXFLAGS="$CXXFLAGS -march=$i" - LDFLAGS="$LDFLAGS -march=$i" - done - fi - ]) -]) - - AC_DEFUN([TORRENT_MINCORE_SIGNEDNESS], [ AC_LANG_PUSH(C++) AC_MSG_CHECKING(signedness of mincore parameter) @@ -90,7 +26,7 @@ AC_DEFUN([TORRENT_MINCORE_SIGNEDNESS], [ AC_MSG_RESULT(signed) ], [ - AC_MSG_ERROR([failed, do *not* attempt fix this with --disable-mincore unless you are running Win32.]) + AC_MSG_ERROR([failed, do *not* attempt fix this with --disable-mincore unless you are running Win32 or OpenBSD.]) ]) ]) @@ -144,20 +80,6 @@ AC_DEFUN([TORRENT_CHECK_POSIX_FADVISE], [ ]) ]) -AC_DEFUN([TORRENT_CHECK_POPCOUNT], [ - AC_MSG_CHECKING(for __builtin_popcount) - - AC_COMPILE_IFELSE([AC_LANG_SOURCE([ - int f() { return __builtin_popcount(0); } - ])], - [ - AC_MSG_RESULT(yes) - AC_DEFINE(USE_BUILTIN_POPCOUNT, 1, Use __builtin_popcount.) - ], [ - AC_MSG_RESULT(no) - ]) -]) - AC_DEFUN([TORRENT_CHECK_CACHELINE], [ AC_REQUIRE([AC_CANONICAL_HOST]) AC_MSG_CHECKING([for target cacheline size]) @@ -227,74 +149,119 @@ AC_DEFUN([TORRENT_CHECK_CACHELINE], [ esac ]) -AC_DEFUN([TORRENT_CHECK_ALIGNED], [ - AC_MSG_CHECKING(the byte alignment) - AC_RUN_IFELSE([AC_LANG_SOURCE([ - #include - int main() { - char buf@<:@8@:>@ = { 0, 0, 0, 0, 1, 0, 0, 0 }; - int i; - for (i = 1; i < 4; ++i) - if (*(uint32_t*)(buf + i) == 0) return -1; - return 0; - } +AC_DEFUN([TORRENT_CHECK_CUSTOM_ENDIAN64], [ + AC_CHECK_HEADERS([endian.h sys/endian.h libkern/OSByteOrder.h]) + AC_C_BIGENDIAN + + AH_TEMPLATE([CUSTOM_ENDIAN_HEADER], [The system header to include for endian conversions.]) + AH_TEMPLATE([custom_ntohll], [Convert 64-bit integer from network to host byte order.]) + AH_TEMPLATE([custom_htonll], [Convert 64-bit integer from host to network byte order.]) + + dnl 1. Initialize our header variable tracking + endian_header_file='' + + dnl 2. Test if native be64toh works natively via (Standard Linux/glibc) + AC_MSG_CHECKING([for native be64toh via endian.h]) + AC_LINK_IFELSE([AC_LANG_SOURCE([ + #include + #ifdef HAVE_ENDIAN_H + # include + #endif + int main() { uint64_t x = be64toh(1); return 0; } + ])], + [has_native_be64=yes; endian_header_file=''], + [has_native_be64=no] + ) + AC_MSG_RESULT([$has_native_be64]) + + dnl 3. If missing, test if it works via (True BSD systems like FreeBSD) + if test "$has_native_be64" = "no"; then + AC_MSG_CHECKING([for native be64toh via sys/endian.h]) + AC_LINK_IFELSE([AC_LANG_SOURCE([ + #include + #ifdef HAVE_SYS_ENDIAN_H + # include + #endif + int main() { uint64_t x = be64toh(1); return 0; } ])], - [ - AC_MSG_RESULT(none needed) - ], [ - AC_DEFINE(USE_ALIGNED, 1, Require byte alignment) - AC_MSG_RESULT(required) - ]) + [has_native_be64=yes; endian_header_file=''], + [has_native_be64=no] + ) + AC_MSG_RESULT([$has_native_be64]) + fi + + dnl 4. Route definitions cleanly based on actual testing results + if test "$has_native_be64" = "yes"; then + dnl Linux or true BSD environment + AC_DEFINE_UNQUOTED([CUSTOM_ENDIAN_HEADER], [$endian_header_file], [The header containing native endian macros.]) + AC_DEFINE([custom_ntohll(x)], [(be64toh(x))], [Use native platform be64toh]) + AC_DEFINE([custom_htonll(x)], [(htobe64(x))], [Use native platform htobe64]) + else + dnl Fallback block: Check if we are on macOS using Apple's optimized hardware libraries + if test "$ac_cv_header_libkern_OSByteOrder_h" = "yes"; then + AC_DEFINE([CUSTOM_ENDIAN_HEADER], [], [The header containing native endian macros.]) + AC_DEFINE([custom_ntohll(x)], [(OSSwapBigToHostInt64(x))], [Map missing be64toh to macOS native swap]) + AC_DEFINE([custom_htonll(x)], [(OSSwapHostToBigInt64(x))], [Map missing htobe64 to macOS native swap]) + else + dnl Fallback for platforms with no built-in architecture macros (compiler built-ins) + AC_DEFINE([CUSTOM_ENDIAN_HEADER], [], [The header containing native endian macros.]) + if test "$ac_cv_c_bigendian" = "yes"; then + AC_DEFINE([custom_ntohll(x)], [((uint64_t)(x))], [Fallback 64-bit conversion.]) + AC_DEFINE([custom_htonll(x)], [((uint64_t)(x))], [Fallback 64-bit conversion.]) + else + AC_DEFINE([custom_ntohll(x)], [(__builtin_bswap64((uint64_t)(x)))], [Fallback 64-bit conversion.]) + AC_DEFINE([custom_htonll(x)], [(__builtin_bswap64((uint64_t)(x)))], [Fallback 64-bit conversion.]) + fi + fi + fi ]) -AC_DEFUN([TORRENT_ENABLE_ALIGNED], [ - AC_ARG_ENABLE(aligned, - AS_HELP_STRING([--enable-aligned], - [enable alignment safe code [[default=check]]]), - [ - if test "$enableval" = "yes"; then - AC_DEFINE(USE_ALIGNED, 1, Require byte alignment) - fi - ],[ - TORRENT_CHECK_ALIGNED - ]) -]) - - -AC_DEFUN([TORRENT_DISABLE_INSTRUMENTATION], [ +AC_DEFUN([TORRENT_ENABLE_INSTRUMENTATION], [ AC_MSG_CHECKING([if instrumentation should be included]) AC_ARG_ENABLE(instrumentation, - AS_HELP_STRING([--disable-instrumentation], - [disable instrumentation [[default=enabled]]]), + AS_HELP_STRING([--enable-instrumentation], + [enable instrumentation [[default=disabled]]]), [ if test "$enableval" = "yes"; then AC_DEFINE(LT_INSTRUMENTATION, 1, enable instrumentation) - AC_MSG_RESULT(yes) + AC_MSG_RESULT(yes) else - AC_MSG_RESULT(no) + AC_MSG_RESULT(no) fi ],[ - AC_DEFINE(LT_INSTRUMENTATION, 1, enable instrumentation) - AC_MSG_RESULT(yes) + AC_MSG_RESULT(no) ]) ]) -AC_DEFUN([TORRENT_ENABLE_INTERRUPT_SOCKET], [ - AC_ARG_ENABLE(interrupt-socket, - AS_HELP_STRING([--enable-interrupt-socket], - [enable interrupt socket [[default=no]]]), - [ - if test "$enableval" = "yes"; then - AC_DEFINE(USE_INTERRUPT_SOCKET, 1, Use interrupt socket instead of pthread_kill) - fi - ] - ) +AC_DEFUN([TORRENT_ENABLE_CUSTOM_STACK_SIZE], [ + AC_ARG_ENABLE([pthread-setstacksize], + [AS_HELP_STRING([--enable-pthread-setstacksize], [explicitly set pthread stack size (auto-enabled for musl)])], + [enable_pthread_setstacksize=$enableval], + [enable_pthread_setstacksize=auto]) + + AC_CANONICAL_HOST + if test "x$enable_pthread_setstacksize" = "xauto"; then + case "$host" in + *-musl*) + enable_pthread_setstacksize=yes + ;; + *) + enable_pthread_setstacksize=no + ;; + esac + fi + + if test "x$enable_pthread_setstacksize" = "xyes"; then + AC_DEFINE([USE_PTHREAD_SETSTACKSIZE], [1], [Use explicit pthread stack size]) + AC_DEFINE([DEFAULT_PTHREAD_STACKSIZE], [(8 * 1024 * 1024)], [Default pthread stack size in bytes]) + fi ]) + AC_DEFUN([TORRENT_DISABLE_IPV6], [ AC_ARG_ENABLE(ipv6, AS_HELP_STRING([--enable-ipv6],