Cc always picks ruby/ruby.h on OS X

 ruby 1.8 の tk ライブラリが OS X 上でビルドできない件です。

 OS X の gcc には仕掛けがあり、 ruby 1.9 が入っていなくても
#include <ruby/ruby.h> は

/System/Library/Frameworks/Ruby.framework/Headers/ruby.h

を拾ってしまいます。(framework名/Headers以下のパス)

 以下の修正で直ります。コミットしてよいでしょうか。

Index: trunk/ext/tk/tcltklib.c

— trunk/ext/tk/tcltklib.c (revision 17964)
+++ trunk/ext/tk/tcltklib.c (working copy)
@@ -8,8 +8,7 @@

#include “ruby.h”

-#ifdef HAVE_RUBY_RUBY_H
-/* #include “ruby/ruby.h” */
+#ifdef HAVE_RUBY_SIGNAL_H
#include “ruby/signal.h”
#ifdef HAVE_RUBY_ENCODING_H
#include “ruby/encoding.h”
Index: trunk/ext/tk/extconf.rb

— trunk/ext/tk/extconf.rb (revision 17964)
+++ trunk/ext/tk/extconf.rb (working copy)
@@ -5,7 +5,7 @@ require ‘mkmf’
is_win32 = (/mswin|mingw|cygwin|bccwin|wince/ =~ RUBY_PLATFORM)
#is_macosx = (/darwin/ =~ RUBY_PLATFORM)

-have_header(“ruby/ruby.h”)
+have_header(“ruby/signal.h”)
have_header(“ruby/encoding.h”)
have_func(“ruby_native_thread_p”, “ruby.h”)
have_func(“rb_errinfo”, “ruby.h”)
Index: trunk/ext/tk/tkutil/tkutil.c

— trunk/ext/tk/tkutil/tkutil.c (revision 17964)
+++ trunk/ext/tk/tkutil/tkutil.c (working copy)
@@ -11,8 +11,7 @@

#include “ruby.h”

-#ifdef HAVE_RUBY_RUBY_H
-/* #include “ruby/ruby.h” */
+#ifdef HAVE_RUBY_SIGNAL_H
#include “ruby/signal.h”
#include “ruby/st.h”
#else
Index: branches/ruby_1_8/ext/tk/tcltklib.c

— branches/ruby_1_8/ext/tk/tcltklib.c (revision 17964)
+++ branches/ruby_1_8/ext/tk/tcltklib.c (working copy)
@@ -8,8 +8,7 @@

#include “ruby.h”

-#ifdef HAVE_RUBY_RUBY_H
-/* #include “ruby/ruby.h” */
+#ifdef HAVE_RUBY_SIGNAL_H
#include “ruby/signal.h”
#ifdef HAVE_RUBY_ENCODING_H
#include “ruby/encoding.h”
Index: branches/ruby_1_8/ext/tk/extconf.rb

— branches/ruby_1_8/ext/tk/extconf.rb (revision 17964)
+++ branches/ruby_1_8/ext/tk/extconf.rb (working copy)
@@ -5,7 +5,7 @@ require ‘mkmf’
is_win32 = (/mswin|mingw|cygwin|bccwin|wince/ =~ RUBY_PLATFORM)
#is_macosx = (/darwin/ =~ RUBY_PLATFORM)

-have_header(“ruby/ruby.h”)
+have_header(“ruby/signal.h”)
have_header(“ruby/encoding.h”)
have_func(“ruby_native_thread_p”, “ruby.h”)
have_func(“rb_errinfo”, “ruby.h”)
Index: branches/ruby_1_8/ext/tk/tkutil/tkutil.c

— branches/ruby_1_8/ext/tk/tkutil/tkutil.c (revision 17964)
+++ branches/ruby_1_8/ext/tk/tkutil/tkutil.c (working copy)
@@ -11,8 +11,7 @@

#include “ruby.h”

-#ifdef HAVE_RUBY_RUBY_H
-/* #include “ruby/ruby.h” */
+#ifdef HAVE_RUBY_SIGNAL_H
#include “ruby/signal.h”
#include “ruby/st.h”
#else

At Wed, 9 Jul 2008 10:14:07 +0900,
I wrote:

 ruby 1.8 の tk ライブラリが OS X 上でビルドできない件です。

 OS X の gcc には仕掛けがあり、 ruby 1.9 が入っていなくても
#include <ruby/ruby.h> は

/System/Library/Frameworks/Ruby.framework/Headers/ruby.h

を拾ってしまいます。(framework名/Headers以下のパス)

 以下の修正で直ります。コミットしてよいでしょうか。

ext/tk/tkutil/extconf.rb のパッチが漏れていました。

Index: trunk/ext/tk/tcltklib.c

— trunk/ext/tk/tcltklib.c (revision 17964)
+++ trunk/ext/tk/tcltklib.c (working copy)
@@ -8,8 +8,7 @@

#include “ruby.h”

-#ifdef HAVE_RUBY_RUBY_H
-/* #include “ruby/ruby.h” */
+#ifdef HAVE_RUBY_SIGNAL_H
#include “ruby/signal.h”
#ifdef HAVE_RUBY_ENCODING_H
#include “ruby/encoding.h”
Index: trunk/ext/tk/extconf.rb

— trunk/ext/tk/extconf.rb (revision 17964)
+++ trunk/ext/tk/extconf.rb (working copy)
@@ -5,7 +5,7 @@ require ‘mkmf’
is_win32 = (/mswin|mingw|cygwin|bccwin|wince/ =~ RUBY_PLATFORM)
#is_macosx = (/darwin/ =~ RUBY_PLATFORM)

-have_header(“ruby/ruby.h”)
+have_header(“ruby/signal.h”)
have_header(“ruby/encoding.h”)
have_func(“ruby_native_thread_p”, “ruby.h”)
have_func(“rb_errinfo”, “ruby.h”)
Index: trunk/ext/tk/tkutil/extconf.rb

— trunk/ext/tk/tkutil/extconf.rb (revision 17964)
+++ trunk/ext/tk/tkutil/extconf.rb (working copy)
@@ -7,7 +7,7 @@ end

if has_tk
require ‘mkmf’

  • have_header(“ruby/ruby.h”)
  • have_header(“ruby/signal.h”)
    have_func(“rb_obj_instance_exec”, “ruby.h”)
    have_func(“rb_sym_to_s”, “ruby.h”)
    have_func(“strndup”, “string.h”)
    Index: trunk/ext/tk/tkutil/tkutil.c
    ===================================================================
    — trunk/ext/tk/tkutil/tkutil.c (revision 17964)
    +++ trunk/ext/tk/tkutil/tkutil.c (working copy)
    @@ -11,8 +11,7 @@

#include “ruby.h”

-#ifdef HAVE_RUBY_RUBY_H
-/* #include “ruby/ruby.h” */
+#ifdef HAVE_RUBY_SIGNAL_H
#include “ruby/signal.h”
#include “ruby/st.h”
#else
Index: branches/ruby_1_8/ext/tk/tcltklib.c

— branches/ruby_1_8/ext/tk/tcltklib.c (revision 17964)
+++ branches/ruby_1_8/ext/tk/tcltklib.c (working copy)
@@ -8,8 +8,7 @@

#include “ruby.h”

-#ifdef HAVE_RUBY_RUBY_H
-/* #include “ruby/ruby.h” */
+#ifdef HAVE_RUBY_SIGNAL_H
#include “ruby/signal.h”
#ifdef HAVE_RUBY_ENCODING_H
#include “ruby/encoding.h”
Index: branches/ruby_1_8/ext/tk/extconf.rb

— branches/ruby_1_8/ext/tk/extconf.rb (revision 17964)
+++ branches/ruby_1_8/ext/tk/extconf.rb (working copy)
@@ -5,7 +5,7 @@ require ‘mkmf’
is_win32 = (/mswin|mingw|cygwin|bccwin|wince/ =~ RUBY_PLATFORM)
#is_macosx = (/darwin/ =~ RUBY_PLATFORM)

-have_header(“ruby/ruby.h”)
+have_header(“ruby/signal.h”)
have_header(“ruby/encoding.h”)
have_func(“ruby_native_thread_p”, “ruby.h”)
have_func(“rb_errinfo”, “ruby.h”)
Index: branches/ruby_1_8/ext/tk/tkutil/extconf.rb

— branches/ruby_1_8/ext/tk/tkutil/extconf.rb (revision 17964)
+++ branches/ruby_1_8/ext/tk/tkutil/extconf.rb (working copy)
@@ -7,7 +7,7 @@ end

