# Platform checks to generate pg_config.h from pg_config.h.in
include ( CheckFunctionExists )
include ( CheckLibraryExists )
include ( CheckSymbolExists )
include ( CheckTypeSize )
include ( CheckIncludeFiles )

# Hard settings
set ( ACCEPT_TYPE_ARG1 "int" )
set ( ACCEPT_TYPE_ARG2 "struct sockaddr *" )
set ( ACCEPT_TYPE_ARG3 "socklen_t" )
set ( ACCEPT_TYPE_RETURN "int" )

set ( BLCKSZ 8192 )
set ( DEF_PGPORT 5432 )
set ( DEF_PGPORT_STR "\"${DEF_PGPORT}\"" )
option ( ENABLE_GSS "Define to build with GSSAPI support." 0 )
option ( ENABLE_NLS "Define to 1 if you want National Language Support." 0 )
option ( ENABLE_THREAD_SAFETY "Define to 1 to build client libraries as thread-safe code." 1 )
option ( KRB5 "Define to build with Kerberos 5 support." 0 )
set ( FLEXIBLE_ARRAY_MEMBER "/**/" )
set ( FLOAT4PASSBYVAL true )
set ( FLOAT8PASSBYVAL true )
set ( GETPWUID_R_5ARG "/**/" )
#set ( GETTIMEOFDAY_1ARG 1 )
set ( HAVE_FUNCNAME__FUNC 1 )
#set ( HAVE_FUNCNAME__FUNCTION 1 )
set ( HAVE_GCC_INT_ATOMICS 1 )
set ( HAVE_IPV6 1 )
#set ( HAVE_KRB5_ERROR_E_DATA 1 )
#set ( HAVE_KRB5_ERROR_TEXT_DATA )
#set ( HAVE_KRB5_FREE_UNPARSED_NAME )
#set ( HAVE_KRB5_TICKET_CLIENT )
#set ( HAVE_KRB5_TICKET_ENC_PART2 )
set ( HAVE_LIBM 1 )
#set ( HAVE_LIBPAM 1 )
set ( HAVE_LIBREADLINE 1 )
#set ( HAVE_LIBSELINUX 1 )
#set ( HAVE_LIBSSL 1 )
#set ( HAVE_LIBWLDAP32 1 )
#set ( HAVE_LIBXML2 1 )
#set ( HAVE_LIBXSLT 1 )
set ( HAVE_LIBZ 1 )
#set ( HAVE_LL_CONSTANTS 1 )
set ( HAVE_POSIX_SIGNALS "/**/" )
#set ( HAVE_PPC_LWARX_MUTEX_HINT 1 )
set ( HAVE_PTHREAD 1 )
set ( HAVE_STRINGIZE 1 )
set ( HAVE_SYSLOG 1 )
set ( INT64_FORMAT "\"%ld\"" )
set ( LOCALE_T_IN_XLOCALE 1 )
set ( MAXIMUM_ALIGNOF 8 )
set ( MEMSET_LOOP_LIMIT 1024 )
set ( PACKAGE_BUGREPORT "\"http://github.com/LuaDist/Repository\"" )
set ( PACKAGE_NAME "\"PostgreSQL\"" )
set ( PACKAGE_STRING "\"PostgreSQL ${DIST_VERSION}\"" )
set ( PACKAGE_TARNAME "\"${DIST_NAME}\"" )
set ( PACKAGE_VERSION "\"${DIST_VERSION}\"" )
set ( PG_KRB_SRVNAM "\"postgres\"" )
set ( PG_MAJORVERSION "\"9.2"\" )
set ( PG_VERSION "\"${DIST_VERSION}\"" )
set ( PG_VERSION_NUM 90201 )
set ( PG_VERSION_STR "\"PostgreSQL ${DIST_VERSION} LuaDist\"" )
#set ( PROFILE_PID_DIR 1 )
#set ( PTHREAD_CREATE_JOINABLE "" )
set ( RELSEG_SIZE 131072 )
set ( STDC_HEADERS 1 )
set ( STRERROR_R_INT "/**/" )
#set ( TM_IN_SYS_TIME 1 )
set ( UINT64_FORMAT "\"%lu\"" )
#set ( USE_ASSERT_CHECKING 1 )
#set ( USE_BONJOUR 1 )
option ( USE_FLOAT4_BYVAL "Define to 1 if you want float4 values to be passed by value." 1 )
option ( USE_FLOAT8_BYVAL "Define to 1 if you want 64-bit integer timestamp and interval support." 1 )
option ( USE_LDAP "Define to 1 to build with LDAP support." 0 )
option ( USE_LIBXML "Define to 1 to build with XML support." 0 )
option ( USE_LIBXSLT "Define to 1 to use XSLT support when building contrib/xml2." 0 )
set ( USE_NAMED_POSIX_SEMAPHORES 1 )
option ( USE_PAM "Define to 1 to build with PAM support." 0 )
#set ( USE_REPL_SNPRINTF 1 )
option ( USE_SSL "Define to build with (Open)SSL support." 0 )
set ( USE_SYSV_SEMAPHORES 1 )
set ( USE_SYSV_SHARED_MEMORY 1 )
#set ( USE_UNNAMED_POSIX_SEMAPHORES 1 )
#set ( USE_WIN32_SEMAPHORES 1 ) 
#set ( USE_WIN32_SHARED_MEMORY 1 )
set ( XLOG_BLCKSZ 8192 )
set ( XLOG_SEG_SIZE "(16 * 1024 * 1024)" )
#set ( _FILE_OFFSET_BITS )
#set ( _LARGEFILE_SOURCE )
#set ( _LARGE_FILES )
set ( HAVE_STRUCT_ADDRINFO 1 )
set ( HAVE_STRUCT_OPTION 1 )
set ( HAVE_STRUCT_CMSGCRED )
set ( HAVE_STRUCT_SOCKADDR_SA_LEN 1 )
set ( HAVE_STRUCT_SOCKADDR_STORAGE 1 )
set ( HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1 )
set ( HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1 )
#set ( HAVE_STRUCT_SOCKADDR_STORAGE_SS___FAMILY 1 )
#set ( HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN 1 )
set ( HAVE_STRUCT_TM_TM_ZONE 1 )
set ( HAVE_TZNAME 1 )
set ( HAVE_UNION_SEMUN 1 )
set ( USE_INLINE 1 )
option ( USE_INTEGER_DATETIMES "Define to 1 if you want 64-bit integer timestamp and interval support." 1 )
  
# Types
check_type_size ( double SIZEOF_DOUBLE )
if ( SIZEOF_DOUBLE )
  set ( ALIGNOF_DOUBLE ${SIZEOF_DOUBLE} )
endif ()

check_type_size ( int SIZEOF_INT )
if ( SIZEOF_INT )
  set ( ALIGNOF_INT ${SIZEOF_INT} )
endif ()

check_type_size ( long SIZEOF_LONG )
if ( SIZEOF_LONG )
  set ( ALIGNOF_LONG ${SIZEOF_LONG} )
endif ()

check_type_size ( "long long int" SIZEOF_LONG_LONG_INT )
if ( SIZEOF_LONG_LONG_INT )
  set ( ALIGNOF_LONG_LONG_INT ${SIZEOF_LONG_LONG_INT} )
endif ()

check_type_size ( short SIZEOF_SHORT )
if ( SIZEOF_SHORT )
  set ( ALIGNOF_SHORT ${SIZEOF_SHORT} )
endif ()

check_type_size ( int64 HAVE_INT64 )
check_type_size ( int8 HAVE_INT8 )
check_type_size ( intptr_t HAVE_INTPTR_T )
check_type_size ( locale_t HAVE_LOCALE_T )
check_type_size ( int64 HAVE_INT64 )
check_type_size ( "long int" HAVE_LONG_INT_64 )
check_type_size ( int64 HAVE_INT64 )
check_type_size ( "long long int" HAVE_LONG_LONG_INT )
set ( HAVE_LONG_LONG_INT_64 ${HAVE_LONG_LONG_INT} )
check_type_size ( MINIDUMP_TYPE HAVE_MINIDUMP_TYPE )
check_type_size ( sig_atomic_t HAVE_SIG_ATOMIC_T )
#check_type_size ( "struct addrinfo" HAVE_STRUCT_ADDRINFO )
#check_type_size ( "struct cmsgcred" HAVE_STRUCT_CMSGCRED )
#check_type_size ( "struct option" HAVE_STRUCT_OPTION )
#check_type_size ( "struct sockaddr" HAVE_STRUCT_SOCKADDR_SA_LEN )
#check_type_size ( "struct sockaddr_storage" HAVE_STRUCT_SOCKADDR_STORAGE )
#check_type_size ( "struct sockaddr_storage.ss_family" HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY )
#check_type_size ( "struct sockaddr_storage.ss_len" HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN )
#check_type_size ( "struct sockaddr_storage.__ss_family" HAVE_STRUCT_SOCKADDR_STORAGE_SS___FAMILY )
#check_type_size ( "struct sockaddr_storage.__ss_len" HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN )
#check_type_size ( "struct tm.tm_zone" HAVE_STRUCT_TM_TM_ZONE )
set ( HAVE_TM_ZONE ${HAVE_STRUCT_TM_TM_ZONE} )
check_type_size ( uint64 HAVE_UINT64 )
check_type_size ( uint8 HAVE_UINT8 )
check_type_size ( uintptr_t HAVE_UINTPTR_T )
#check_type_size ( "union semun" HAVE_UNION_SEMUN )
check_type_size ( off_t SIZEOF_OFF_T )
check_type_size ( size_t SIZEOF_SIZE_T )
check_type_size ( "void *" SIZEOF_VOID_P )

# Headers
check_include_files ( crtdefs.h HAVE_CRTDEFS_H )
check_include_files ( crypt.h HAVE_CRYPT_H )
check_include_files ( dld.h HAVE_DLD_H )
check_include_files ( "editline/history.h" HAVE_EDITLINE_HISTORY_H )
check_include_files ( "editline/readline.h" HAVE_EDITLINE_READLINE_H )
check_include_files ( fp_class.h HAVE_FP_CLASS_H )
check_include_files ( getopt.h HAVE_GETOPT_H )
check_include_files ( gssapi/gssapi.h HAVE_GSSAPI_GSSAPI_H )
check_include_files ( gssapi.h HAVE_GSSAPI_H )
check_include_files ( history.h HAVE_HISTORY_H )
check_include_files ( ieeefp.h HAVE_IEEEFP_H )
check_include_files ( ifaddrs.h HAVE_IFADDRS_H )
check_include_files ( inttypes.h HAVE_INTTYPES_H )
check_include_files ( langinfo.h HAVE_LANGINFO_H )
check_include_files ( ldap.h HAVE_LDAP_H )
check_include_files ( memory.h HAVE_MEMORY_H )
check_include_files ( "netinet/in.h" HAVE_NETINET_IN_H )
check_include_files ( "metinet/tcp.h" HAVE_NETINET_TCP_H )
check_include_files ( "net/if.h" HAVE_NET_IF_H )
check_include_files ( "ossp/uuid.h" HAVE_OSSP_UUID_H )
check_include_files ( "pam/pam_appl.h" HAVE_PAM_PAM_APPL_H )
check_include_files ( poll.h HAVE_POLL_H )
check_include_files ( pwd.h HAVE_PWD_H )
check_include_files ( readline.h HAVE_READLINE_H )
check_include_files ( "readline/history.h" HAVE_READLINE_HISTORY_H )
check_include_files ( "readline/readline.h" HAVE_READLINE_READLINE_H )
check_include_files ( "security/pam_appl.h" HAVE_SECURITY_PAM_APPL_H )
check_include_files ( stdint.h HAVE_STDINT_H )
check_include_files ( stdlib.h HAVE_STDLIB_H )
check_include_files ( strings.h HAVE_STRINGS_H )
check_include_files ( string.h HAVE_STRING_H )
check_include_files ( "sys/ioctl.h" HAVE_SYS_IOCTL_H )
check_include_files ( "sys/ipc.h" HAVE_SYS_IPC_H )
check_include_files ( "sys/poll.h" HAVE_SYS_POLL_H )
check_include_files ( "sys/pstat.h" HAVE_SYS_PSTAT_H )
check_include_files ( "sys/resource.h" HAVE_SYS_RESOURCE_H )
check_include_files ( "sys/select.h" HAVE_SYS_SELECT_H )
check_include_files ( "sys/sem.h" HAVE_SYS_SEM_H )
check_include_files ( "sys/shm.h" HAVE_SYS_SHM_H )
check_include_files ( "sys/socket.h" HAVE_SYS_SOCKET_H )
check_include_files ( "sys/sockio.h" HAVE_SYS_SOCKIO_H )
check_include_files ( "sys/stat.h" HAVE_SYS_STAT_H )
check_include_files ( "sys/tas.h" HAVE_SYS_TAS_H )
check_include_files ( "sys/time.h" HAVE_SYS_TIME_H )
check_include_files ( "sys/types.h" HAVE_SYS_TYPES_H )
check_include_files ( "sys/ucred.h" HAVE_SYS_UCRED_H )
check_include_files ( "sys/un.h" HAVE_SYS_UN_H )
check_include_files ( termios.h HAVE_TERMIOS_H )
check_include_files ( unistd.h HAVE_UNISTD_H )
check_include_files ( utime.h HAVE_UTIME_H )
check_include_files ( uuid.h HAVE_UUID_H )
check_include_files ( wchar.h HAVE_WCHAR_H )
check_include_files ( wctype.h HAVE_WCTYPE_H )
check_include_files ( winldap.h HAVE_WINLDAP_H )
check_include_files ( ucred.h HAVE_UCRED_H )

# Symbols
check_type_size ( "int opterr" HAVE_INT_OPTERR )
check_type_size ( "int optreset" HAVE_INT_OPTRESET )
check_type_size ( "int timezone" HAVE_INT_TIMEZONE )
check_type_size ( PS_STRINGS HAVE_PS_STRINGS )
check_type_size ( rl_completion_append_character HAVE_RL_COMPLETION_APPEND_CHARACTER )
#check_type_size ( tzname HAVE_TZNAME )

# Functions
check_function_exists ( append_history HAVE_APPEND_HISTORY )
check_function_exists ( cbrt HAVE_CBRT )
check_function_exists ( class HAVE_CLASS )
check_function_exists ( fdatasync HAVE_DECL_FDATASYNC )
check_function_exists ( F_FULLSYNC add_custom_command )
check_function_exists ( posix_fadvise HAVE_DECL_POSIX_FADVISE )
check_function_exists ( snprintf HAVE_DECL_SNPRINTF )
check_function_exists ( strlcat HAVE_DECL_STRLCAT )
check_function_exists ( strlcpy HAVE_DECL_STRLCPY )
check_function_exists ( sys_siglist HAVE_DECL_SYS_SIGLIST )
check_function_exists ( vsnprintf HAVE_DECL_VSNPRINTF )
check_function_exists ( crypt HAVE_CRYPT )
check_function_exists ( dlopen HAVE_DLOPEN )
check_function_exists ( fdatasync HAVE_FDATASYNC )
check_function_exists ( fls HAVE_FLS )
check_function_exists ( fpclass HAVE_FPCLASS )
check_function_exists ( fp_class HAVE_FP_CLASS )
check_function_exists ( fp_class_d HAVE_FP_CLASS_D )
check_function_exists ( fseeko HAVE_FSEEKO )
check_function_exists ( getaddrinfo HAVE_GETADDRINFO )
check_function_exists ( gethostbyname_r HAVE_GETHOSTBYNAME_R )
check_function_exists ( getifaddrs HAVE_GETIFADDRS )
check_function_exists ( getopt HAVE_GETOPT )
check_function_exists ( getopt_long HAVE_GETOPT_LONG )
check_function_exists ( getpeereid HAVE_GETPEEREID )
check_function_exists ( getpeerucred HAVE_GETPEERUCRED )
check_function_exists ( getpwuid_r HAVE_GETPWUID_R )
check_function_exists ( getrlimit HAVE_GETRLIMIT )
check_function_exists ( getrusage HAVE_GETRUSAGE )
check_function_exists ( gettimeofday HAVE_GETTIMEOFDAY )
check_function_exists ( history_truncate_file HAVE_HISTORY_TRUNCATE_FILE )
check_function_exists ( inet_aton HAVE_INET_ATON )
check_function_exists ( isinf HAVE_ISINF )
check_function_exists ( mbstowcs_l HAVE_MBSTOWCS_L )
check_function_exists ( memmove HAVE_MEMMOVE )
check_function_exists ( poll HAVE_POLL )
check_function_exists ( posix_fadvise HAVE_POSIX_FADVISE )
check_function_exists ( pstat HAVE_PSTAT )
check_function_exists ( readlink HAVE_READLINK )
check_function_exists ( rint HAVE_RINT )
check_function_exists ( rl_completion_matches HAVE_RL_COMPLETION_MATCHES )
check_function_exists ( rl_filename_completion_function HAVE_RL_FILENAME_COMPLETION_FUNCTION )
check_function_exists ( setproctitle HAVE_SETPROCTITLE )
check_function_exists ( setsid HAVE_SETSID )
check_function_exists ( sigprocmask HAVE_SIGPROCMASK )
check_function_exists ( sigsetjmp HAVE_SIGSETJMP )
check_function_exists ( snprintf HAVE_SNPRINTF )
check_function_exists ( spinlocks HAVE_SPINLOCKS )
check_function_exists ( srandom HAVE_SRANDOM )
check_function_exists ( strerror HAVE_STRERROR )
check_function_exists ( strerror_r HAVE_STRERROR_R )
check_function_exists ( strlcat HAVE_STRLCAT )
check_function_exists ( strlcpy HAVE_STRLCPY )
check_function_exists ( strtoll HAVE_STRTOLL )
check_function_exists ( strtoq HAVE_STRTOQ )
check_function_exists ( strtoull HAVE_STRTOULL )
check_function_exists ( strtouq HAVE_STRTOUQ )
check_function_exists ( symlink HAVE_SYMLINK )
check_function_exists ( towlower HAVE_TOWLOWER )
check_function_exists ( unsetenv HAVE_UNSETENV )
check_function_exists ( utime HAVE_UTIME )
check_function_exists ( utimes HAVE_UTIMES )
check_function_exists ( vsnprintf HAVE_VSNPRINTF )
check_function_exists ( waitpid HAVE_WAITPID )
check_function_exists ( wcstombs HAVE_WCSTOMBS )
check_function_exists ( wcstombs_l HAVE_WCSTOMBS_L )
