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, Diagnostic

Constant Summary collapse

MKMF_LITE_VERSION =

The version of the mkmf-lite library

'0.9.1'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configurationObject



72
73
74
# File 'lib/mkmf/lite.rb', line 72

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



76
77
78
79
80
# File 'lib/mkmf/lite.rb', line 76

def configure
  yield configuration
  reset_memoized_results
  configuration
end

.extended(object) ⇒ Object



82
83
84
# File 'lib/mkmf/lite.rb', line 82

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


315
316
317
318
319
320
321
322
# File 'lib/mkmf/lite.rb', line 315

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


290
291
292
293
294
295
296
297
# File 'lib/mkmf/lite.rb', line 290

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.



266
267
268
269
270
271
272
273
# File 'lib/mkmf/lite.rb', line 266

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

#configurationObject



172
173
174
# File 'lib/mkmf/lite.rb', line 172

def configuration
  Mkmf::Lite.configuration
end

#configure(&block) ⇒ Object



168
169
170
# File 'lib/mkmf/lite.rb', line 168

def configure(&block)
  Mkmf::Lite.configure(&block)
end

#diagnosticsObject



176
177
178
# File 'lib/mkmf/lite.rb', line 176

def diagnostics
  @diagnostics
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.



200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/mkmf/lite.rb', line 200

def have_func(function, headers = [])
  headers_provided = !Array(headers).flatten.empty?
  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 a header declaration first. If no headers were provided,
  # fall back to an explicit declaration so symbol-only probes still work.
  try_to_compile(ptr_code) || (!headers_provided && 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.



185
186
187
188
189
190
191
# File 'lib/mkmf/lite.rb', line 185

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.



227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/mkmf/lite.rb', line 227

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.



250
251
252
253
254
255
256
# File 'lib/mkmf/lite.rb', line 250

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