I'm writing a C extension for Ruby, and I have something like this in the extconf.rb file:
if(not have_library('z'))
$stderr << "Error, could not locate zlib.\n"
abort "Missing zlib"
end
So the installation process aborts if zlib is missing. Instead, since my extension can work with AND without zlib, I would like to do something like the following;
if(have_library('z'))
# do something so that -DHAVE_ZLIB is passed to the compiler
# when compiling the extension.
end
How can I do that?
EDIT: The question is on the comment in the if...end statement: how to add the -DHAVE_ZLIB definition for the compiler?
If you can rely on checking for a header file then
have_headerwill define aHAVE_HEADER_Hmacro for you. For example:will define
HAVE_ZLIB_H, which you can then refer to in your code.If this isn’t enough or you need to define a macro for some other reason you can use the
$defsglobal: