diff --git a/CMakeLists.txt b/CMakeLists.txt index 0955280c..e7976ac7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -291,7 +291,11 @@ add_mdbx_option(MDBX_ALLOY_BUILD "Build MDBX library as single object file" ON) add_mdbx_option(MDBX_TXN_CHECKOWNER "Checking transaction matches the calling thread inside libmdbx's API" ON) add_mdbx_option(MDBX_TXN_CHECKPID "Paranoid checking PID inside libmdbx's API" AUTO) mark_as_advanced(MDBX_TXN_CHECKPID) -if(APPLE) +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + add_mdbx_option(MDBX_DISABLE_GNU_SOURCE "Don't use nonstandard GNU/Linux extension functions" OFF) + mark_as_advanced(MDBX_DISABLE_GNU_SOURCE) +endif() +if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") add_mdbx_option(MDBX_OSX_SPEED_INSTEADOF_DURABILITY "Disable use fcntl(F_FULLFSYNC) in favor of speed" OFF) mark_as_advanced(MDBX_OSX_SPEED_INSTEADOF_DURABILITY) endif() diff --git a/GNUmakefile b/GNUmakefile index 46d55b1d..d0fa4c6a 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -20,7 +20,7 @@ suffix ?= CC ?= gcc LD ?= ld -MDBX_OPTIONS ?= -D_GNU_SOURCE=1 -DNDEBUG=1 +MDBX_OPTIONS ?= -DNDEBUG=1 CFLAGS ?= -O2 -g3 -Wall -Werror -Wextra -ffunction-sections -fPIC -fvisibility=hidden -std=gnu11 -pthread # LY: '--no-as-needed,-lrt' for ability to built with modern glibc, but then run with the old diff --git a/src/elements/config.h.in b/src/elements/config.h.in index 5eb1e716..fdd3cac1 100644 --- a/src/elements/config.h.in +++ b/src/elements/config.h.in @@ -28,6 +28,7 @@ /* POSIX */ #cmakedefine01 MDBX_USE_ROBUST #cmakedefine01 MDBX_USE_OFDLOCKS +#cmakedefine01 MDBX_DISABLE_GNU_SOURCE /* Simulate "AUTO" values of tristate options */ #cmakedefine MDBX_TXN_CHECKPID_AUTO diff --git a/src/elements/core.c b/src/elements/core.c index 50e69016..d06b883a 100644 --- a/src/elements/core.c +++ b/src/elements/core.c @@ -15628,6 +15628,11 @@ __dll_export " MDBX_TXN_CHECKPID=" STRINGIFY(MDBX_TXN_CHECKPID) " MDBX_TXN_CHECKOWNER=" STRINGIFY(MDBX_TXN_CHECKOWNER) " MDBX_64BIT_ATOMIC=" STRINGIFY(MDBX_64BIT_ATOMIC) +#ifdef _GNU_SOURCE + " _GNU_SOURCE=YES" +#else + " _GNU_SOURCE=NO" +#endif /* _GNU_SOURCE */ #ifdef __APPLE__ " MDBX_OSX_SPEED_INSTEADOF_DURABILITY=" STRINGIFY(MDBX_OSX_SPEED_INSTEADOF_DURABILITY) #endif /* MacOS */ diff --git a/src/elements/internals.h b/src/elements/internals.h index 7e83b0a5..7aa715d4 100644 --- a/src/elements/internals.h +++ b/src/elements/internals.h @@ -49,6 +49,15 @@ # define MDBX_INTERNAL_VAR extern #endif /* MDBX_ALLOY */ +#ifndef MDBX_DISABLE_GNU_SOURCE +#define MDBX_DISABLE_GNU_SOURCE 0 +#endif +#if MDBX_DISABLE_GNU_SOURCE +#undef _GNU_SOURCE +#elif defined(__linux__) || defined(__gnu_linux__) +#define _GNU_SOURCE +#endif + /*----------------------------------------------------------------------------*/ /* Should be defined before any includes */ diff --git a/src/elements/osal.c b/src/elements/osal.c index 3cd139c4..a8c8fe07 100644 --- a/src/elements/osal.c +++ b/src/elements/osal.c @@ -1275,10 +1275,7 @@ retry_mapview:; return rc; #else if (limit != map->length) { -#if defined(_GNU_SOURCE) && \ - !(defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ - defined(__BSD__) || defined(__NETBSD__) || defined(__bsdi__) || \ - defined(__DragonFly__) || defined(__APPLE__) || defined(__MACH__)) +#if defined(_GNU_SOURCE) && (defined(__linux__) || defined(__gnu_linux__)) void *ptr = mremap(map->address, map->length, limit, /* LY: in case changing the mapping size calling code must guarantees the absence of competing threads, and @@ -1292,7 +1289,7 @@ retry_mapview:; map->length = limit; #else return MDBX_RESULT_TRUE; -#endif /* mremap() <= _GNU_SOURCE && !__FreeBSD__ */ +#endif /* _GNU_SOURCE && __linux__ */ } return (flags & MDBX_RDONLY) ? MDBX_SUCCESS : mdbx_ftruncate(map->fd, size); #endif diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index 2724a11a..5cb796d0 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -13,7 +13,7 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # the RPATH to be used when installing, but only if it's not a system directory list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir) if(isSystemDir EQUAL -1) - if(APPLE) + if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") set(CMAKE_INSTALL_RPATH "@executable_path/../lib") else() set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib")