[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] Add native ruby binding to Subversion distribution

From: Yoshiki Hayashi <yoshiki_at_xemacs.org>
Date: 2001-10-19 12:27:13 CEST

Here's a patch to build native Ruby binding inside
Subversion distribution. All you have to do is:

1. unpack svn-ruby-0.2.tar.gz from
   http://www.sodan.org/~penny/tmp/svn-ruby-0.2.tar.gz to
   subversion/bindings/ruby and rename svn-ruby-0.2 to

2. Apply following patch.

3. Add attached rb-config.rb and svn-ruby.m4 files to
   ac-helpers directory.

The default is not to build Ruby binding so you need to add
--enable-ruby-binding to configure. The reason is I'm not
sure it can be built on every system. I can only test it on
Debian unstable. However, it would be very nice if it can
be added to Subversion distribution and people can test it
so that I can shake out some bugs. I expect the default to
be --enable-ruby-binding in the future.

It installs Svn.la to
/usr/local/lib/site_ruby/1.6/i386-linux on my machine.
Probably Debian package or other package on FHS compliant
system doesn't like it but I decided to ignore it at this

What this patch does is to add dso type to gen-make.py and
build.conf. The main purpose is to add new link rule and to
be able to add more targets which creates Svn.la. The name
of dso rule consists of language name and .la name
concatenated with underscore like Ruby_Svn. This allows you
to add Python_Svn to create another Svn.la at the later time.

There's one problem with this patch, though. It adds hack
in SVN_FIND_RUBY to add -lpthread to LDFLAGS if -pthread is
present in CFLAGS. You can link without -lpthread but if
you try to load the Svn.so from Ruby interpreter, it barfs
on error that it cannot find libpthread.so. If
ruby/native/Svn.so is linked with -lpthread, it will be
loaded successfully. I don't know the correct answer to
this problem. I thought APR should add -lpthread but the
magical undocumented -pthread flag of GCC allows you to
compile and link C programs without problem. The linking
problem only occurs when a library linked with thread
enabled APR is dlopened by the program not linked with
pthread. Any ideas?

I appreciate any feedback.

ChangeLog and patch are attached below.


(RUBY_INCLUDES, ruby_moddir): New var.
(LDFLAGS): Now the value is determined by configure.


* Use $(MODULE) to link when target type is dso.
* Add new 'ruby-mod' custom rule to compile Ruby module.
* Add new target type dso. It is similar to lib but has
  different target name convention and link command.


* New target Ruby_Svn.


* Include new helper macro from svn-ruby.m4
* Call AC_LIBTOOL_DLOPEN to check whether the system
  supports dlopen.
* Call SVN_FIND_RUBY to determine if it can/should build
  Ruby binding.
* (BUILD_RULES, INSTALL_RULES): Add Ruby rule when
  Berkeley DB is present. Fs binding depends on it.


New file.

(SVN_FIND_RUBY): New function. If --enable-ruby-binding is
  given and correct inperter is found, add rules to build
  and install Ruby binding.


New file.

Return the location of header file or install directory
depending on the command line argument.

Index: ./Makefile.in
--- ./.svn/text-base/Makefile.in Wed Oct 10 19:55:16 2001
+++ ./Makefile.in Fri Oct 19 09:55:58 2001
@@ -51,18 +51,23 @@
+ruby_moddir = @ruby_moddir@
 LT_COMPILE = $(LIBTOOL) $(LTFLAGS) --mode=compile $(COMPILE) -o $@ -c $<
+COMPILE_RUBY_MOD = $(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) $(CFLAGS) $(RUBY_INCLUDES) $(INCLUDES) -o $@ -c $<
 LINK = $(LIBTOOL) $(LTFLAGS) --mode=link $(LT_LDFLAGS) $(COMPILE) $(LDFLAGS) -rpath $(libdir)
+MODULE = $(LIBTOOL) $(LTFLAGS) $(LT_LDFLAGS) $(COMPILE) -module -avoid-version $(LDFLAGS) -rpath $(libdir)
 INSTALL_LIB = $(LIBTOOL) --mode=install $(INSTALL)
@@ -72,8 +77,10 @@
 all: external-all local-all
 clean: external-clean local-clean
Index: ./ac-helpers/svn-ruby.m4
Index: ./ac-helpers/rb-config.rb
Index: ./gen-make.py
--- ./.svn/text-base/gen-make.py Mon Oct 8 17:55:01 2001
+++ ./gen-make.py Thu Oct 18 21:45:14 2001
@@ -115,6 +115,11 @@
         # something we don't know, so just include it directly
+ if parser.get(target, 'type') == 'dso':
+ link = '$(MODULE)'
+ else:
+ link = '$(LINK)'
     targ_varname = string.replace(target, '-', '_')
     ldflags = parser.get(target, 'link-flags')
     add_deps = parser.get(target, 'add-deps')
