This repository has been archived by the owner on Apr 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
/
extconf.rb
81 lines (68 loc) · 2.23 KB
/
extconf.rb
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
ENV["RC_ARCHS"] = "" if RUBY_PLATFORM =~ /darwin/
require 'mkmf'
# Allow for custom compiler to be specified.
RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
# All instances of mysql_config on PATH ...
def mysql_config_paths
ENV['PATH'].split(File::PATH_SEPARATOR).collect do |path|
[ "#{path}/mysql_config", "#{path}/mysql_config5" ].
detect { |bin| File.exist?(bin) }
end
end
# The first mysql_config binary on PATH ...
def default_mysql_config_path
mysql_config_paths.compact.first
end
def mysql_config(type)
IO.popen("#{default_mysql_config_path} --#{type}").readline.chomp rescue nil
end
def default_prefix
if mc = default_mysql_config_path
File.dirname(File.dirname(mc))
else
"/usr/local"
end
end
# Allow overriding path to mysql_config on command line using:
# ruby extconf.rb --with-mysql-config=/path/to/mysql_config
if RUBY_PLATFORM =~ /mswin|mingw/
dir_config('mysql')
have_header 'my_global.h'
have_header 'mysql.h'
have_library 'libmysql'
have_func('mysql_query', 'mysql.h')
have_func('mysql_ssl_set', 'mysql.h')
elsif mc = with_config('mysql-config', default_mysql_config_path)
includes = mysql_config('include').split(/\s+/).map do |dir|
dir.gsub(/^-I/, "")
end.uniq
libs = mysql_config('libs').split(/\s+/).select {|lib| lib =~ /^-L/}.map do |dir|
dir.gsub(/^-L/, "")
end.uniq
linked = mysql_config('libs').split(/\s+/).select {|lib| lib =~ /^-l/}.map do |dir|
dir.gsub(/^-l/, "")
end.uniq
dir_config('mysql', includes, libs)
linked.each do |link|
have_library link
end
else
inc, lib = dir_config('mysql', default_prefix)
libs = ['m', 'z', 'socket', 'nsl']
lib_dirs =
[ lib, "/usr/lib", "/usr/local/lib", "/opt/local/lib" ].collect do |path|
[ path, "#{path}/mysql", "#{path}/mysql5/mysql" ]
end
find_library('mysqlclient', 'mysql_query', *lib_dirs.flatten) || exit(1)
find_header('mysql.h', *lib_dirs.flatten.map { |p| p.gsub('/lib', '/include') })
end
unless RUBY_PLATFORM =~ /mswin|mingw/
have_header 'mysql.h'
have_func 'mysql_query'
have_func 'mysql_ssl_set'
end
$CFLAGS << ' -Wall ' unless RUBY_PLATFORM =~ /mswin/
if RUBY_VERSION < '1.8.6'
$CFLAGS << ' -DRUBY_LESS_THAN_186'
end
create_makefile('do_mysql/do_mysql')