if has_tk
require ‘mkmf’

  • have_header(“ruby/ruby.h”)
  • have_header(“ruby/signal.h”)
    have_func(“rb_obj_instance_exec”, “ruby.h”)
    have_func(“rb_sym_to_s”, “ruby.h”)
    have_func(“strndup”, “string.h”)
    Index: branches/ruby_1_8/ext/tk/tkutil/tkutil.c
    ===================================================================
    — branches/ruby_1_8/ext/tk/tkutil/tkutil.c (revision 17964)
    +++ branches/ruby_1_8/ext/tk/tkutil/tkutil.c (working copy)
    @@ -11,8 +11,7 @@

#include “ruby.h”

-#ifdef HAVE_RUBY_RUBY_H
-/* #include “ruby/ruby.h” */
+#ifdef HAVE_RUBY_SIGNAL_H
#include “ruby/signal.h”
#include “ruby/st.h”
#else

At Wed, 9 Jul 2008 10:49:46 +0900,
Urabe S. wrote:

なんでtkは#include <ruby/ruby.h>してるんでしょうか?

一般的に#include したときにがどこから拾われてくるかはコンパイ
ラ実装依存で、ユーザーからはコントロールできないと思います。

 パッチをよく見てほしいんですが、 #include <ruby/ruby.h> はして
いませんよ。1.9系なのかの判定に使っていて、それがうまくいかない
理由が上記です。

 実際に #include しているのは <ruby/signal.h> なので、同ヘッダ
ファイルをチェックするようにするのが私のパッチです。

e$B$J$+$@$G$9!#e(B

At Wed, 9 Jul 2008 10:14:07 +0900,
Akinori MUSHA wrote in [ruby-dev:35396]:

