@@ -91,21 +91,27 @@ def asplode lib
9191 asplode h unless have_header h
9292end
9393
94- # GCC | Clang | XCode specific flags
95- if RbConfig ::MAKEFILE_CONFIG [ 'CC' ] =~ /gcc|clang|xcrun/
96- $CFLAGS << ' -Wall -funroll-loops'
94+ # These gcc style flags are also supported by clang and xcode compilers,
95+ # so we'll use a does-it-work test instead of an is-it-gcc test.
96+ gcc_flags = ' -Wall -funroll-loops'
97+ if try_link ( 'int main() {return 0;}' , gcc_flags )
98+ $CFLAGS << gcc_flags
99+ end
97100
98- if libdir = rpath_dir [ %r{(-L)?(/[^ ]+)} , 2 ]
99- # The following comment and test is borrowed from the Pg gem:
100- # Try to use runtime path linker option, even if RbConfig doesn't know about it.
101- # The rpath option is usually set implicit by dir_config() , but so far not on Mac OS X.
102- if RbConfig :: CONFIG [ "RPATHFLAG" ] . to_s . empty? && try_link ( 'int main() {return 0;}' , " -Wl,- rpath, #{ libdir } " )
103- warn "----- \n Setting rpath to #{ libdir } \n -----"
104- $LDFLAGS << " -Wl,-rpath, #{ libdir } "
105- else
106- # Make sure that LIBPATH gets set if we didn't explicitly set the rpath.
107- $LIBPATH << libdir unless $LIBPATH . include? ( libdir )
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 "----- \n Setting 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 "----- \n Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load \n -----"
108111 end
112+ # Make sure that LIBPATH gets set if we didn't explicitly set the rpath.
113+ warn "-----\n Setting libpath to #{ libdir } \n -----"
114+ $LIBPATH << libdir unless $LIBPATH. include? ( libdir )
109115 end
110116end
111117
0 commit comments