@@ -74,10 +74,6 @@ def asplode lib
74
74
rpath_dir = lib
75
75
end
76
76
77
- if RUBY_PLATFORM =~ /mswin|mingw/
78
- exit 1 unless have_library ( 'libmysql' )
79
- end
80
-
81
77
if have_header ( 'mysql.h' )
82
78
prefix = nil
83
79
elsif have_header ( 'mysql/mysql.h' )
@@ -127,4 +123,47 @@ def asplode lib
127
123
end
128
124
end
129
125
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 "-----\n Cannot find libmysql.a\n ----" unless have_library ( 'libmysql' )
148
+ abort "-----\n Cannot 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
+
130
169
create_makefile ( 'mysql2/mysql2' )
0 commit comments