@@ -31,19 +31,27 @@ def asplode lib
31
31
32
32
GLOB = "{#{ dirs . join ( ',' ) } }/{mysql_config,mysql_config5}"
33
33
34
- if RUBY_PLATFORM =~ /mswin|mingw/
35
- inc , lib = dir_config ( 'mysql' )
36
-
34
+ # If the user has provided a --with-mysql-dir argument, we must respect it or fail.
35
+ inc , lib = dir_config ( 'mysql' )
36
+ if inc && lib
37
37
# Ruby versions not incorporating the mkmf fix at
38
38
# https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/39717
39
39
# do not properly search for lib directories, and must be corrected
40
40
unless lib && lib [ -3 , 3 ] == 'lib'
41
41
@libdir_basename = 'lib'
42
42
inc , lib = dir_config ( 'mysql' )
43
43
end
44
- exit 1 unless have_library ( "libmysql" )
45
- elsif mc = ( with_config ( 'mysql-config' ) || Dir [ GLOB ] . first ) then
44
+ abort "-----\n Cannot find include dir at #{ inc } \n -----" unless inc && File . directory? ( inc )
45
+ abort "-----\n Cannot find library dir at #{ lib } \n -----" unless lib && File . directory? ( lib )
46
+ warn "-----\n Using --with-mysql-dir=#{ File . dirname inc } \n -----"
47
+ rpath_dir = lib
48
+ elsif mc = ( with_config ( 'mysql-config' ) || Dir [ GLOB ] . first )
49
+ # If the user has provided a --with-mysql-config argument, we must respect it or fail.
50
+ # If the user gave --with-mysql-config with no argument means we should try to find it.
46
51
mc = Dir [ GLOB ] . first if mc == true
52
+ abort "-----\n Cannot find mysql_config at #{ mc } \n -----" unless mc && File . exists? ( mc )
53
+ abort "-----\n Cannot execute mysql_config at #{ mc } \n -----" unless File . executable? ( mc )
54
+ warn "-----\n Using mysql_config at #{ mc } \n -----"
47
55
ver = `#{ mc } --version` . chomp . to_f
48
56
includes = `#{ mc } --include` . chomp
49
57
exit 1 if $? != 0
@@ -55,18 +63,24 @@ def asplode lib
55
63
exit 1 if $? != 0
56
64
$INCFLAGS += ' ' + includes
57
65
$libs = libs + " " + $libs
66
+ rpath_dir = libs
58
67
else
59
68
inc , lib = dir_config ( 'mysql' , '/usr/local' )
60
69
libs = [ 'm' , 'z' , 'socket' , 'nsl' , 'mygcc' ]
61
70
while not find_library ( 'mysqlclient' , 'mysql_query' , lib , "#{ lib } /mysql" ) do
62
71
exit 1 if libs . empty?
63
72
have_library ( libs . shift )
64
73
end
74
+ rpath_dir = lib
75
+ end
76
+
77
+ if RUBY_PLATFORM =~ /mswin|mingw/
78
+ exit 1 unless have_library ( 'libmysql' )
65
79
end
66
80
67
- if have_header ( 'mysql.h' ) then
81
+ if have_header ( 'mysql.h' )
68
82
prefix = nil
69
- elsif have_header ( 'mysql/mysql.h' ) then
83
+ elsif have_header ( 'mysql/mysql.h' )
70
84
prefix = 'mysql'
71
85
else
72
86
asplode 'mysql.h'
@@ -77,16 +91,20 @@ def asplode lib
77
91
asplode h unless have_header h
78
92
end
79
93
80
- # GCC specific flags
81
- if RbConfig ::MAKEFILE_CONFIG [ 'CC' ] =~ /gcc/
94
+ # GCC | Clang | XCode specific flags
95
+ if RbConfig ::MAKEFILE_CONFIG [ 'CC' ] =~ /gcc|clang|xcrun /
82
96
$CFLAGS << ' -Wall -funroll-loops'
83
97
84
- if libdir = $libs [ %r{-L (/[^ ]+)} , 1 ]
98
+ if libdir = rpath_dir [ %r{(-L)? (/[^ ]+)} , 2 ]
85
99
# The following comment and test is borrowed from the Pg gem:
86
100
# Try to use runtime path linker option, even if RbConfig doesn't know about it.
87
101
# The rpath option is usually set implicit by dir_config(), but so far not on Mac OS X.
88
102
if RbConfig ::CONFIG [ "RPATHFLAG" ] . to_s . empty? && try_link ( 'int main() {return 0;}' , " -Wl,-rpath,#{ libdir } " )
103
+ warn "-----\n Setting rpath to #{ libdir } \n -----"
89
104
$LDFLAGS << " -Wl,-rpath,#{ libdir } "
105
+ else
106
+ # Make sure that LIBPATH gets set if we didn't explicitly set the rpath.
107
+ $LIBPATH << libdir unless $LIBPATH. include? ( libdir )
90
108
end
91
109
end
92
110
end
0 commit comments