From 4ff9bb184ea3bd35299674f13d4eb8ae57cc1d8d Mon Sep 17 00:00:00 2001 From: Lukas Fittl Date: Mon, 1 Jan 2024 10:48:55 -0800 Subject: [PATCH] Keep pg_config overrides in separate pg_config_overrides.h file We've previously managed these in the Makefile inline, but that is very hard to read, and not necessary, since we can simply concatenate the override file to pg_config.h during the source extraction process. --- Makefile | 47 ++--------------------------- scripts/pg_config_overrides.h | 52 ++++++++++++++++++++++++++++++++ src/postgres/include/pg_config.h | 18 ++++++++++- 3 files changed, 71 insertions(+), 46 deletions(-) create mode 100644 scripts/pg_config_overrides.h diff --git a/Makefile b/Makefile index c49e587f..2d80dc21 100644 --- a/Makefile +++ b/Makefile @@ -127,54 +127,11 @@ $(PGDIR): cd $(PGDIR); make -C src/port pg_config_paths.h cd $(PGDIR); make -C src/backend generated-headers cd $(PGDIR); make -C src/backend parser-recursive # Triggers copying of includes to where they belong, as well as generating gram.c/scan.c - # This causes compatibility problems on some Linux distros, with "xlocale.h" not being available - echo "#undef HAVE_LOCALE_T" >> $(PGDIR)/src/include/pg_config.h - echo "#undef LOCALE_T_IN_XLOCALE" >> $(PGDIR)/src/include/pg_config.h - echo "#undef WCSTOMBS_L_IN_XLOCALE" >> $(PGDIR)/src/include/pg_config.h - # Support 32-bit systems without reconfiguring - echo "#undef PG_INT128_TYPE" >> $(PGDIR)/src/include/pg_config.h - # Support gcc earlier than 4.6.0 without reconfiguring - echo "#undef HAVE__STATIC_ASSERT" >> $(PGDIR)/src/include/pg_config.h # Avoid problems with static asserts echo "#undef StaticAssertDecl" >> $(PGDIR)/src/include/c.h echo "#define StaticAssertDecl(condition, errmessage)" >> $(PGDIR)/src/include/c.h - # Avoid dependency on execinfo (requires extra library on musl-libc based systems) - echo "#undef HAVE_EXECINFO_H" >> $(PGDIR)/src/include/pg_config.h - echo "#undef HAVE_BACKTRACE_SYMBOLS" >> $(PGDIR)/src/include/pg_config.h - # Avoid dependency on hardware popcount instructions (POPQNTQ) on x86 - echo "#undef HAVE_X86_64_POPCNTQ" >> $(PGDIR)/src/include/pg_config.h - # Avoid dependency on cpuid.h (only supported on x86 systems) - echo "#undef HAVE__GET_CPUID" >> $(PGDIR)/src/include/pg_config.h - # Avoid CRC extension usage to ensure we are not architecture-dependent - echo "#undef USE_ARMV8_CRC32C" >> $(PGDIR)/src/include/pg_config.h - echo "#undef USE_SSE42_CRC32C_WITH_RUNTIME_CHECK" >> $(PGDIR)/src/include/pg_config.h - # Ensure we don't fail on systems that have strchrnul support (FreeBSD and NetBSD) - echo "#include " >> $(PGDIR)/src/include/pg_config.h - echo "#if defined(__FreeBSD__) || defined(__NetBSD__) || (defined(__GLIBC__) && ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 38) || __GLIBC__ > 2))" >> $(PGDIR)/src/include/pg_config.h - echo "#define HAVE_STRCHRNUL" >> $(PGDIR)/src/include/pg_config.h - echo "#endif" >> $(PGDIR)/src/include/pg_config.h - # Optionally support 32-bit - echo "#if defined(_WIN32) || __SIZEOF_POINTER__ == 4" >> $(PGDIR)/src/include/pg_config.h - echo "#undef ALIGNOF_DOUBLE" >> $(PGDIR)/src/include/pg_config.h - echo "#define ALIGNOF_DOUBLE 4" >> $(PGDIR)/src/include/pg_config.h - echo "#undef ALIGNOF_LONG" >> $(PGDIR)/src/include/pg_config.h - echo "#define ALIGNOF_LONG 4" >> $(PGDIR)/src/include/pg_config.h - echo "#define ALIGNOF_LONG_LONG_INT 4" >> $(PGDIR)/src/include/pg_config.h - echo "#undef ALIGNOF_PG_INT128_TYPE" >> $(PGDIR)/src/include/pg_config.h - echo "#undef HAVE_LONG_INT_64" >> $(PGDIR)/src/include/pg_config.h - echo "#define HAVE_LONG_LONG_INT_64 1" >> $(PGDIR)/src/include/pg_config.h - echo "#undef INT64_MODIFIER" >> $(PGDIR)/src/include/pg_config.h - echo "#define INT64_MODIFIER \"ll\"" >> $(PGDIR)/src/include/pg_config.h - echo "#undef PG_INT128_TYPE" >> $(PGDIR)/src/include/pg_config.h - echo "#undef PG_INT64_TYPE" >> $(PGDIR)/src/include/pg_config.h - echo "#define PG_INT64_TYPE long long int" >> $(PGDIR)/src/include/pg_config.h - echo "#undef SIZEOF_LONG" >> $(PGDIR)/src/include/pg_config.h - echo "#define SIZEOF_LONG 4" >> $(PGDIR)/src/include/pg_config.h - echo "#undef SIZEOF_SIZE_T" >> $(PGDIR)/src/include/pg_config.h - echo "#define SIZEOF_SIZE_T 4" >> $(PGDIR)/src/include/pg_config.h - echo "#undef SIZEOF_VOID_P" >> $(PGDIR)/src/include/pg_config.h - echo "#define SIZEOF_VOID_P 4" >> $(PGDIR)/src/include/pg_config.h - echo "#endif" >> $(PGDIR)/src/include/pg_config.h + # Add pg_config.h overrides + cat scripts/pg_config_overrides.h >> $(PGDIR)/src/include/pg_config.h extract_source: $(PGDIR) -@ $(RM) -rf ./src/postgres/ diff --git a/scripts/pg_config_overrides.h b/scripts/pg_config_overrides.h new file mode 100644 index 00000000..1a1c082f --- /dev/null +++ b/scripts/pg_config_overrides.h @@ -0,0 +1,52 @@ +/* This causes compatibility problems on some Linux distros, with "xlocale.h" not being available */ +#undef HAVE_LOCALE_T +#undef LOCALE_T_IN_XLOCALE +#undef WCSTOMBS_L_IN_XLOCALE + +/* Support gcc earlier than 4.6.0 and MSVC */ +#undef HAVE__STATIC_ASSERT + +/* Avoid dependency on execinfo (requires extra library on musl-libc based systems, not supported on Windows) */ +#undef HAVE_EXECINFO_H +#undef HAVE_BACKTRACE_SYMBOLS + +/* Avoid dependency on hardware popcount instructions (POPQNTQ) on x86 */ +#undef HAVE_X86_64_POPCNTQ + +/* Avoid dependency on cpuid.h (only supported on x86 systems) */ +#undef HAVE__GET_CPUID + +/* Avoid CRC extension usage to ensure we are not architecture-dependent */ +#undef USE_ARMV8_CRC32C +#undef USE_SSE42_CRC32C_WITH_RUNTIME_CHECK + +/* Ensure we do not fail on systems that have strchrnul support (FreeBSD, NetBSD and newer glibc) */ +#include +#if defined(__FreeBSD__) || defined(__NetBSD__) || (defined(__GLIBC__) && ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 38) || __GLIBC__ > 2)) +#define HAVE_STRCHRNUL +#endif + +/* 32-bit */ +#if defined(_WIN32) || __SIZEOF_POINTER__ == 4 +#undef ALIGNOF_DOUBLE +#define ALIGNOF_DOUBLE 4 +#undef ALIGNOF_LONG +#define ALIGNOF_LONG 4 +#define ALIGNOF_LONG_LONG_INT 4 +#undef ALIGNOF_PG_INT128_TYPE +#undef HAVE_LONG_INT_64 +#define HAVE_LONG_LONG_INT_64 1 +#undef INT64_MODIFIER +#define INT64_MODIFIER "ll" +#undef PG_INT128_TYPE +#undef PG_INT64_TYPE +#define PG_INT64_TYPE long long int +#undef SIZEOF_LONG +#define SIZEOF_LONG 4 +#undef SIZEOF_OFF_T +#define SIZEOF_OFF_T 4 +#undef SIZEOF_SIZE_T +#define SIZEOF_SIZE_T 4 +#undef SIZEOF_VOID_P +#define SIZEOF_VOID_P 4 +#endif diff --git a/src/postgres/include/pg_config.h b/src/postgres/include/pg_config.h index 33a03e50..aac5f600 100644 --- a/src/postgres/include/pg_config.h +++ b/src/postgres/include/pg_config.h @@ -826,21 +826,35 @@ /* Define to how the compiler spells `typeof'. */ /* #undef typeof */ +/* This causes compatibility problems on some Linux distros, with "xlocale.h" not being available */ #undef HAVE_LOCALE_T #undef LOCALE_T_IN_XLOCALE #undef WCSTOMBS_L_IN_XLOCALE -#undef PG_INT128_TYPE + +/* Support gcc earlier than 4.6.0 and MSVC */ #undef HAVE__STATIC_ASSERT + +/* Avoid dependency on execinfo (requires extra library on musl-libc based systems, not supported on Windows) */ #undef HAVE_EXECINFO_H #undef HAVE_BACKTRACE_SYMBOLS + +/* Avoid dependency on hardware popcount instructions (POPQNTQ) on x86 */ #undef HAVE_X86_64_POPCNTQ + +/* Avoid dependency on cpuid.h (only supported on x86 systems) */ #undef HAVE__GET_CPUID + +/* Avoid CRC extension usage to ensure we are not architecture-dependent */ #undef USE_ARMV8_CRC32C #undef USE_SSE42_CRC32C_WITH_RUNTIME_CHECK + +/* Ensure we do not fail on systems that have strchrnul support (FreeBSD, NetBSD and newer glibc) */ #include #if defined(__FreeBSD__) || defined(__NetBSD__) || (defined(__GLIBC__) && ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 38) || __GLIBC__ > 2)) #define HAVE_STRCHRNUL #endif + +/* 32-bit */ #if defined(_WIN32) || __SIZEOF_POINTER__ == 4 #undef ALIGNOF_DOUBLE #define ALIGNOF_DOUBLE 4 @@ -857,6 +871,8 @@ #define PG_INT64_TYPE long long int #undef SIZEOF_LONG #define SIZEOF_LONG 4 +#undef SIZEOF_OFF_T +#define SIZEOF_OFF_T 4 #undef SIZEOF_SIZE_T #define SIZEOF_SIZE_T 4 #undef SIZEOF_VOID_P