なかだです。

  ちょっと前に nifty の ruby 会議室で、VC を持ってないんで gcc
で ActiveScriptRuby や Apollo 用の拡張ライブラリを作るにはどう
すればいいかって話がありました。たぶんランタイムライブラリが同
じもの同士なら forwarding DLL を使えば共有できるんじゃないかと
いうことで、実験的にこういうパッチを作ってみました。

  ライブラリ関連のマクロがこうなります。DLL と implib で名前が
ねじれててややこしいですが、ruby.so と $(LIBRUBY_SA) のインス
トール先は archlibdir になります。

: $(LIBRUBY_A)  (= $(RUBY_INSTALL_NAME)s)
  スタティックリンクライブラリ

: $(LIBRUBY_SO) (= $(RUBY_SO_NAME).dll)
  ruby DLL 本体

: $(LIBRUBY_SA) (= $(RUBY_INSTALL_NAME))
  $(LIBRUBY_SO)をリンクするインポートライブラリ (NEW)

: ruby.so       (ファイル名は共通)
  拡張ライブラリがリンクする Forwarding DLL

: $(LIBRUBY)    (= $(RUBY_SO_NAME))
  拡張ライブラリ用のインポートライブラリ

* ライブラリのファイル名は cygwin/mingw で lib*.a、mswin で
  *.lib という形

  蛇足かも知れませんが、i686-msvcrt というディレクトリも探すよ
うにするのもどうかなとか。

# それはそうと mingw は automode.o を使うようにしたりはしない
# んでしょうか。windres が CR をゴミとみなして大量に吐き出すん
# で、ログをファイルに落したりするとちょっとびっくり。


