There is mkmf
in the standard attached library of Ruby.
This is originally a Ruby standard attached library for making Makefiles that make Ruby extension libraries, but since it is made wonderfully convenient and flexible by the hands of Ruby developers, it can also be used for easily checking the environment of the machine. It seems that it can be used.
"I want to check if the environment can take st_ctim.tv_nsec members with the structure struct stat." => have_struct_member("structstat","st_ctim.tv_nsec")
"I want to use if mecab can be used" => have_header('mecab.h')
"I can't help wondering if there is a library libc and printf can be used." => have_library("c","printf")
"I want to write out what I have checked so far as a header file" => create_header
This header file is written as #define HAVE_STRUCT_STAT_ST_CTIM 1
if it has a struct stat st_ctim.tv_nsec
member.
After that, if you #include
the header file and branch with #ifdef
etc., you can write code that can be used portablely in any environment. (Investigation required)
Even if you don't bother to write it in the header, $ defs will have ["-DHAVE_STRUCT_STAT_ST_CTIM ". Since the array is packed like]
, it is designed to be easy to use as a compile option.
Easy to use. Just say require'mkmf'
.
Since it is Ruby code, if statements can be used as you like, and some of the configures that are complicatedly packed in the corner of your home can be neatly organized in Ruby code.
If you have a voice such as "This is more versatile and highly functional", I would love to hear from you, but I think "standard attachment" is a considerable advantage. Ruby is great. (What if I was told "Don't use mkmf for that purpose!")
Recommended Posts