Skip to content

Commit 012beef

Browse files
committed
Merge pull request #439 from sodabrew/with_rpath
Options to alter or disable rpath
2 parents d1dad2d + 1b6f2d6 commit 012beef

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,24 @@ By default, the mysql2 gem will try to find a copy of MySQL in this order:
3232
### Configuration options
3333

3434
Use these options by `gem install mysql2 -- [--optionA] [--optionB=argument]`.
35-
The following options are mutually exclusive.
3635

3736
* `--with-mysql-dir[=/path/to/mysqldir]` -
3837
Specify the directory where MySQL is installed. The mysql2 gem will not use
3938
`mysql_config`, but will instead look at `mysqldir/lib` and `mysqldir/include`
4039
for the library and header files.
40+
This option is mutually exclusive with `--with-mysql-config`.
4141

4242
* `--with-mysql-config[=/path/to/mysql_config]` -
4343
Specify a path to the `mysql_config` binary provided by your copy of MySQL. The
4444
mysql2 gem will ask this `mysql_config` binary about the compiler and linker
4545
arguments needed.
46+
This option is mutually exclusive with `--with-mysql-dir`.
47+
48+
* `--with-mysql-rpath=/path/to/mysql/lib` / `--without-mysql-rpath` -
49+
Override the runtime path used to find the MySQL libraries.
50+
This may be needed if you deploy to a system where these libraries
51+
are located somewhere different than on your build system.
52+
This overrides any rpath calculated by default or by the options above.
4653

4754
### Windows
4855
First, make sure you have the DevKit installed (http://rubyinstaller.org/downloads/) and its variables

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)