From b6322bad1b59680c915d2dc8636d5c2310e9a4f9 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 7 Nov 2019 15:56:22 +0100 Subject: [PATCH 1/2] Generate pg_config.h from pg_config.h.in on Windows --- src/tools/msvc/Solution.pm | 224 ++++++++++++++++++++++++++++--------- 1 file changed, 174 insertions(+), 50 deletions(-) diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm index ac626dfa53..b129c649ea 100644 --- a/src/tools/msvc/Solution.pm +++ b/src/tools/msvc/Solution.pm @@ -8,6 +8,7 @@ package Solution; use Carp; use strict; use warnings; +use File::Basename; use VSObjectFactory; no warnings qw(redefine); ## no critic @@ -20,7 +21,6 @@ sub _new projects => {}, options => $options, numver => '', - strver => '', VisualStudioVersion => undef, MinimumVisualStudioVersion => undef, vcver => undef, @@ -140,16 +140,22 @@ sub GenerateFiles { my $self = shift; my $bits = $self->{platform} eq 'Win32' ? 32 : 64; + my $package_name; + my $package_version; + my $package_bugreport; # Parse configure.in to get version numbers open(my $c, '<', "configure.in") || confess("Could not open configure.in for reading\n"); while (<$c>) { - if (/^AC_INIT\(\[PostgreSQL\], \[([^\]]+)\]/) + if (/^AC_INIT\(\[([^\]]+)\], \[([^\]]+)\], \[([^\]]+)\]/) { - $self->{strver} = $1; - if ($self->{strver} !~ /^(\d+)(?:\.(\d+))?/) + $package_name = $1; + $package_version = $2; + $package_bugreport = $3; + + if ($package_version !~ /^(\d+)(?:\.(\d+))?/) { confess "Bad format of version: $self->{strver}\n"; } @@ -159,7 +165,8 @@ sub GenerateFiles } close($c); confess "Unable to parse configure.in for all variables!" - if ($self->{strver} eq '' || $self->{numver} eq ''); + if ($package_name eq '' || $package_version eq '' || $self->{numver} eq '' || + $package_bugreport eq ''); if (IsNewer("src/include/pg_config_os.h", "src/include/port/win32.h")) { @@ -167,89 +174,206 @@ sub GenerateFiles copyFile("src/include/port/win32.h", "src/include/pg_config_os.h"); } - if (IsNewer("src/include/pg_config.h", "src/include/pg_config.h.win32")) + if (IsNewer("src/include/pg_config.h", "src/include/pg_config.h.in")) { print "Generating pg_config.h...\n"; - open(my $i, '<', "src/include/pg_config.h.win32") - || confess "Could not open pg_config.h.win32\n"; + open(my $i, '<', "src/include/pg_config.h.in") + || confess "Could not open pg_config.h.in\n"; open(my $o, '>', "src/include/pg_config.h") || confess "Could not write to pg_config.h\n"; + + print $o "/* src/include/pg_config.h. Generated from pg_config.h.in by ", basename(__FILE__), ". */\n"; + + my %define; + + $define{PACKAGE_BUGREPORT} = qq{"$package_bugreport"}; + $define{PACKAGE_NAME} = qq{"$package_name"}; + $define{PACKAGE_STRING} = qq{"$package_name $package_version"}; + $define{PACKAGE_TARNAME} = lc $define{PACKAGE_NAME}; + $define{PACKAGE_VERSION} = qq{"$package_version"}; + my $extraver = $self->{options}->{extraver}; $extraver = '' unless defined $extraver; - while (<$i>) - { - s{PG_VERSION "[^"]+"}{PG_VERSION "$self->{strver}$extraver"}; - s{PG_VERSION_NUM \d+}{PG_VERSION_NUM $self->{numver}}; - s{PG_VERSION_STR "[^"]+"}{PG_VERSION_STR "PostgreSQL $self->{strver}$extraver, compiled by Visual C++ build " CppAsString2(_MSC_VER) ", $bits-bit"}; - print $o $_; - } - print $o "#define PG_MAJORVERSION \"$self->{majorver}\"\n"; - print $o "/* defines added by config steps */\n"; - print $o "#ifndef IGNORE_CONFIGURED_SETTINGS\n"; - print $o "#define USE_ASSERT_CHECKING 1\n" + $define{PG_VERSION} = qq{"$package_version$extraver"}; + $define{PG_VERSION_NUM} = $self->{numver}; + $define{PG_VERSION_STR} = qq{"PostgreSQL $package_version$extraver, compiled by Visual C++ build " CppAsString2(_MSC_VER) ", $bits-bit"}; + + $define{PG_MAJORVERSION} = qq{"$self->{majorver}"}; + $define{USE_ASSERT_CHECKING} = 1 if ($self->{options}->{asserts}); - print $o "#define USE_LDAP 1\n" if ($self->{options}->{ldap}); - print $o "#define HAVE_LIBZ 1\n" if ($self->{options}->{zlib}); - print $o "#define ENABLE_NLS 1\n" if ($self->{options}->{nls}); - - print $o "#define BLCKSZ ", 1024 * $self->{options}->{blocksize}, - "\n"; - print $o "#define RELSEG_SIZE ", - (1024 / $self->{options}->{blocksize}) * - $self->{options}->{segsize} * 1024, "\n"; - print $o "#define XLOG_BLCKSZ ", - 1024 * $self->{options}->{wal_blocksize}, "\n"; + $define{USE_LDAP} = 1 if ($self->{options}->{ldap}); + $define{HAVE_LIBZ} = 1 if ($self->{options}->{zlib}); + $define{ENABLE_NLS} = 1 if ($self->{options}->{nls}); + + $define{BLCKSZ} = 1024 * $self->{options}->{blocksize}; + $define{RELSEG_SIZE} = ((1024 / $self->{options}->{blocksize}) * + $self->{options}->{segsize} * 1024); + $define{XLOG_BLCKSZ} = 1024 * $self->{options}->{wal_blocksize}; if ($self->{options}->{uuid}) { - print $o "#define HAVE_UUID_OSSP\n"; - print $o "#define HAVE_UUID_H\n"; + $define{HAVE_UUID_OSSP} = 1; + $define{HAVE_UUID_H} = 1; } if ($self->{options}->{xml}) { - print $o "#define HAVE_LIBXML2\n"; - print $o "#define USE_LIBXML\n"; + $define{HAVE_LIBXML2} = 1; + $define{USE_LIBXML} = 1; } if ($self->{options}->{xslt}) { - print $o "#define HAVE_LIBXSLT\n"; - print $o "#define USE_LIBXSLT\n"; + $define{HAVE_LIBXSLT} = 1; + $define{USE_LIBXSLT} = 1; } if ($self->{options}->{gss}) { - print $o "#define ENABLE_GSS 1\n"; + $define{ENABLE_GSS} = 1; } if ($self->{options}->{openssl}) { - print $o "#define USE_OPENSSL 1\n"; + $define{USE_OPENSSL} = 1; my ($digit1, $digit2, $digit3) = $self->GetOpenSSLVersion(); # More symbols are needed with OpenSSL 1.1.0 and above. if ($digit1 >= '1' && $digit2 >= '1' && $digit3 >= '0') { - print $o "#define HAVE_ASN1_STRING_GET0_DATA 1\n"; - print $o "#define HAVE_BIO_GET_DATA 1\n"; - print $o "#define HAVE_BIO_METH_NEW 1\n"; - print $o "#define HAVE_OPENSSL_INIT_SSL 1\n"; + $define{HAVE_ASN1_STRING_GET0_DATA} = 1; + $define{HAVE_BIO_GET_DATA} = 1; + $define{HAVE_BIO_METH_NEW} = 1; + $define{HAVE_OPENSSL_INIT_SSL} = 1; } } if ($self->{options}->{icu}) { - print $o "#define USE_ICU 1\n"; + $define{USE_ICU} = 1; + } + my $port = $self->{options}->{"--with-pgport"} || 5432; + $define{DEF_PGPORT} = $port; + $define{DEF_PGPORT_STR} = qq{"$port"}; + $define{PG_KRB_SRVNAM} = qq{"postgres"}; + + $define{ACCEPT_TYPE_ARG1} = 'unsigned int'; + $define{ACCEPT_TYPE_ARG2} = 'struct sockaddr *'; + $define{ACCEPT_TYPE_ARG3} = 'int'; + $define{ACCEPT_TYPE_RETURN} = 'unsigned int PASCAL'; + $define{ALIGNOF_DOUBLE} = 8; + $define{ALIGNOF_INT} = 4; + $define{ALIGNOF_LONG} = 4; + $define{ALIGNOF_LONG_LONG_INT} = 8; + $define{ALIGNOF_SHORT} = 2; + $define{ENABLE_THREAD_SAFETY} = 1; + $define{FLEXIBLE_ARRAY_MEMBER} = '/**/'; + $define{HAVE_DECL_FDATASYNC} = 0; + $define{HAVE_DECL_F_FULLFSYNC} = 0; + $define{HAVE_DECL_LLVMGETHOSTCPUNAME} = 0; + $define{HAVE_DECL_LLVMGETHOSTCPUFEATURES} = 0; + $define{HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN} = 0; + $define{HAVE_DECL_RTLD_GLOBAL} = 0; + $define{HAVE_DECL_RTLD_NOW} = 0; + $define{HAVE_DECL_STRNLEN} = 1; + $define{HAVE_DECL_STRTOLL} = 1; + $define{HAVE_DECL_STRTOULL} = 1; + $define{INT64_MODIFIER} = qq{"ll"}; + $define{MAXIMUM_ALIGNOF} = 8; + $define{MEMSET_LOOP_LIMIT} = 1024; + $define{PG_INT64_TYPE} = 'long long int'; + $define{SIZEOF_BOOL} = 1; + $define{SIZEOF_LONG} = 4; + $define{inline} = '__inline'; + $define{pg_restrict} = '__restrict'; + + if ($bits == 32) + { + $define{SIZEOF_SIZE_T} = 4; + $define{SIZEOF_VOID_P} = 4; + } + else + { + $define{SIZEOF_SIZE_T} = 8; + $define{SIZEOF_VOID_P} = 8; } - if (my $port = $self->{options}->{"--with-pgport"}) + + my @simple_defines = qw( + HAVE_ATOMICS + HAVE_FSEEKO + HAVE_FUNCNAME__FUNCTION + HAVE_INT_TIMEZONE + HAVE_IPV6 + HAVE_ISINF + HAVE_LOCALE_T + HAVE_LONG_LONG_INT_64 + HAVE_MBSTOWCS_L + HAVE_MEMMOVE + HAVE_MEMORY_H + HAVE_MINIDUMP_TYPE + HAVE_STRNLEN + HAVE_RINT + HAVE_SPINLOCKS + HAVE_STDBOOL_H + HAVE_STDLIB_H + HAVE_STRING_H + HAVE_STRTOF + HAVE_STRTOLL + HAVE_STRTOULL + HAVE_STRUCT_ADDRINFO + HAVE_STRUCT_SOCKADDR_STORAGE + HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY + HAVE_SYMLINK + HAVE_SYS_STAT_H + HAVE_SYS_TYPES_H + HAVE_UNISTD_H + HAVE_UTIME + HAVE_UTIME_H + HAVE_WCHAR_H + HAVE_WCSTOMBS_L + HAVE_WCTYPE_H + HAVE_X509_GET_SIGNATURE_NID + HAVE__CONFIGTHREADLOCALE + HAVE__CPUID + PG_USE_STDBOOL + STDC_HEADERS + USE_SSE42_CRC32C_WITH_RUNTIME_CHECK + USE_WIN32_RANDOM + USE_WIN32_SEMAPHORES + USE_WIN32_SHARED_MEMORY + ); + + foreach my $k (@simple_defines) + { + $define{$k} = 1; + } + + while (<$i>) { - print $o "#undef DEF_PGPORT\n"; - print $o "#undef DEF_PGPORT_STR\n"; - print $o "#define DEF_PGPORT $port\n"; - print $o "#define DEF_PGPORT_STR \"$port\"\n"; + if (m/^#(\s*)undef\s+(\w+)/) + { + my $ws = $1; + my $macro = $2; + if (exists $define{$macro}) + { + print $o "#${ws}define $macro ", $define{$macro}, "\n"; + } + else + { + print $o "/* #${ws}undef $macro */\n"; + } + delete $define{$macro}; + } + else + { + print $o $_; + } } + print $o "\n"; print $o "#define VAL_CONFIGURE \"" . $self->GetFakeConfigure() . "\"\n"; - print $o "#endif /* IGNORE_CONFIGURED_SETTINGS */\n"; close($o); close($i); + if (scalar(keys %define) > 0) + { + croak "unused defines: @{[%define]}"; + } } if (IsNewer( @@ -581,7 +705,7 @@ EOF open(my $o, '>', "doc/src/sgml/version.sgml") || croak "Could not write to version.sgml\n"; print $o <{strver}"> + {majorver}"> EOF close($o); -- 2.24.0