Skip to content

Commit 875a627

Browse files
committed
Vendor libmysql.dll by default on Windows. Use rpath only on Unix platforms.
1 parent 05ba33e commit 875a627

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

ext/mysql2/extconf.rb

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -94,43 +94,14 @@ def asplode lib
9494
$CFLAGS << gcc_flags
9595
end
9696

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

130101
# Build libmysql.a interface link library
131102
# Use rake to rebuild only if these files change
132103
deffile = File.expand_path('../../../support/libmysql.def', __FILE__)
133-
libfile = File.expand_path(File.join(libdir, 'libmysql.lib'))
104+
libfile = File.expand_path(File.join(rpath_dir, 'libmysql.lib'))
134105
file 'libmysql.a' => [deffile, libfile] do |t|
135106
when_writing 'building libmysql.a' do
136107
sh 'dlltool', '--kill-at',
@@ -149,7 +120,7 @@ def asplode lib
149120

150121
# Vendor libmysql.dll
151122
vendordll = File.expand_path('../../../vendor/libmysql.dll', __FILE__)
152-
dllfile = File.expand_path(File.join(libdir, 'libmysql.dll'))
123+
dllfile = File.expand_path(File.join(rpath_dir, 'libmysql.dll'))
153124
file vendordll => dllfile do |t|
154125
when_writing 'copying libmysql.dll' do
155126
cp dllfile, vendordll
@@ -164,6 +135,35 @@ def asplode lib
164135
# Let's do it!
165136
Rake::Task[vendordll].invoke
166137
end
138+
else
139+
case explicit_rpath = with_config('mysql-rpath')
140+
when true
141+
abort "-----\nOption --with-mysql-rpath must have an argument\n-----"
142+
when false
143+
warn "-----\nOption --with-mysql-rpath has been disabled at your request\n-----"
144+
when String
145+
# The user gave us a value so use it
146+
rpath_flags = " -Wl,-rpath,#{explicit_rpath}"
147+
warn "-----\nSetting mysql rpath to #{explicit_rpath}\n-----"
148+
$LDFLAGS << rpath_flags
149+
else
150+
if libdir = rpath_dir[%r{(-L)?(/[^ ]+)}, 2]
151+
rpath_flags = " -Wl,-rpath,#{libdir}"
152+
if RbConfig::CONFIG["RPATHFLAG"].to_s.empty? && try_link('int main() {return 0;}', rpath_flags)
153+
# Usually Ruby sets RPATHFLAG the right way for each system, but not on OS X.
154+
warn "-----\nSetting rpath to #{libdir}\n-----"
155+
$LDFLAGS << rpath_flags
156+
else
157+
if RbConfig::CONFIG["RPATHFLAG"].to_s.empty?
158+
# If we got here because try_link failed, warn the user
159+
warn "-----\nDon't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load\n-----"
160+
end
161+
# Make sure that LIBPATH gets set if we didn't explicitly set the rpath.
162+
warn "-----\nSetting libpath to #{libdir}\n-----"
163+
$LIBPATH << libdir unless $LIBPATH.include?(libdir)
164+
end
165+
end
166+
end
167167
end
168168

169169
create_makefile('mysql2/mysql2')

0 commit comments

Comments
 (0)