1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
require 'pp'
require 'mkmf'
if ENV['MAINTAINER_MODE']
$stderr.puts "Maintainer mode enabled."
$CFLAGS <<
' -Wall' <<
' -ggdb' <<
' -DDEBUG' <<
' -pedantic'
end
if pgdir = with_config( 'pg' )
ENV['PATH'] = "#{pgdir}/bin" + File::PATH_SEPARATOR + ENV['PATH']
end
if enable_config("gvl-unlock", true)
$defs.push( "-DENABLE_GVL_UNLOCK" )
$stderr.puts "Calling libpq with GVL unlocked"
else
$stderr.puts "Calling libpq with GVL locked"
end
if enable_config("windows-cross")
# Avoid dependency to external libgcc.dll on x86-mingw32
$LDFLAGS << " -static-libgcc"
# Don't use pg_config for cross build, but --with-pg-* path options
dir_config 'pg'
else
# Native build
pgconfig = with_config('pg-config') ||
with_config('pg_config') ||
find_executable('pg_config')
if pgconfig && pgconfig != 'ignore'
$stderr.puts "Using config values from %s" % [ pgconfig ]
incdir = IO.popen([pgconfig, "--includedir"], &:read).chomp
libdir = IO.popen([pgconfig, "--libdir"], &:read).chomp
dir_config 'pg', incdir, libdir
# Windows traditionally stores DLLs beside executables, not in libdir
dlldir = RUBY_PLATFORM=~/mingw|mswin/ ? IO.popen([pgconfig, "--bindir"], &:read).chomp : libdir
elsif checking_for "libpq per pkg-config" do
_cflags, ldflags, _libs = pkg_config("libpq")
dlldir = ldflags && ldflags[/-L([^ ]+)/] && $1
end
else
incdir, libdir = dir_config 'pg'
dlldir = libdir
end
if /mswin/ =~ RUBY_PLATFORM
$libs = append_library($libs, 'ws2_32')
end
end
$stderr.puts "Using libpq from #{dlldir}"
File.write("postgresql_lib_path.rb", <<-EOT)
module PG
POSTGRESQL_LIB_PATH = #{dlldir.inspect}
end
EOT
$INSTALLFILES = {
"./postgresql_lib_path.rb" => "$(RUBYLIBDIR)/pg/"
}
if RUBY_VERSION >= '2.3.0' && /solaris/ =~ RUBY_PLATFORM
append_cppflags( '-D__EXTENSIONS__' )
end
begin
find_header( 'libpq-fe.h' ) or abort "Can't find the 'libpq-fe.h header"
find_header( 'libpq/libpq-fs.h' ) or abort "Can't find the 'libpq/libpq-fs.h header"
find_header( 'pg_config_manual.h' ) or abort "Can't find the 'pg_config_manual.h' header"
abort "Can't find the PostgreSQL client library (libpq)" unless
have_library( 'pq', 'PQconnectdb', ['libpq-fe.h'] ) ||
have_library( 'libpq', 'PQconnectdb', ['libpq-fe.h'] ) ||
have_library( 'ms/libpq', 'PQconnectdb', ['libpq-fe.h'] )
rescue SystemExit
install_text = case RUBY_PLATFORM
when /linux/
<<-EOT
Please install libpq or postgresql client package like so:
sudo apt install libpq-dev
sudo yum install postgresql-devel
sudo zypper in postgresql-devel
sudo pacman -S postgresql-libs
EOT
when /darwin/
<<-EOT
Please install libpq or postgresql client package like so:
brew install libpq
EOT
when /mingw/
<<-EOT
Please install libpq or postgresql client package like so:
ridk exec sh -c "pacman -S ${MINGW_PACKAGE_PREFIX}-postgresql"
EOT
else
<<-EOT
Please install libpq or postgresql client package.
EOT
end
$stderr.puts <<-EOT
*****************************************************************************
Unable to find PostgreSQL client library.
#{install_text}
or try again with:
gem install pg -- --with-pg-config=/path/to/pg_config
or set library paths manually with:
gem install pg -- --with-pg-include=/path/to/libpq-fe.h/ --with-pg-lib=/path/to/libpq.so/
EOT
raise
end
if /mingw/ =~ RUBY_PLATFORM && RbConfig::MAKEFILE_CONFIG['CC'] =~ /gcc/
# Work around: https://sourceware.org/bugzilla/show_bug.cgi?id=22504
checking_for "workaround gcc version with link issue" do
`#{RbConfig::MAKEFILE_CONFIG['CC']} --version`.chomp =~ /\s(\d+)\.\d+\.\d+(\s|$)/ &&
$1.to_i >= 6 &&
have_library(':libpq.lib') # Prefer linking to libpq.lib over libpq.dll if available
end
end
have_func 'PQconninfo', 'libpq-fe.h' or
abort "Your PostgreSQL is too old. Either install an older version " +
"of this gem or upgrade your database to at least PostgreSQL-9.3."
# optional headers/functions
have_func 'PQsslAttribute', 'libpq-fe.h' # since PostgreSQL-9.5
have_func 'PQresultVerboseErrorMessage', 'libpq-fe.h' # since PostgreSQL-9.6
have_func 'PQencryptPasswordConn', 'libpq-fe.h' # since PostgreSQL-10
have_func 'PQresultMemorySize', 'libpq-fe.h' # since PostgreSQL-12
have_func 'PQenterPipelineMode', 'libpq-fe.h' do |src| # since PostgreSQL-14
# Ensure header files fit as well
src + " int con(){ return PGRES_PIPELINE_SYNC; }"
end
have_func 'timegm'
have_func 'rb_gc_adjust_memory_usage' # since ruby-2.4
have_func 'rb_gc_mark_movable' # since ruby-2.7
have_func 'rb_io_wait' # since ruby-3.0
# unistd.h confilicts with ruby/win32.h when cross compiling for win32 and ruby 1.9.1
have_header 'unistd.h'
have_header 'inttypes.h'
have_header('ruby/fiber/scheduler.h') if RUBY_PLATFORM=~/mingw|mswin/
checking_for "C99 variable length arrays" do
$defs.push( "-DHAVE_VARIABLE_LENGTH_ARRAYS" ) if try_compile('void test_vla(int l){ int vla[l]; }')
end
create_header()
create_makefile( "pg_ext" )
|