[RUBY] Exciting environment check with mkmf

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

Exciting environment check with mkmf
Build TensorFlow operation check environment with Docker
Pytorch execution environment with Docker
Check compliance with object-oriented exercise
Check CSV value with RSpec
Integer check method with ruby
Check performance quickly with irb
Prepare Python3 environment with CentOS7
[Docker] Rails 5.2 environment construction with docker
Build docker environment with WSL
React environment construction with Docker
[Java 8] Duplicate deletion (& duplicate check) with Stream
Rails + MySQL environment construction with Docker
Create a Vue3 environment with Docker!
Build Couchbase local environment with Docker
Build a Node.js environment with Docker
Build a Tomcat 8.5 environment with Pleiades 4.8
Create RUNTEQ's environment with Windows DockerDesktop
Build environment with vue.js + rails + docker
[Java] Element existence check with Stream
Build Rails environment with Docker Compose
Create SolrCloud verification environment with Docker
Create Laravel environment with Docker (docker-compose)
Build jooby development environment with Eclipse
Check date correlation with Spring Boot
[Environment construction with Docker] Rails 6 & MySQL 8
Check when moss with SimpleDateFormat parse
Check your internet connection with Alamofire
Build docker + laravel environment with laradock
Check MySQL logs in Docker environment