@@ -122,11 +127,11 @@
     ofile.write('%s_DEPS = %s %s\n'
                 '%s_OBJECTS = %s\n'
                 '%s: $(%s_DEPS)\n'
- '\tcd %s && $(LINK) -o %s %s $(%s_OBJECTS) %s $(LIBS)\n\n'
+ '\tcd %s && %s -o %s %s $(%s_OBJECTS) %s $(LIBS)\n\n'
                 % (targ_varname, string.join(objects + deps), add_deps,
                    targ_varname, objnames,
                    tpath, targ_varname,
- path, tfile, ldflags, targ_varname, string.join(libs)))
+ path, link, tfile, ldflags, targ_varname, string.join(libs)))
     custom = parser.get(target, 'custom')
     if custom == 'apache-mod':
@@ -137,6 +142,14 @@
           ofile.write('%s%s: %s\n\t$(COMPILE_APACHE_MOD)\n'
                       % (src[:-2], objext, src))
+ elif custom == 'ruby-mod':
+ # special build, needing Ruby includes
+ ofile.write('# build these special -- use RUBY_INCLUDES\n')
+ for src in sources:
+ if src[-2:] == '.c':
+ ofile.write('%s%s: %s\n\t$(COMPILE_RUBY_MOD)\n'
+ % (src[:-2], objext, src))
+ ofile.write('\n')
   for g_name, g_targets in install.items():
     target_names = [ ]
@@ -303,6 +316,10 @@
         install = 'lib'
     elif type == 'doc':
+ elif type == 'dso':
+ ignore, tname = string.split(name, '_')
+ tfile = tname + '.la'
+ self.objext = '.lo'
       raise GenMakeError('ERROR: unknown build type: ' + type)
@@ -325,6 +342,7 @@
 _default_sources = {
   'lib' : '*.c',
   'exe' : '*.c',
+ 'dso' : '*.c',
   'doc' : '*.texi',
Index: ./build.conf
--- ./.svn/text-base/build.conf Mon Oct 8 17:55:03 2001
+++ ./build.conf Thu Oct 18 21:45:56 2001
@@ -145,6 +145,14 @@
 # there are some .c files included by others, so *.c isn't appropriate
 sources = hashtable.c xmlparse.c xmlrole.c xmltok.c
+type = dso
+path = subversion/bindings/ruby/native
+libs = libsvn_client libsvn_wc libsvn_ra libsvn_repos libsvn_fs
+ libsvn_delta libsvn_subr $(SVN_APR_LIBS)
+custom = ruby-mod
+install = ruby-mod
 # ----------------------------------------------------------------------------
Index: ./configure.in
--- ./.svn/text-base/configure.in Fri Oct 12 14:45:57 2001
+++ ./configure.in Fri Oct 19 10:10:11 2001
@@ -25,6 +25,7 @@
 dnl Grab the libtool macros
@@ -109,6 +110,7 @@
 dnl Check for libtool -- we'll definitely need it for all our shared libs!
 echo "configuring libtool now"
 dnl Configure neon --------------------------
@@ -143,6 +145,12 @@
 dnl find Apache
+dnl find Ruby
 dnl ### should we ever bother with the system install?
 dnl use abs_srcdir. sometimes during installation, libtool will relink the
 dnl library. when it does this, it does a "cd", so a relative use of
@@ -169,8 +177,8 @@
 INSTALL_RULES="install-lib install-bin install-include"
 BUILD_RULES="lib bin test"
 if test "$svn_lib_berkeley_db" = "yes"; then
- BUILD_RULES="lib fs-lib bin fs-bin $BUILD_APACHE_RULE test fs-test"
- INSTALL_RULES="install-lib install-fs-lib install-bin install-fs-bin $INSTALL_APACHE_RULE install-include"
+ BUILD_RULES="lib fs-lib bin fs-bin $BUILD_APACHE_RULE $BUILD_RUBY_RULE test fs-test"
+ INSTALL_RULES="install-lib install-fs-lib install-bin install-fs-bin $INSTALL_APACHE_RULE $INSTALL_RUBY_RULE install-include"


[ --enable-ruby-binding Turn on native Ruby binding support],
  if test "$enableval" = "yes"; then

if test "$ruby_binding" = "yes"; then
  if test "$RUBY" = ""; then
    AC_MSG_WARN(Ruby interpreter not found. Native Ruby binding will not be compiled)
    AC_MSG_CHECKING(for Ruby header)
    ruby_header="`ruby ${abs_srcdir}/ac-helpers/rb-config.rb include`"
    if test "$ruby_header" = ""; then
      AC_MSG_WARN([ruby.h not found. Native Ruby binding will not be compiled])
      case "$EXTRA_CFLAGS" in
          LDFLAGS="$LDFLAGS -lpthread"
      ruby_moddir="`ruby ${abs_srcdir}/ac-helpers/rb-config.rb site-install`"


  require 'rbconfig'
rescue LoadError
  exit 1

command = ARGV.shift

if command == 'include' then
  if File.exists?(File.join(Config::CONFIG['archdir'], 'ruby.h')) then
    print Config::CONFIG['archdir']
elsif command == 'site-install' then
  print Config::CONFIG['sitearchdir']

Yoshiki Hayashi

To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Oct 21 14:36:45 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.