summaryrefslogtreecommitdiff
path: root/lib/mkmf.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-08-30 04:13:16 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-08-30 04:13:16 +0000
commit9eb692cbe293abf43d7f3c8208d9922d2f6fd5f7 (patch)
treeefb36fcf0cfc4217198a4ee710c134635fbb4a82 /lib/mkmf.rb
parentac56065357732586bfe94aa1a35c23c2817c6aa3 (diff)
* lib/mkmf.rb (try_const, have_const): check for a const is defined.
[ruby-core:04422] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@13317 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/mkmf.rb')
-rw-r--r--lib/mkmf.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index ca320cd8de..c56717c1d6 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -808,6 +808,44 @@ def find_type(type, opt, *headers, &b)
end
end
+def try_const(const, headers = nil, opt = "", &b)
+ const, type = *const
+ if try_compile(<<"SRC", opt, &b)
+#{COMMON_HEADERS}
+#{cpp_include(headers)}
+/*top*/
+typedef #{type || 'int'} conftest_type;
+conftest_type conftestval = #{type ? '' : '(int)'}#{const};
+SRC
+ $defs.push(format("-DHAVE_CONST_%s", const.strip.upcase.tr_s("^A-Z0-9_", "_")))
+ true
+ else
+ false
+ end
+end
+
+# Returns whether or not the constant +const+ is defined. You may
+# optionally pass the +type+ of +const+ as <code>[const, type]</code>,
+# like as:
+#
+# have_const(%w[PTHREAD_MUTEX_INITIALIZER pthread_mutex_t], "pthread.h")
+#
+# You may also pass additional +headers+ to check against in addition
+# to the common header files, and additional flags to +opt+ which are
+# then passed along to the compiler.
+#
+# If found, a macro is passed as a preprocessor constant to the compiler using
+# the type name, in uppercase, prepended with 'HAVE_CONST_'.
+#
+# For example, if have_const('foo') returned true, then the HAVE_CONST_FOO
+# preprocessor macro would be passed to the compiler.
+#
+def have_const(const, headers = nil, opt = "", &b)
+ checking_for checking_message([*const].compact.join(' '), headers, opt) do
+ try_const(const, headers, opt, &b)
+ end
+end
+
# Returns the size of the given +type+. You may optionally specify additional
# +headers+ to search in for the +type+.
#