* 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/trunk@13317 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b58f080349
commit
10084a3e61
@ -1,3 +1,8 @@
|
|||||||
|
Thu Aug 30 13:13:13 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/mkmf.rb (try_const, have_const): check for a const is defined.
|
||||||
|
[ruby-core:04422]
|
||||||
|
|
||||||
Thu Aug 30 08:00:12 2007 Tanaka Akira <akr@fsij.org>
|
Thu Aug 30 08:00:12 2007 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* include/ruby/intern.h: declare rb_hash_tbl.
|
* include/ruby/intern.h: declare rb_hash_tbl.
|
||||||
|
38
lib/mkmf.rb
38
lib/mkmf.rb
@ -826,6 +826,44 @@ def find_type(type, opt, *headers, &b)
|
|||||||
end
|
end
|
||||||
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
|
# Returns the size of the given +type+. You may optionally specify additional
|
||||||
# +headers+ to search in for the +type+.
|
# +headers+ to search in for the +type+.
|
||||||
#
|
#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user