1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/mkmf.rb: rdoc added. [ruby-Patches-9762]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2008-03-07 10:56:13 +00:00
parent 643d2bad07
commit 983aea463f
2 changed files with 125 additions and 2 deletions

View file

@ -1,3 +1,7 @@
Fri Mar 7 19:56:10 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb: rdoc added. [ruby-Patches-9762]
Thu Mar 6 17:26:53 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> Thu Mar 6 17:26:53 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* sprintf.c (rb_str_format): space flag is in effect for Inf/NaN too. * sprintf.c (rb_str_format): space flag is in effect for Inf/NaN too.

View file

@ -66,6 +66,8 @@ $beos = /beos/ =~ RUBY_PLATFORM
$solaris = /solaris/ =~ RUBY_PLATFORM $solaris = /solaris/ =~ RUBY_PLATFORM
$dest_prefix_pattern = (File::PATH_SEPARATOR == ';' ? /\A([[:alpha:]]:)?/ : /\A/) $dest_prefix_pattern = (File::PATH_SEPARATOR == ';' ? /\A([[:alpha:]]:)?/ : /\A/)
# :stopdoc:
def config_string(key, config = CONFIG) def config_string(key, config = CONFIG)
s = config[key] and !s.empty? and block_given? ? yield(s) : s s = config[key] and !s.empty? and block_given? ? yield(s) : s
end end
@ -171,14 +173,18 @@ CPPOUTFILE = CONFIG['CPPOUTFILE']
CONFTEST_C = "conftest.c".freeze CONFTEST_C = "conftest.c".freeze
class String class String
# Wraps a string in escaped quotes if it contains whitespace.
def quote def quote
/\s/ =~ self ? "\"#{self}\"" : "#{self}" /\s/ =~ self ? "\"#{self}\"" : "#{self}"
end end
# Generates a string used as cpp macro name.
def tr_cpp def tr_cpp
strip.upcase.tr_s("^A-Z0-9_", "_") strip.upcase.tr_s("^A-Z0-9_", "_")
end end
end end
class Array class Array
# Wraps all strings in escaped quotes if they contain whitespace.
def quote def quote
map {|s| s.quote} map {|s| s.quote}
end end
@ -188,6 +194,8 @@ def rm_f(*files)
FileUtils.rm_f(Dir[*files]) FileUtils.rm_f(Dir[*files])
end end
# Returns time stamp of the +target+ file if it exists and is newer
# than or equal to all of +times+.
def modified?(target, times) def modified?(target, times)
(t = File.mtime(target)) rescue return nil (t = File.mtime(target)) rescue return nil
Array === times or times = [times] Array === times or times = [times]
@ -210,6 +218,12 @@ def merge_libs(*libs)
end end
end end
# This is a custom logging module. It generates an mkmf.log file when you
# run your extconf.rb script. This can be useful for debugging unexpected
# failures.
#
# This module and its associated methods are meant for internal use only.
#
module Logging module Logging
@log = nil @log = nil
@logfile = 'mkmf.log' @logfile = 'mkmf.log'
@ -538,6 +552,7 @@ ensure
log_src(src) log_src(src)
end end
# This is used internally by the have_macro? method.
def macro_defined?(macro, src, opt = "", &b) def macro_defined?(macro, src, opt = "", &b)
src = src.sub(/[^\n]\z/, "\\&\n") src = src.sub(/[^\n]\z/, "\\&\n")
try_compile(src + <<"SRC", opt, &b) try_compile(src + <<"SRC", opt, &b)
@ -606,7 +621,7 @@ def install_rb(mfile, dest, srcdir = nil)
install_files(mfile, [["lib/**/*.rb", dest, "lib"]], nil, srcdir) install_files(mfile, [["lib/**/*.rb", dest, "lib"]], nil, srcdir)
end end
def append_library(libs, lib) def append_library(libs, lib) # :no-doc:
format(LIBARG, lib) + " " + libs format(LIBARG, lib) + " " + libs
end end
@ -617,6 +632,11 @@ def message(*s)
end end
end end
# This emits a string to stdout that allows users to see the results of the
# various have* and find* methods as they are tested.
#
# Internal use only.
#
def checking_for(m, fmt = nil) def checking_for(m, fmt = nil)
f = caller[0][/in `(.*)'$/, 1] and f << ": " #` for vim #' f = caller[0][/in `(.*)'$/, 1] and f << ": " #` for vim #'
m = "checking #{/\Acheck/ =~ f ? '' : 'for '}#{m}... " m = "checking #{/\Acheck/ =~ f ? '' : 'for '}#{m}... "
@ -646,6 +666,8 @@ def checking_message(target, place = nil, opt = nil)
end end
end end
# :startdoc:
# Returns whether or not +macro+ is defined either in the common header # Returns whether or not +macro+ is defined either in the common header
# files or within any +headers+ you provide. # files or within any +headers+ you provide.
# #
@ -665,7 +687,7 @@ end
# If +headers+ are provided, it will include those header files as the # If +headers+ are provided, it will include those header files as the
# header files it looks in when searching for +func+. # header files it looks in when searching for +func+.
# #
# Real name of the library to be linked can be altered by # The real name of the library to be linked can be altered by
# '--with-FOOlib' configuration option. # '--with-FOOlib' configuration option.
# #
def have_library(lib, func = nil, headers = nil, &b) def have_library(lib, func = nil, headers = nil, &b)
@ -945,6 +967,10 @@ def check_sizeof(type, headers = nil, &b)
end end
end end
# :stopdoc:
# Used internally by the what_type? method to determine if +type+ is a scalar
# pointer.
def scalar_ptr_type?(type, member = nil, headers = nil, &b) def scalar_ptr_type?(type, member = nil, headers = nil, &b)
try_compile(<<"SRC", &b) # pointer try_compile(<<"SRC", &b) # pointer
#{COMMON_HEADERS} #{COMMON_HEADERS}
@ -956,6 +982,8 @@ int t() {return (int)(1-*(conftestval#{member ? ".#{member}" : ""}));}
SRC SRC
end end
# Used internally by the what_type? method to determine if +type+ is a scalar
# pointer.
def scalar_type?(type, member = nil, headers = nil, &b) def scalar_type?(type, member = nil, headers = nil, &b)
try_compile(<<"SRC", &b) # pointer try_compile(<<"SRC", &b) # pointer
#{COMMON_HEADERS} #{COMMON_HEADERS}
@ -999,6 +1027,10 @@ def what_type?(type, member = nil, headers = nil, &b)
end end
end end
# This method is used internally by the find_executable method.
#
# Internal use only.
#
def find_executable0(bin, path = nil) def find_executable0(bin, path = nil)
ext = config_string('EXEEXT') ext = config_string('EXEEXT')
if File.expand_path(bin) == bin if File.expand_path(bin) == bin
@ -1019,12 +1051,25 @@ def find_executable0(bin, path = nil)
nil nil
end end
# :startdoc:
# Searches for the executable +bin+ on +path+. The default path is your
# PATH environment variable. If that isn't defined, it will resort to
# searching /usr/local/bin, /usr/ucb, /usr/bin and /bin.
#
# If found, it will return the full path, including the executable name,
# of where it was found.
#
# Note that this method does not actually affect the generated Makefile.
#
def find_executable(bin, path = nil) def find_executable(bin, path = nil)
checking_for checking_message(bin, path) do checking_for checking_message(bin, path) do
find_executable0(bin, path) find_executable0(bin, path)
end end
end end
# :stopdoc:
def arg_config(config, default=nil, &block) def arg_config(config, default=nil, &block)
$arg_config << [config, default] $arg_config << [config, default]
defaults = [] defaults = []
@ -1036,6 +1081,20 @@ def arg_config(config, default=nil, &block)
$configure_args.fetch(config.tr('_', '-'), *defaults, &block) $configure_args.fetch(config.tr('_', '-'), *defaults, &block)
end end
# :startdoc:
# Tests for the presence of a --with-<tt>config</tt> or --without-<tt>config</tt>
# option. Returns true if the with option is given, false if the without
# option is given, and the default value otherwise.
#
# This can be useful for adding custom definitions, such as debug information.
#
# Example:
#
# if with_config("debug")
# $defs.push("-DOSSL_DEBUG") unless $defs.include? "-DOSSL_DEBUG"
# end
#
def with_config(config, default=nil) def with_config(config, default=nil)
config = config.sub(/^--with[-_]/, '') config = config.sub(/^--with[-_]/, '')
val = arg_config("--with-"+config) do val = arg_config("--with-"+config) do
@ -1057,6 +1116,18 @@ def with_config(config, default=nil)
end end
end end
# Tests for the presence of an --enable-<tt>config</tt> or
# --disable-<tt>config</tt> option. Returns true if the enable option is given,
# false if the disable option is given, and the default value otherwise.
#
# This can be useful for adding custom definitions, such as debug information.
#
# Example:
#
# if enable_config("debug")
# $defs.push("-DOSSL_DEBUG") unless $defs.include? "-DOSSL_DEBUG"
# end
#
def enable_config(config, default=nil) def enable_config(config, default=nil)
if arg_config("--enable-"+config) if arg_config("--enable-"+config)
true true
@ -1069,6 +1140,32 @@ def enable_config(config, default=nil)
end end
end end
# Generates a header file consisting of the various macro definitions generated
# by other methods such as have_func and have_header. These are then wrapped in
# a custom #ifndef based on the +header+ file name, which defaults to
# 'extconf.h'.
#
# For example:
#
# # extconf.rb
# require 'mkmf'
# have_func('realpath')
# have_header('sys/utime.h')
# create_header
# create_makefile('foo')
#
# The above script would generate the following extconf.h file:
#
# #ifndef EXTCONF_H
# #define EXTCONF_H
# #define HAVE_REALPATH 1
# #define HAVE_SYS_UTIME_H 1
# #endif
#
# Given that the create_header method generates a file based on definitions
# set earlier in your extconf.rb file, you will probably want to make this
# one of the last methods you call in your script.
#
def create_header(header = "extconf.h") def create_header(header = "extconf.h")
message "creating %s\n", header message "creating %s\n", header
sym = header.tr("a-z./\055", "A-Z___") sym = header.tr("a-z./\055", "A-Z___")
@ -1136,6 +1233,10 @@ def dir_config(target, idefault=nil, ldefault=nil)
[idir, ldir] [idir, ldir]
end end
# :stopdoc:
# Handles meta information about installed libraries. Uses your platform's
# pkg-config program if it has one.
def pkg_config(pkg) def pkg_config(pkg)
if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig) if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig)
# iff package specific config command is given # iff package specific config command is given
@ -1173,6 +1274,10 @@ def with_destdir(dir)
/\A\$[\(\{]/ =~ dir ? dir : "$(DESTDIR)"+dir /\A\$[\(\{]/ =~ dir ? dir : "$(DESTDIR)"+dir
end end
# Converts forward slashes to backslashes. Aimed at MS Windows.
#
# Internal use only.
#
def winsep(s) def winsep(s)
s.tr('/', '\\') s.tr('/', '\\')
end end
@ -1283,6 +1388,7 @@ preload = #{defined?($preload) && $preload ? $preload.join(' ') : ''}
end end
mk mk
end end
# :startdoc:
def dummy_makefile(srcdir) def dummy_makefile(srcdir)
configuration(srcdir) << <<RULES << CLEANINGS configuration(srcdir) << <<RULES << CLEANINGS
@ -1398,6 +1504,10 @@ end
# instead of copying files around manually, because some third party # instead of copying files around manually, because some third party
# libraries may depend on the +target_prefix+ being set properly. # libraries may depend on the +target_prefix+ being set properly.
# #
# The +srcprefix+ argument can be used to override the default source
# directory, i.e. the current directory . It is included as part of the VPATH
# and added to the list of INCFLAGS.
#
def create_makefile(target, srcprefix = nil) def create_makefile(target, srcprefix = nil)
$target = target $target = target
libpath = $DEFLIBPATH|$LIBPATH libpath = $DEFLIBPATH|$LIBPATH
@ -1629,6 +1739,8 @@ ensure
mfile.close if mfile mfile.close if mfile
end end
# :stopdoc:
def init_mkmf(config = CONFIG) def init_mkmf(config = CONFIG)
$makefile_created = false $makefile_created = false
$arg_config = [] $arg_config = []
@ -1682,6 +1794,11 @@ details. You may need configuration options.
Provided configuration options: Provided configuration options:
MESSAGE MESSAGE
# Returns whether or not the Makefile was successfully generated. If not,
# the script will abort with an error message.
#
# Internal use only.
#
def mkmf_failed(path) def mkmf_failed(path)
unless $makefile_created or File.exist?("Makefile") unless $makefile_created or File.exist?("Makefile")
opts = $arg_config.collect {|t, n| "\t#{t}#{n ? "=#{n}" : ""}\n"} opts = $arg_config.collect {|t, n| "\t#{t}#{n ? "=#{n}" : ""}\n"}
@ -1689,6 +1806,8 @@ def mkmf_failed(path)
end end
end end
# :startdoc:
init_mkmf init_mkmf
$make = with_config("make-prog", ENV["MAKE"] || "make") $make = with_config("make-prog", ENV["MAKE"] || "make")