Generator is concerned with taking configuration for an extension and writing a Rakefile to the local filesystem which will later be used to build the extension.
You will typically only create one Generator per extconf.rb file, which in turn will generate a Rakefile for building one extension module.
In the most basic usage, Generator simply takes the name of the library to compile:
require 'mkrf' Mkrf::Generator.new('libtrivial')
Configuration of the build can be passed to the Generator constructor as a block:
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
It is also possible to specify the library paths in include_library
Mkrf::Generator.new('libxml') do |g| g.include_library('socket','socket', '/usr/local/lib/libxml') end
Create a Generator object which writes a Rakefile to the current directory of the local filesystem.
Params:
extension_name — the name of the extension
source_patterns — an array of patterns describing source files to be compiled. [“*.c”] is the default.
# File lib/mkrf/generator.rb, line 73 73: def initialize(extension_name, source_patterns = ["*.c"], availability_options = {}) 74: @sources = source_patterns 75: @extension_name = extension_name + ".#{CONFIG['DLEXT']}" 76: @available = Mkrf::Availability.new(availability_options) 77: @defines = [] 78: if @sources[0] =~ /cpp/ 79: @cc = 'g++' # should be in CONFIG['C++'] but is not. 80: @source_extension = 'cpp' 81: else 82: @cc = CONFIG['CC'] 83: @source_extension = 'c' 84: end 85: 86: @objects = '' 87: @ldshared = '' 88: @cflags = "#{CONFIG['CCDLFLAGS']} #{CONFIG['CFLAGS']} #{CONFIG['ARCH_FLAG']}" 89: 90: yield self if block_given? 91: write_rakefile 92: end
Logs a fatal error and exits with a non-zero code (defaults to 1)
# File lib/mkrf/generator.rb, line 147 147: def abort!(str, code = 1) 148: logger.fatal str 149: exit code 150: end
Add a define to the compile string. Example:
Mkrf::Generator.new('my_library') do |g| g.add_define('HAVE_PTHREADS') end
Params:
defn — string to add to compile time defines
# File lib/mkrf/generator.rb, line 107 107: def add_define(defn) 108: @available.defines << defn 109: end
Returns true if the function is able to be called based on libraries and headers currently loaded. Returns false otherwise.
Params:
function — the function to check for
# File lib/mkrf/generator.rb, line 132 132: def has_function?(function) 133: @available.has_function? function 134: end
Include a header in the compile. Returns false if the header is not available, returns non-false otherwise. As a side effect, a compile time define occurs as HAVE_ appended with the name of the header in upper and scored case. Parameters are the same as Mkrf::Availability#include_header
# File lib/mkrf/generator.rb, line 123 123: def include_header(*args) 124: @available.include_header(*args) 125: end
Include a library in the compile. Returns false if the library is not available. Returns non-false otherwise. Parameters are the same as Mkrf::Availability#include_library
# File lib/mkrf/generator.rb, line 114 114: def include_library(*args) 115: @available.include_library(*args) 116: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.