kamk-pg 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/ext/extconf.rb +87 -0
  2. data/ext/pg.c +3877 -0
  3. metadata +57 -0
data/ext/extconf.rb ADDED
@@ -0,0 +1,87 @@
1
+ require 'mkmf'
2
+
3
+ begin
4
+ IO.popen("pg_config --version").readline.chomp
5
+ rescue
6
+ $stderr.write("ERROR: can't find pg_config.\n")
7
+ $stderr.write("HINT: Make sure pg_config is in your PATH\n")
8
+ exit 1
9
+ end
10
+
11
+ # OS X compatibility
12
+ if(RUBY_PLATFORM =~ /darwin/) then
13
+ # test if postgresql is probably universal
14
+ bindir = (IO.popen("pg_config --bindir").readline.chomp rescue nil)
15
+ filetype = (IO.popen("file #{bindir}/pg_config").
16
+ readline.chomp rescue nil)
17
+ # if it's not universal, ARCHFLAGS should be set
18
+ if((filetype !~ /universal binary/) && ENV['ARCHFLAGS'].nil?) then
19
+ arch_tmp = (IO.popen("uname -p").readline.chomp rescue nil)
20
+ if(arch_tmp == 'powerpc')
21
+ arch = 'ppc'
22
+ else
23
+ arch = 'i386'
24
+ end
25
+ $stderr.write %{
26
+ =========== WARNING ===========
27
+
28
+ You are building this extension on OS X without setting the
29
+ ARCHFLAGS environment variable, and PostgreSQL does not appear
30
+ to have been built as a universal binary. If you are seeing this
31
+ message, that means that the build will probably fail.
32
+
33
+ Try setting the environment variable ARCHFLAGS
34
+ to '-arch #{arch}' before building.
35
+
36
+ For example:
37
+ (in bash) $ export ARCHFLAGS='-arch #{arch}'
38
+ (in tcsh) % setenv ARCHFLAGS '-arch #{arch}'
39
+
40
+ Then try building again.
41
+
42
+ ===================================
43
+ }
44
+ # We don't exit here. Who knows? It might build.
45
+ end
46
+ end
47
+
48
+ if RUBY_VERSION < '1.8'
49
+ puts 'This library is for ruby-1.8 or higher.'
50
+ exit 1
51
+ end
52
+
53
+ def config_value(type)
54
+ ENV["POSTGRES_#{type.upcase}"] || pg_config(type)
55
+ end
56
+
57
+ def pg_config(type)
58
+ IO.popen("pg_config --#{type}dir").readline.chomp rescue nil
59
+ end
60
+
61
+ def have_build_env
62
+ (have_library('pq') || have_library('libpq') || have_library('ms/libpq')) &&
63
+ have_header('libpq-fe.h') && have_header('libpq/libpq-fs.h')
64
+ end
65
+
66
+ dir_config('pg', config_value('include'), config_value('lib'))
67
+
68
+ desired_functions = %w(
69
+ PQconnectionUsedPassword
70
+ PQisthreadsafe
71
+ PQprepare
72
+ PQexecParams
73
+ PQescapeString
74
+ PQescapeStringConn
75
+ lo_create
76
+ pg_encoding_to_char
77
+ PQsetClientEncoding
78
+ )
79
+
80
+ if have_build_env
81
+ desired_functions.each(&method(:have_func))
82
+ $OBJS = ['pg.o','compat.o']
83
+ create_makefile("pg")
84
+ else
85
+ puts 'Could not find PostgreSQL build environment (libraries & headers): Makefile not created'
86
+ end
87
+