| Class | Mkrf::Generator |
| In: |
lib/mkrf/generator.rb
|
| Parent: | Object |
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
| CONFIG | = | Config::CONFIG |
| additional_code | [RW] | Any extra code, given as a string, to be appended to the Rakefile. |
| cflags | [RW] |
You may append to these attributes directly in your Generator.new block, for example:
g.objects << ’ ../common/foo.o ../common/bar.so
-lmystuff‘ or g.cflags << ’ -ansi
-Wall‘
Note the extra space at the beginning of those strings. |
| ldshared | [RW] | Any additional options you‘d like appended to your system-specific linker command (which is used to build the shared library). |
| objects | [RW] | objects is for adding additional object files to the link-edit command — outside of the ones that correspond to the source files. |
Create a Generator object which writes a Rakefile to the current directory of the local filesystem.
Params:
Add a define to the compile string. Example:
Mkrf::Generator.new('my_library') do |g|
g.add_define('HAVE_PTHREADS')
end
Params:
Returns true if the function is able to be called based on libraries and headers currently loaded. Returns false otherwise.
Params:
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
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
Returns mkrf‘s logger instance. You can use this to set logging levels.
Mkrf::Generator.new('libsomethin') do |g|
g.logger.level = Logger::WARN
end