Hi Mike,
Thanks for your reply.
> If you can write a patch for the extconf.rb file that works for your
> compiler, send it to us and we'll apply to master. We recently did something
> similar for cl.exe, the windows compiler.
I created this diff. It may not be the most elegant solution and it's
not ideal in the sense that it seems to be ignoring the $CC
environment variable when it actually comes to invoking the compiler
later (it'll still call "cc", even if I "export CC=gcc"). That part
seems out of the scope of this script, though. It may pick the
compiler based on which compiler was used to build Ruby itself. Not
sure. -- It does properly pick the compiler flags based on $CC with my
patch, though.
If the command "$CC -v" contains the string "gcc", it'll append the
GCC specific CFLAGS. Otherwise, it won't.
With cc = Sun Studio:
$ grep ^CFLAGS Makefile
CFLAGS = -KPIC -O -g -DUSE_INCLUDED_VASPRINTF
With cc sym-linked to gcc:
$ grep ^CFLAGS Makefile
CFLAGS = -KPIC -O -g -DUSE_INCLUDED_VASPRINTF -O3 -Wall -Wcast-
qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline
Note that -KPIC is not working for GCC, but that, too, seems to be
coming from the compiled-in Ruby defaults. Nothing that can be done
about it in extconf.rb, I think.
------------------------------------------------------------------------------------------------------------
$ cat cflags.diff
diff --git a/ext/nokogiri/extconf.rb b/ext/nokogiri/extconf.rb
index ce6276a..7584a35 100644
--- a/ext/nokogiri/extconf.rb
+++ b/ext/nokogiri/extconf.rb
@@ -42,7 +42,11 @@ if Config::CONFIG['target_os'] =~ /mswin32/
else
lib_prefix = ''
- $CFLAGS << " -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -
Wmissing-noreturn -Winline"
+ mycc=`#{RbConfig::MAKEFILE_CONFIG['CC']} -v 2>&1`
+ if mycc =~ /gcc/ then
+ $CFLAGS << " -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion
"+
+ "-Wmissing-noreturn -Winline"
+ end
HEADER_DIRS = [
# First search /opt/local for macports
------------------------------------------------------------------------------------------------------------
Let's put it this way. It should work as long as folks use the same
compiler to compile their native extensions that they used to compile
Ruby with. I guess most people will. It should take care of the hard-
coded compiler flags and compiler name that don't come from
extconf.rb.
Regards,
-Markus