-
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
The mkmf-lite gem is a lightweight version of the mkmf library that ships as part of the Ruby standard library. Unlike the mkmf library, this library is meant to be used as a module. It is NOT meant as a build tool, nor is it a replacement for mkmf.
The mkmf-lite module currently includes the following methods:
- check_sizeof
- check_valueof
- have_func
- have_func_pointer
- have_header
- have_struct_member
require 'mkmf/lite'
class System
extend Mkmf::Lite
HAVE_PW_NAME = have_struct_member('struct passwd', 'pw_name', 'pwd.h')
def some_method
if HAVE_PW_NAME
# Do something
end
if have_func('printf', 'stdio.h') # or just have_func('printf')
# Do something else
end
if have_header('stdio.h')
# Other things
end
size = check_sizeof('div_t', 'stdlib.h') # or just check_sizeof('div_t')
eof = check_valueof('EOF', 'stdio.h') # or just check_valueof('EOF')
end
end
The results of each call are memoized for speed via the Memoist library, since the odds of a result changing between calls is basically zero. You can always force the issue via the Memoist API.
You may see a difference between the results of the methods provided here and the ones from Ruby's mkmf library. How is that possible?
The difference is in the header files that are automatically included when a check is made. Ruby's mkmf library will always use "ruby.h"
as an included header file. That header, in turn, includes several other header files whereas this library only uses common header files, or just <stdio.h>
and <stdlib.h>
by default. This can lead to different results.