Index: Makefile.in =================================================================== RCS file: /cvs/ruby/src/ruby/Makefile.in,v retrieving revision 1.25 diff -u -2 -p -r1.25 Makefile.in --- Makefile.in 2001/05/07 09:26:23 1.25 +++ Makefile.in 2001/06/17 14:09:40 @@ -37,4 +37,5 @@ TEENY= @TEENY@ LIBRUBY_A = @LIBRUBY_A@ +LIBRUBY_SA = @LIBRUBY_SA@ LIBRUBY_SO = @LIBRUBY_SO@ LIBRUBY_ALIASES= @LIBRUBY_ALIASES@ Index: configure.in =================================================================== RCS file: /cvs/ruby/src/ruby/configure.in,v retrieving revision 1.92 diff -u -2 -p -r1.92 configure.in --- configure.in 2001/06/11 05:31:17 1.92 +++ configure.in 2001/06/16 15:13:44 @@ -848,4 +848,5 @@ LIBRUBY_LDSHARED=$LDSHARED LIBRUBY_DLDFLAGS=$DLDFLAGS LIBRUBY_SO='lib$(RUBY_INSTALL_NAME).so.$(MAJOR).$(MINOR).$(TEENY)' +LIBRUBY_SA='' LIBRUBY_ALIASES='lib$(RUBY_INSTALL_NAME).so' ENABLE_SHARED=no @@ -970,12 +971,13 @@ case "$target_os" in if test x"$enable_shared" = xyes; then LIBRUBY_SO='$(RUBY_SO_NAME)'.dll - LIBRUBY_DLDFLAGS='--dllname=$@ --output-lib=$(LIBRUBY) --add-stdcall-alias --def=$(RUBYDEF)' + LIBRUBY_DLDFLAGS='--dllname=$@ --output-lib=$(LIBRUBY_SA) --add-stdcall-alias --def=$(RUBYDEF)' else LIBRUBY_SO=dummy - LIBRUBY_DLDFLAGS='--output-exp=$(RUBY_INSTALL_NAME).exp --dllname=$(RUBY_INSTALL_NAME)$(EXEEXT) --output-lib=$(LIBRUBY) --add-stdcall-alias --def=$(RUBYDEF)' + LIBRUBY_DLDFLAGS='--output-exp=$(RUBY_INSTALL_NAME).exp --dllname=$(RUBY_INSTALL_NAME)$(EXEEXT) --output-lib=$(LIBRUBY_SA) --add-stdcall-alias --def=$(RUBYDEF)' fi LIBRUBY_ALIASES='' LIBRUBY_A='lib$(RUBY_INSTALL_NAME)s.a' LIBRUBY='lib$(RUBY_SO_NAME).a' + LIBRUBY_SA='lib$(RUBY_INSTALL_NAME).a' LIBRUBYARG='-L. -l$(RUBY_SO_NAME)' FIRSTMAKEFILE=GNUmakefile:cygwin/GNUmakefile.in @@ -1000,4 +1002,5 @@ AC_SUBST(RUBY_INSTALL_NAME) AC_SUBST(RUBY_SO_NAME) AC_SUBST(LIBRUBY_A) +AC_SUBST(LIBRUBY_SA) AC_SUBST(LIBRUBY_SO) AC_SUBST(LIBRUBY_ALIASES) @@ -1068,4 +1071,10 @@ fi AC_DEFINE_UNQUOTED(RUBY_ARCHLIB, "${RUBY_LIB_PATH}/${arch}") AC_DEFINE_UNQUOTED(RUBY_SITE_ARCHLIB, "${RUBY_SITE_LIB_PATH2}/${arch}") +case ${target_os} in + mingw*|mswin*) + AC_DEFINE_UNQUOTED(RUBY_ARCHLIB2, "${RUBY_LIB_PATH}/${target_cpu}-msvcrt") + AC_DEFINE_UNQUOTED(RUBY_SITE_ARCHLIB2, "${RUBY_SITE_LIB_PATH2}/${target_cpu}-msvcrt") + ;; +esac AC_ARG_WITH(search-path, Index: instruby.rb =================================================================== RCS file: /cvs/ruby/src/ruby/instruby.rb,v retrieving revision 1.19 diff -u -2 -p -r1.19 instruby.rb --- instruby.rb 2001/04/30 17:55:56 1.19 +++ instruby.rb 2001/05/30 09:40:18 @@ -65,6 +65,12 @@ File.makedirs sitelibdir, true File.makedirs sitearchlibdir, true -if RUBY_PLATFORM =~ /-aix/ +if f = CONFIG["LIBRUBY_SA"] and File.exist?(f) + File.install f, archlibdir, 0644, true +end +case RUBY_PLATFORM +when /-aix/ File.install "ruby.imp", archlibdir, 0644, true +when /cygwin|mingw|mswin/ + File.install "ruby.so", archlibdir, 0755, true end Index: ruby.c =================================================================== RCS file: /cvs/ruby/src/ruby/ruby.c,v retrieving revision 1.47 diff -u -2 -p -r1.47 ruby.c --- ruby.c 2001/05/30 09:12:34 1.47 +++ ruby.c 2001/06/14 05:34:10 @@ -270,4 +270,7 @@ ruby_init_loadpath() #endif ruby_incpush(RUBY_RELATIVE(RUBY_SITE_ARCHLIB)); +#ifdef RUBY_SITE_ARCHLIB2 + ruby_incpush(RUBY_RELATIVE(RUBY_SITE_ARCHLIB2)); +#endif ruby_incpush(RUBY_RELATIVE(RUBY_SITE_LIB2)); ruby_incpush(RUBY_RELATIVE(RUBY_SITE_LIB)); @@ -277,4 +280,7 @@ ruby_init_loadpath() #endif ruby_incpush(RUBY_RELATIVE(RUBY_ARCHLIB)); +#ifdef RUBY_ARCHLIB2 + ruby_incpush(RUBY_RELATIVE(RUBY_ARCHLIB2)); +#endif ruby_incpush(RUBY_RELATIVE(RUBY_LIB)); @@ -283,4 +289,13 @@ ruby_init_loadpath() ruby_incpush("."); } + +#ifdef LIBRUBY_SO + if (libruby) { + static const char ruby_so[] = RUBY_ARCHLIB"/ruby"DLEXT; + rb_rescue2(rb_require, (VALUE)RUBY_RELATIVE(ruby_so), + rb_require, (VALUE)(ruby_so+sizeof(RUBY_ARCHLIB)), + rb_eLoadError, 0); + } +#endif } Index: cygwin/GNUmakefile.in =================================================================== RCS file: /cvs/ruby/src/ruby/cygwin/GNUmakefile.in,v retrieving revision 1.19 diff -u -2 -p -r1.19 GNUmakefile.in --- cygwin/GNUmakefile.in 2001/05/28 16:07:34 1.19 +++ cygwin/GNUmakefile.in 2001/06/18 07:44:43 @@ -7,4 +7,5 @@ ifneq (,$(findstring no, $(ENABLE_SHARED LIBRUBYARG = $(LIBRUBY_A) else + LIBRUBYARG = -L. -l$(RUBY_INSTALL_NAME) CPPFLAGS += -DLIBRUBY_SO=\"$(LIBRUBY_SO)\" endif @@ -17,9 +18,14 @@ else WPROGRAM = $(RUBYW_INSTALL_NAME)$(EXEEXT) RUBYDEF = $(RUBY_INSTALL_NAME).def +LIBRUBYDEF = $(RUBY_SO_NAME).def SOLIBS := $(LIBRUBY_SO).res.@OBJEXT@ $(SOLIBS) EXTOBJS += $(@:$(EXEEXT)=.res.@OBJEXT@) + +all: $(RUBY_INSTALL_NAME).@DLEXT@ -$(LIBRUBY_SO): $(RUBYDEF) $(LIBRUBY_SO).res.@OBJEXT@ -$(LIBRUBY): $(LIBRUBY_SO) +$(LIBRUBY_SO) $(LIBRUBY_SA): $(RUBYDEF) $(LIBRUBY_SO).res.@OBJEXT@ +$(RUBY_INSTALL_NAME).@DLEXT@ $(LIBRUBY): $(LIBRUBYDEF) $(LIBRUBY_SO) $(LIBRUBY_SA) + $(LDSHARED) --dllname=$(RUBY_INSTALL_NAME).@DLEXT@ --output-lib=$(LIBRUBY) \ + --add-stdcall-alias --def=$(LIBRUBYDEF) -o $(RUBY_INSTALL_NAME).@DLEXT@ %.res.@OBJEXT@: %.rc @@ -42,2 +48,7 @@ $(RUBYDEF): $(LIBRUBY_A) @NM@ --extern-only --defined-only $(LIBRUBY_A) | \ @MINIRUBY@ -ne 'puts $$1 if / [CDT] _(.*)$$/' >> $(RUBYDEF) + +$(LIBRUBYDEF): $(RUBYDEF) + @MINIRUBY@ -lp \ + -e '($$_<<"=$(RUBY_SO_NAME)."+$$_).sub!(/^Init_ext=/,"Init_ruby=") unless 1../^EXPORTS/' \ + $< > $@ Index: djgpp/config.sed =================================================================== RCS file: /cvs/ruby/src/ruby/djgpp/config.sed,v retrieving revision 1.2 diff -u -2 -p -r1.2 config.sed --- djgpp/config.sed 2000/12/06 09:10:15 1.2 +++ djgpp/config.sed 2001/06/18 09:08:40 @@ -53,4 +53,5 @@ s%@LIBRUBY@%libruby.a%g s%@LIBRUBY_A@%libruby.a%g s%@LIBRUBYARG@%libruby.a%g +s%@LIBRUBY_SA@%%g s%@LIBRUBY_SO@%%g s%@SOLIBS@%%g Index: win32/Makefile.sub =================================================================== RCS file: /cvs/ruby/src/ruby/win32/Makefile.sub,v retrieving revision 1.12 diff -u -2 -p -r1.12 Makefile.sub --- win32/Makefile.sub 2001/06/09 07:41:44 1.12 +++ win32/Makefile.sub 2001/06/18 08:49:48 @@ -53,5 +53,5 @@ EXEEXT = .exe PROGRAM=$(RUBY_INSTALL_NAME)$(EXEEXT) WPROGRAM=$(RUBYW_INSTALL_NAME)$(EXEEXT) -RUBYDEF = $(RUBY_SO_NAME).def +RUBYDEF = $(RUBY_INSTALL_NAME).def STACK = 0x2000000 @@ -60,8 +60,10 @@ ORGLIBPATH = $(LIB) #### End of system configuration section. #### -LIBRUBY_A = lib$(RUBY_INSTALL_NAME).lib +LIBRUBYDEF = $(RUBY_SO_NAME).def +LIBRUBY_A = $(RUBY_INSTALL_NAME)s.lib +LIBRUBY_SA = $(RUBY_INSTALL_NAME).lib LIBRUBY_SO = $(RUBY_SO_NAME).dll -LIBRUBY = $(RUBY_SO_NAME).lib -LIBRUBYARG = $(LIBRUBY) +LIBRUBY = $(RUBY_SO_NAME).lib +LIBRUBYARG = $(LIBRUBY_SA) EXTOBJS = dmyext.obj @@ -109,5 +111,5 @@ OBJS = array.obj \ all: miniruby$(EXEEXT) rbconfig.rb ext/extmk.rb \ - $(LIBRUBY) $(MISCLIBS) + $(RUBY_INSTALL_NAME).so $(LIBRUBY) $(MISCLIBS) set LIB=..\..;$(ORGLIBPATH) @.\miniruby$(EXEEXT) -Cext extmk.rb @@ -144,21 +146,21 @@ $(WPROGRAM): $(MAINOBJ) $(WINMAINOBJ) $( $(LIBRUBY_A): $(OBJS) dmyext.obj lib -nologo /OUT:$@ $(OBJS) dmyext.obj - -$(LIBRUBY): $(RUBYDEF) - lib -nologo /OUT:$@ /DEF:$(RUBYDEF) -$(LIBRUBY_SO): $(LIBRUBY_A) $(EXTOBJS) $(RUBYDEF) $@.res - set LIB=.\win32;$(ORGLIBPATH) - $(CC) $(LDFLAGS) $(MAINOBJ) $(EXTOBJS) $(LIBRUBY_A) $@.res $(LIBS) \ - -Fe$@ -link -dll -def:$(RUBYDEF) - -!if "$(LIBRUBY_SO)" != "rubymw.dll" -rubymw.dll: $(LIBRUBY) - $(CC) -nologo $(EXTOBJS) $(LIBRUBY) -o $@ -link /DLL /DEF:$(RUBYDEF) -!endif +$(RUBY_INSTALL_NAME).so $(LIBRUBY): $(LIBRUBYDEF) dmyext.obj $(LIBRUBY_SO) $(LIBRUBY_SA) + $(CC) -LD $(LIBRUBYDEF) $(LDFLAGS) dmyext.obj $(LIBRUBY_SA) \ + -Feruby.so -link -implib:$(LIBRUBY) -incremental:no + +$(LIBRUBY_SO) $(LIBRUBY_SA): $(EXTOBJS) $(RUBYDEF) $(LIBRUBY_SO).res + $(CC) -LD $(RUBYDEF) $(LDFLAGS) $(MAINOBJ) $(EXTOBJS) $(LIBRUBY_A) $(LIBRUBY_SO).res $(LIBS) \ + -Fe$(LIBRUBY_SO) -link -implib:$(LIBRUBY_SA) -incremental:no $(RUBYDEF): $(LIBRUBY_A) miniruby$(EXEEXT) .\miniruby$(EXEEXT) $(srcdir)/win32/mkexports.rb -output=$@ $(LIBRUBY_A) +$(LIBRUBYDEF): $(RUBYDEF) + .\miniruby$(EXEEXT) -lp \ + -e '$$_+="=$(RUBY_SO_NAME)."+$$_; sub!(/^Init_ext=/, "Init_ruby=") unless 1../^EXPORTS/' \ + $(RUBYDEF) > $@ + install: rbconfig.rb .\miniruby.exe $(srcdir)/instruby.rb $(DESTDIR) Index: win32/config.h.in =================================================================== RCS file: /cvs/ruby/src/ruby/win32/config.h.in,v retrieving revision 1.9 diff -u -2 -p -r1.9 config.h.in --- win32/config.h.in 2001/05/02 17:09:22 1.9 +++ win32/config.h.in 2001/05/31 09:36:00 @@ -50,8 +50,13 @@ #define RUBY_LIB "/lib/ruby/1.7" #define RUBY_SITE_LIB "/lib/ruby/site_ruby" -#define RUBY_SITE_LIB2 "/lib/ruby/site_ruby/1.7" -#define RUBY_PLATFORM "i586-mswin32" -#define RUBY_ARCHLIB "/lib/ruby/1.7/i586-mswin32" -#define RUBY_SITE_ARCHLIB "/lib/ruby/site_ruby/1.7/i586-mswin32" +#define RUBY_SITE_LIB2 RUBY_SITE_LIB"/1.7" +#define RUBY_PLATFORM RUBY_CPU"-"RUBY_OS +#define RUBY_CPU "i586" +#define RUBY_OS "mswin32" +#define RUBY_OS2 "msvcrt" +#define RUBY_ARCHLIB RUBY_LIB"/"RUBY_PLATFORM +#define RUBY_SITE_ARCHLIB RUBY_SITE_LIB2"/"RUBY_PLATFORM +#define RUBY_ARCHLIB2 RUBY_LIB"/"RUBY_CPU"-"RUBY_OS2 +#define RUBY_SITE_ARCHLIB2 RUBY_SITE_LIB2"/"RUBY_CPU"-"RUBY_OS2 #define SIZEOF_INT 4 Index: win32/config.status.in =================================================================== RCS file: /cvs/ruby/src/ruby/win32/config.status.in,v retrieving revision 1.9 diff -u -2 -p -r1.9 config.status.in --- win32/config.status.in 2001/04/14 04:38:19 1.9 +++ win32/config.status.in 2001/06/14 00:52:30 @@ -51,7 +51,8 @@ s%@STRIP@%%g s%@LIBRUBY_DLDFLAGS@%%g s%@RUBY_INSTALL_NAME@%ruby%g -s%@RUBY_SO_NAME@%ruby.mswin32%g -s%@LIBRUBY_A@%lib$(RUBY_INSTALL_NAME).lib%g -s%@LIBRUBY_SO@%%g +s%@RUBY_SO_NAME@%mswin32-ruby17%g +s%@LIBRUBY_A@%$(RUBY_INSTALL_NAME)s.lib%g +s%@LIBRUBY_SA@%$(RUBY_INSTALL_NAME).lib%g +s%@LIBRUBY_SO@%$(RUBY_SO_NAME).dll%g s%@LIBRUBY_ALIASES@%%g s%@LIBRUBY@%$(RUBY_SO_NAME).lib%g
-- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