Skip to content

Commit 60f5731

Browse files
committed
Provide --with-mysql-rpath to override rpath if needed.
1 parent d1dad2d commit 60f5731

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

ext/mysql2/extconf.rb

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,32 @@ def asplode lib
9898
$CFLAGS << gcc_flags
9999
end
100100

101-
if libdir = rpath_dir[%r{(-L)?(/[^ ]+)}, 2]
102-
rpath_flags = " -Wl,-rpath,#{libdir}"
103-
if RbConfig::CONFIG["RPATHFLAG"].to_s.empty? && try_link('int main() {return 0;}', rpath_flags)
104-
# Usually Ruby sets RPATHFLAG the right way for each system, but not on OS X.
105-
warn "-----\nSetting rpath to #{libdir}\n-----"
106-
$LDFLAGS << rpath_flags
107-
else
108-
if RbConfig::CONFIG["RPATHFLAG"].to_s.empty?
109-
# If we got here because try_link failed, warn the user
110-
warn "-----\nDon't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load\n-----"
101+
case explicit_rpath = with_config('mysql-rpath')
102+
when true
103+
abort "-----\nOption --with-mysql-rpath must have an argument\n-----"
104+
when false
105+
warn "-----\nOption --with-mysql-rpath has been disabled at your request\n-----"
106+
when String
107+
# The user gave us a value so use it
108+
rpath_flags = " -Wl,-rpath,#{explicit_rpath}"
109+
warn "-----\nSetting mysql rpath to #{explicit_rpath}\n-----"
110+
$LDFLAGS << rpath_flags
111+
else
112+
if libdir = rpath_dir[%r{(-L)?(/[^ ]+)}, 2]
113+
rpath_flags = " -Wl,-rpath,#{libdir}"
114+
if RbConfig::CONFIG["RPATHFLAG"].to_s.empty? && try_link('int main() {return 0;}', rpath_flags)
115+
# Usually Ruby sets RPATHFLAG the right way for each system, but not on OS X.
116+
warn "-----\nSetting rpath to #{libdir}\n-----"
117+
$LDFLAGS << rpath_flags
118+
else
119+
if RbConfig::CONFIG["RPATHFLAG"].to_s.empty?
120+
# If we got here because try_link failed, warn the user
121+
warn "-----\nDon't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load\n-----"
122+
end
123+
# Make sure that LIBPATH gets set if we didn't explicitly set the rpath.
124+
warn "-----\nSetting libpath to #{libdir}\n-----"
125+
$LIBPATH << libdir unless $LIBPATH.include?(libdir)
111126
end
112-
# Make sure that LIBPATH gets set if we didn't explicitly set the rpath.
113-
warn "-----\nSetting libpath to #{libdir}\n-----"
114-
$LIBPATH << libdir unless $LIBPATH.include?(libdir)
115127
end
116128
end
117129

0 commit comments

Comments
 (0)