ruby-changes:1826
From: ko1@a...
Date: 30 Aug 2007 13:13:26 +0900
Subject: [ruby-changes:1826] nobu - Ruby:r13317 (ruby_1_8, trunk): * lib/mkmf.rb (try_const, have_const): check for a const is defined.
nobu 2007-08-30 13:13:16 +0900 (Thu, 30 Aug 2007) New Revision: 13317 Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/lib/mkmf.rb trunk/ChangeLog trunk/lib/mkmf.rb Log: * lib/mkmf.rb (try_const, have_const): check for a const is defined. [ruby-core:04422] http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/lib/mkmf.rb?r1=13317&r2=13316 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=13317&r2=13316 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13317&r2=13316 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/mkmf.rb?r1=13317&r2=13316 Index: ChangeLog =================================================================== --- ChangeLog (revision 13316) +++ ChangeLog (revision 13317) @@ -1,3 +1,8 @@ +Thu Aug 30 13:13:13 2007 Nobuyoshi Nakada <nobu@r...> + + * 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@f...> * include/ruby/intern.h: declare rb_hash_tbl. Index: lib/mkmf.rb =================================================================== --- lib/mkmf.rb (revision 13316) +++ lib/mkmf.rb (revision 13317) @@ -826,6 +826,44 @@ 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+. # Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 13316) +++ ruby_1_8/ChangeLog (revision 13317) @@ -1,3 +1,8 @@ +Thu Aug 30 13:13:13 2007 Nobuyoshi Nakada <nobu@r...> + + * lib/mkmf.rb (try_const, have_const): check for a const is defined. + [ruby-core:04422] + Thu Aug 30 13:10:57 2007 Nobuyoshi Nakada <nobu@r...> * configure.in (group_member): check if presents. Index: ruby_1_8/lib/mkmf.rb =================================================================== --- ruby_1_8/lib/mkmf.rb (revision 13316) +++ ruby_1_8/lib/mkmf.rb (revision 13317) @@ -808,6 +808,44 @@ 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+. # -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml