Skip to content

Commit 7366f9c

Browse files
committed
Generate interface library libmysql.a from MySQL Connector/C libmysql.lib and the pre-generated libmysql.def included here
1 parent 12287c3 commit 7366f9c

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

ext/mysql2/extconf.rb

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ def asplode lib
7474
rpath_dir = lib
7575
end
7676

77-
if RUBY_PLATFORM =~ /mswin|mingw/
78-
exit 1 unless have_library('libmysql')
79-
end
80-
8177
if have_header('mysql.h')
8278
prefix = nil
8379
elsif have_header('mysql/mysql.h')
@@ -127,4 +123,47 @@ def asplode lib
127123
end
128124
end
129125

126+
if RUBY_PLATFORM =~ /mswin|mingw/
127+
# Build libmysql.a interface link library
128+
require 'rake'
129+
130+
# Build libmysql.a interface link library
131+
# Use rake to rebuild only if these files change
132+
deffile = File.expand_path('../../../support/libmysql.def', __FILE__)
133+
libfile = File.expand_path(File.join(libdir, 'libmysql.lib'))
134+
file 'libmysql.a' => [deffile, libfile] do |t|
135+
when_writing 'building libmysql.a' do
136+
sh 'dlltool', '--kill-at',
137+
'--dllname', 'libmysql.dll',
138+
'--output-lib', 'libmysql.a',
139+
'--input-def', deffile, libfile
140+
end
141+
end
142+
143+
Rake::Task['libmysql.a'].invoke
144+
145+
# Make sure the generated interface library works
146+
$LOCAL_LIBS << ' ' << 'libmysql.a'
147+
abort "-----\nCannot find libmysql.a\n----" unless have_library('libmysql')
148+
abort "-----\nCannot link to libmysql.a (my_init)\n----" unless have_func('my_init')
149+
150+
# Vendor libmysql.dll
151+
vendordll = File.expand_path('../../../vendor/libmysql.dll', __FILE__)
152+
dllfile = File.expand_path(File.join(libdir, 'libmysql.dll'))
153+
file vendordll => dllfile do |t|
154+
when_writing 'copying libmysql.dll' do
155+
cp dllfile, vendordll
156+
end
157+
end
158+
159+
# Copy libmysql.dll to the local vendor directory by default
160+
if arg_config('--no-vendor-libmysql')
161+
# Fine, don't.
162+
puts "--no-vendor-libmysql"
163+
else # Default: arg_config('--vendor-libmysql')
164+
# Let's do it!
165+
Rake::Task[vendordll].invoke
166+
end
167+
end
168+
130169
create_makefile('mysql2/mysql2')

0 commit comments

Comments
 (0)