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.

Constant Summary collapse

MKMF_LITE_VERSION =

The version of the mkmf-lite library

'0.8.0'

Instance Method Summary collapse

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


220
221
222
223
224
225
226
227
# File 'lib/mkmf/lite.rb', line 220

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)
  options = build_directory_options(directories)

  try_to_execute(code, options)
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


195
196
197
198
199
200
201
202
# File 'lib/mkmf/lite.rb', line 195

def check_sizeof(type, headers = [], *directories)
  headers = get_header_string(headers)
  erb = ERB.new(read_template('check_sizeof.erb'))
  code = erb.result(binding)
  options = build_directory_options(directories)

  try_to_execute(code, options)
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.



171
172
173
174
175
176
177
178
# File 'lib/mkmf/lite.rb', line 171

def check_valueof(constant, headers = [], *directories)
  headers = get_header_string(headers)
  erb = ERB.new(read_template('check_valueof.erb'))
  code = erb.result(binding)
  options = build_directory_options(directories)

  try_to_execute(code, options)
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.



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/mkmf/lite.rb', line 106

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.



91
92
93
94
95
96
97
# File 'lib/mkmf/lite.rb', line 91

def have_header(header, *directories)
  erb = ERB.new(read_template('have_header.erb'))
  code = erb.result(binding)
  options = build_directory_options(directories)

  try_to_compile(code, options)
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.



132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/mkmf/lite.rb', line 132

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
  link_options = windows_with_cl_compiler? ? "#{library}.lib" : "-l#{library}"

  try_to_compile(code, nil, link_options)
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.



155
156
157
158
159
160
161
# File 'lib/mkmf/lite.rb', line 155

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