Module: Mkmf::Lite
- Defined in:
- lib/mkmf/lite.rb
Constant Summary collapse
- MKMF_LITE_VERSION =
The version of the mkmf-lite library
'0.2.3'
- @@cpp_command =
RbConfig::CONFIG['CC'] || RbConfig::CONFIG['CPP']
- @@cpp_srcfile =
'conftest.c'
- @@cpp_outfile =
'-o conftest.exe'
- @@cpp_libraries =
TODO: We should adjust this based on OS. For now we’re using arguments I think you’ll typically see set on Linux and BSD.
"-lrt -ldl -lcrypt -lm"
Instance Method Summary collapse
-
#check_sizeof(type, headers = []) ⇒ Object
Returns the sizeof
type
usingheaders
, or common headers if no headers are specified. -
#have_func(function, headers = []) ⇒ Object
Check for the presence of the given
function
in the common header files, or within anyheaders
that you provide. -
#have_header(header) ⇒ Object
Check for the presence of the given
header
file. -
#have_struct_member(struct_type, struct_member, headers = []) ⇒ Object
Checks whether or not the struct of type
struct_type
contains thestruct_member
.
Instance Method Details
#check_sizeof(type, headers = []) ⇒ 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
103 104 105 106 107 108 109 |
# File 'lib/mkmf/lite.rb', line 103 def check_sizeof(type, headers = []) headers = get_header_string(headers) erb = ERB.new(read_template('check_sizeof.erb')) code = erb.result(binding) try_to_execute(code) 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.
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/mkmf/lite.rb', line 61 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) ⇒ Object
Check for the presence of the given header
file.
Returns true if found, or false if not found.
50 51 52 53 54 |
# File 'lib/mkmf/lite.rb', line 50 def have_header(header) erb = ERB.new(read_template('have_header.erb')) code = erb.result(binding) try_to_compile(code) 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.
82 83 84 85 86 87 88 |
# File 'lib/mkmf/lite.rb', line 82 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 |