From: Tim Hunter Date: 2004-04-21T08:04:07+09:00 Subject: Re: C ext best practices On Tue, 20 Apr 2004 13:43:34 -0600, Ara.T.Howard wrote: > > rubyists- > > i'm wrapped a little libary that already has a full on gnu autotools > installation, call it > > libfoobar-0.0.0.tgz > > obviously, this unpacks like > > libfoobar-0.0.0/ > libfoobar-0.0.0/README > libfoobar-0.0.0/configure > libfoobar-0.0.0/foobar.c > > if i were to wrap this package for ruby, i'd like to be able to > > require 'foobar' > > what is the preferred means to make an extenstion like this? > > * foobar.c defines ruby bindings and extconf.rb must be called with > '--with-foobar-dir' pointing to an install of libfoobar? > > * _foobar.c defines ruby bindings and all libfoobar source files are > simply > dropped in same directory such that > > ruby extconf.rb > make > > results in a foobar.so containing all required stuff? > > thoughts? > > -a Well, I won't argue that it's "best practices" but here's what RMagick does. RMagick assumes that the ImageMagick library, libMagick, has already been installed in a separate step. RMagick uses the standard GNU ./configure, make, make install sequence. The configure script (built by autoconf) handles any non-Ruby configuration - such as finding libMagick - and builds a custom Makefile, extconf.rb, and a metaconfig file for install.rb. The Makefile's all: target runs install.rb's config and setup steps. The Makefile's install: target runs install.rb's install step. Here's RMagick's Makefile.in. This will probably make it clearer than my prose description. (The ./configure script also accepts a number of options, like --with-std-ruby, that it passes on to install.rb via @RUBY_CONFIG_OPTS@.) # Path to ruby interpreter RUBY=@RUBY@ # Any extra options from configure script to pass to 'install.rb config' RUBY_CONFIG_OPTS=@RUBY_CONFIG_OPTS@ all: config.save $(RUBY) install.rb setup install: $(RUBY) install.rb install clean: config.save $(RUBY) install.rb clean distclean: config.save $(RUBY) install.rb clean rm -f Makefile ext/RMagick/extconf.rb metaconfig rm -f config.status Makefile config.cache config.log rm -rf autom4te.cache uninstall: config.save $(RUBY) uninstall.rb $(RUBY_CONFIG_OPTS) config.save: metaconfig $(RUBY) install.rb config $(RUBY_CONFIG_OPTS)