e$B!!e(BOS X e$B$Ne(B gcc e$B$K$O;E3]$1$,$"$j!"e(B ruby 1.9 e$B$,F~$C$F$$$J$/$F$be(B
#include <ruby/ruby.h> e$B$Oe(B

/System/Library/Frameworks/Ruby.framework/Headers/ruby.h

e$B$r=&$C$F$7$^$$$^$9!#e(B(frameworke$BL>e(B/Headerse$B0J2<$N%Q%9e(B)

e$B$=$N>l9g!"e(Bruby/ruby.he$B$rFI$`$?$a$K$Oe(B #include
<ruby/ruby/ruby.h>
e$B$H$7$J$1$l$P$J$i$J$$$s$G$7$g$&$+!#e(B

e$BKNIt$G$9!#e(B

Akinori MUSHA e$B$5$s$O=q$-$^$7$?e(B:

e$B!!e(Bruby 1.8 e$B$Ne(B tk e$B%i%$%V%i%j$,e(B OS X e$B>e$G%S%k%I$G$-$J$$7o$G$9!#e(B

e$B!!e(BOS X e$B$Ne(B gcc e$B$K$O;E3]$1$,$"$j!"e(B ruby 1.9 e$B$,F~$C$F$$$J$/$F$be(B
#include <ruby/ruby.h> e$B$Oe(B

/System/Library/Frameworks/Ruby.framework/Headers/ruby.h

e$B$r=&$C$F$7$^$$$^$9!#e(B(frameworke$BL>e(B/Headerse$B0J2<$N%Q%9e(B)

e$B$J$s$Ge(Btke$B$Oe(B#include <ruby/ruby.h>e$B$7$F$k$s$G$7$g$&$+e(B?

e$B0lHLE*$Ke(B#include
e$B$7$?$H$-$Ke(Be$B$,$I$3$+$i=&$o$l$F$/$k$+$O%3%s%Q%$e(B
e$B%i<BAu0MB8$G!"%f!<%6!<$+$i$O%3%s%H%m!<%k$G$-$J$$$H;W$$$^$9!#e(B

e$B1J0f!wCNG=!%6e9)Bg$G$9!%e(B

e$B7nMK$K5_5^<V$GC4$.9~$^$l$F:rF|$^$GF~1!$7$F$?$N$Ge(B
e$BO"Mm$,CY$/$J$C$F$7$^$$!$$9$_$^$;$s!%e(B

From: “Akinori MUSHA” [email protected]
Subject: [ruby-dev:35396] cc always picks ruby/ruby.h on OS X
Date: Wed, 9 Jul 2008 10:14:07 +0900
Message-ID: [email protected]

e$B!!e(Bruby 1.8 e$B$Ne(B tk e$B%i%$%V%i%j$,e(B OS X e$B>e$G%S%k%I$G$-$J$$7o$G$9!#e(B
(snip)
e$B!!0J2<$N=$@5$GD>$j$^$9!#%3%_%C%H$7$F$h$$$G$7$g$&$+!#e(B

e$B$O$$!%$*<j?t$G$9$,e(B 1.8e$B!$e(B1.9
e$B6&$K$h$m$7$/$*4j$$CW$7$^$9!%e(B

e$B$J$+$@$G$9!#e(B

At Wed, 9 Jul 2008 22:12:21 +0900,
Nobuyoshi N. wrote in [ruby-dev:35412]:

e$B!!e(BOS X e$B$Ne(B gcc e$B$K$O;E3]$1$,$"$j!"e(B ruby 1.9 e$B$,F~$C$F$$$J$/$F$be(B
#include <ruby/ruby.h> e$B$Oe(B

/System/Library/Frameworks/Ruby.framework/Headers/ruby.h

e$B$r=&$C$F$7$^$$$^$9!#e(B(frameworke$BL>e(B/Headerse$B0J2<$N%Q%9e(B)

e$B$=$N>l9g!"e(Bruby/ruby.he$B$rFI$`$?$a$K$Oe(B #include <ruby/ruby/ruby.h>
e$B$H$7$J$1$l$P$J$i$J$$$s$G$7$g$&$+!#e(B

e$B>/$J$/$H$be(B #inlcude “ruby.h”
e$B$OF0$/$s$G$9$h$M!#0J2<$N$h$&$K$7$Fe(B
e$B$_$h$&$+$H;W$$$^$9$,!"e(BOS Xe$B$GLdBj$O$G$J$$$G$7$g$&$+!#e(B

Index: regint.h

— regint.h (revision 18021)
+++ regint.h (working copy)
@@ -814,5 +814,5 @@ extern int onig_is_code_in_cc_len P_((i
typedef void hash_table_type;
#ifdef RUBY
-#include <ruby/st.h>
+#include “ruby/st.h”
typedef st_data_t hash_data_type;
#else
Index: include/ruby.h

— include/ruby.h (revision 18021)
+++ include/ruby.h (working copy)
@@ -13,7 +13,25 @@
#define RUBY_H 1

-#include <ruby/ruby.h>
+#define HAVE_RUBY_DEFINES_H 1
+#define HAVE_RUBY_ENCODING_H 1
+#define HAVE_RUBY_INTERN_H 1
+#define HAVE_RUBY_IO_H 1
+#define HAVE_RUBY_MISSING_H 1
+#define HAVE_RUBY_MVM_H 1
+#define HAVE_RUBY_NODE_H 1
+#define HAVE_RUBY_ONIGURUMA_H 1
+#define HAVE_RUBY_RE_H 1
+#define HAVE_RUBY_REGEX_H 1
+#define HAVE_RUBY_RUBY_H 1
+#define HAVE_RUBY_SIGNAL_H 1
+#define HAVE_RUBY_ST_H 1
+#define HAVE_RUBY_UTIL_H 1
+#ifdef _WIN32
+#define HAVE_RUBY_WIN32_H 1
+#endif
+
+#include “ruby/ruby.h”
#if RUBY_VM
-#include <ruby/mvm.h>
+#include “ruby/mvm.h”
#endif

Index: include/rubyio.h

— include/rubyio.h (revision 18021)
+++ include/rubyio.h (working copy)
@@ -1 +1 @@
-#include <ruby/io.h>
+#include “ruby/io.h”
Index: include/rubysig.h

— include/rubysig.h (revision 18021)
+++ include/rubysig.h (working copy)
@@ -1 +1 @@
-#include <ruby/signal.h>
+#include “ruby/signal.h”
Index: include/ruby/intern.h

— include/ruby/intern.h (revision 18021)
+++ include/ruby/intern.h (working copy)
@@ -27,5 +27,5 @@ extern “C” {

include <varargs.h>

#endif
-#include <ruby/st.h>
+#include “ruby/st.h”

/*