Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 91 lines (67 sloc) 3.368 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
= mkrf -- making C extensions for Ruby a bit easier

<tt>mkrf</tt> is a library for generating Rakefiles to build Ruby
extension modules written in C. It is intended as a replacement for
<tt>mkrf</tt>. The major difference between the two is that +mkrf+
builds you a Rakefile instead of a Makefile.

Major goals of mkrf include
* easy code reuse of its <tt>Availability</tt> class and
* simple, well documented, use of the <tt>Generator</tt> class.

== Basic Usage

<tt>mkrf</tt> works similarly to <tt>mkmf</tt> in that a user writes
an extension configuration file and then runs it, generating a
<tt>Rakefile</tt> in the current directory.

With mkmf it was customary to name the extension configuration file
"<tt>extconf.rb</tt>". With mkrf, you should name this file
"<tt>mkrf_conf.rb</tt>".

In general, <tt>mkrf_conf.rb</tt> should be placed in the root
directory of the extension
(ex. <tt>PROJECT_ROOT/ext/<i>name_of_module</i></tt>) and it expects,
by default, that files to be compiled have a <tt>.c</tt> extension and
reside in that same directory. If your project contains multiple
extension modules, then each one would get its own subdirectory under
<tt>PROJECT_ROOT/ext/</tt> and each would have its own
<tt>mkrf_conf.rb</tt> file.

The most basic usage looks like the following, where the name of the
extension module being built is "libtrivial":

  require 'mkrf'
  Mkrf::Generator.new('libtrivial')

Extra arguments may be passed to the Rakefile generator in a block:
  
  Mkrf::Generator.new('libtrivial') do |g|
    g.logger.level = Logger::WARN
    g.include_library('z')
  end

Another example:

  Mkrf::Generator.new('libxml') do |g|
    g.include_library('socket','socket')
    g.include_header('libxml/xmlversion.h',
                     '/opt/include/libxml2',
                     '/usr/local/include/libxml2',
                     '/usr/include/libxml2')
  end


== Helpers

mkrf also comes with <tt>rakehelper.rb</tt> -- a module which contains
methods you may want to use in your project's top-level Rakefile. The
docs on using rakehelper do not exist at the moment, but for the time
being, have a look at <tt>examples/trivial/Rakefile</tt> to get an
idea of how they're used.


== Credits
* Jim Weirich for writing Rake


== Licence
mkrf is available under an MIT-style license.

Copyright (c) 2006 Kevin Clark

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Something went wrong with that request. Please try again.