Module: Mkmf::Lite
- Extended by:
- Memoist
- Defined in:
- lib/mkmf/lite.rb
Overview
The Lite module scopes the Mkmf module to differentiate it from the Mkmf module in the standard library.
Defined Under Namespace
Classes: Configuration
Constant Summary collapse
- MKMF_LITE_VERSION =
The version of the mkmf-lite library
'0.9.0'
Class Method Summary collapse
Instance Method Summary collapse
-
#check_offsetof(struct_type, field, headers = [], *directories) ⇒ Object
Returns the offset of
fieldwithinstruct_typeusingheaders, or common headers, plus stddef.h, if no headers are specified. -
#check_sizeof(type, headers = [], *directories) ⇒ Object
Returns the sizeof
typeusingheaders, or common headers if no headers are specified. -
#check_valueof(constant, headers = [], *directories) ⇒ Object
Returns the value of the given
constant(which could also be a macro) usingheaders, or common headers if no headers are specified. - #configuration ⇒ Object
- #configure(&block) ⇒ Object
-
#have_func(function, headers = []) ⇒ Object
Check for the presence of the given
functionin the common header files, or within anyheadersthat you provide. -
#have_header(header, *directories) ⇒ Object
Check for the presence of the given
headerfile. -
#have_library(library, function = nil, headers = []) ⇒ Object
Check for the presence of the given
library. -
#have_struct_member(struct_type, struct_member, headers = []) ⇒ Object
Checks whether or not the struct of type
struct_typecontains thestruct_member.
Class Method Details
.configuration ⇒ Object
58 59 60 |
# File 'lib/mkmf/lite.rb', line 58 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
62 63 64 65 66 |
# File 'lib/mkmf/lite.rb', line 62 def configure yield configuration reset_memoized_results configuration end |
.extended(object) ⇒ Object
68 69 70 |
# File 'lib/mkmf/lite.rb', line 68 def extended(object) configured_objects << object end |
Instance Method Details
#check_offsetof(struct_type, field, headers = [], *directories) ⇒ Object
Returns the offset of field within struct_type using headers,
or common headers, plus stddef.h, if no headers are specified.
If this method fails an error is raised. This could happen if the field can't be found and/or the header files do not include the indicated type. It will also fail if the field is a bit field.
Example:
class Foo
include Mkmf::Lite
utsname = check_offsetof('struct utsname', 'release', 'sys/utsname.h')
end
296 297 298 299 300 301 302 303 |
# File 'lib/mkmf/lite.rb', line 296 def check_offsetof(struct_type, field, headers = [], *directories) headers = get_header_string(headers) erb = ERB.new(read_template('check_offsetof.erb')) code = erb.result(binding) = (directories) try_to_execute(code, ) end |
#check_sizeof(type, headers = [], *directories) ⇒ Object
Returns the sizeof type using headers, or common headers if no
headers are specified.
If this method fails an error is raised. This could happen if the type can't be found and/or the header files do not include the indicated type.
Example:
class Foo
include Mkmf::Lite
utsname = check_sizeof('struct utsname', 'sys/utsname.h')
end
271 272 273 274 275 276 277 278 |
# File 'lib/mkmf/lite.rb', line 271 def check_sizeof(type, headers = [], *directories) headers = get_header_string(headers) erb = ERB.new(read_template('check_sizeof.erb')) code = erb.result(binding) = (directories) try_to_execute(code, ) end |
#check_valueof(constant, headers = [], *directories) ⇒ Object
Returns the value of the given constant (which could also be a macro)
using headers, or common headers if no headers are specified.
If this method fails an error is raised. This could happen if the constant can't be found and/or the header files do not include the indicated constant.
247 248 249 250 251 252 253 254 |
# File 'lib/mkmf/lite.rb', line 247 def check_valueof(constant, headers = [], *directories) headers = get_header_string(headers) erb = ERB.new(read_template('check_valueof.erb')) code = erb.result(binding) = (directories) try_to_execute(code, ) end |
#configuration ⇒ Object
158 159 160 |
# File 'lib/mkmf/lite.rb', line 158 def configuration Mkmf::Lite.configuration end |
#configure(&block) ⇒ Object
154 155 156 |
# File 'lib/mkmf/lite.rb', line 154 def configure(&block) Mkmf::Lite.configure(&block) end |
#have_func(function, headers = []) ⇒ Object
Check for the presence of the given function in the common header
files, or within any headers that you provide.
Returns true if found, or false if not found.
182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/mkmf/lite.rb', line 182 def have_func(function, headers = []) headers = get_header_string(headers) erb_ptr = ERB.new(read_template('have_func_pointer.erb')) erb_std = ERB.new(read_template('have_func.erb')) ptr_code = erb_ptr.result(binding) std_code = erb_std.result(binding) # Check for just the function pointer first. If that fails, then try # to compile with the function declaration. try_to_compile(ptr_code) || try_to_compile(std_code) end |
#have_header(header, *directories) ⇒ Object
Check for the presence of the given header file. You may optionally
provide a list of directories to search.
Returns true if found, or false if not found.
167 168 169 170 171 172 173 |
# File 'lib/mkmf/lite.rb', line 167 def have_header(header, *directories) erb = ERB.new(read_template('have_header.erb')) code = erb.result(binding) = (directories) try_to_compile(code, ) end |
#have_library(library, function = nil, headers = []) ⇒ Object
Check for the presence of the given library. You may optionally
provide a function name to check for within that library, as well
as any additional headers.
Returns true if the library can be linked, or false otherwise.
Note: The library name should not include the 'lib' prefix or file extension. For example, use 'xerces-c' not 'libxerces-c' or 'libxerces-c.dylib'. However, if the 'lib' prefix is provided, it will be automatically stripped.
208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/mkmf/lite.rb', line 208 def have_library(library, function = nil, headers = []) # Strip 'lib' prefix if present (e.g., 'libxerces-c' -> 'xerces-c') library = library.sub(/^lib/, '') unless windows_with_cl_compiler? headers = get_header_string(headers) erb = ERB.new(read_template('have_library.erb')) code = erb.result(binding) # Build link options with the library = windows_with_cl_compiler? ? "#{library}.lib" : "-l#{library}" try_to_compile(code, nil, ) end |
#have_struct_member(struct_type, struct_member, headers = []) ⇒ Object
Checks whether or not the struct of type struct_type contains the
struct_member. If it does not, or the struct type cannot be found,
then false is returned.
An optional list of headers may be specified, in addition to the
common header files that are already searched.
231 232 233 234 235 236 237 |
# File 'lib/mkmf/lite.rb', line 231 def have_struct_member(struct_type, struct_member, headers = []) headers = get_header_string(headers) erb = ERB.new(read_template('have_struct_member.erb')) code = erb.result(binding) try_to_compile(code) end |