summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-07 10:56:13 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-07 10:56:13 +0000
commit17099f82c7276b2c643608560500d2273c9018cf (patch)
tree2995555428a8dddd08aa203402cdeb8596fa8f71 /lib
parent4017488e6d48e0df584171512cdd95015fad176e (diff)
* lib/mkmf.rb: rdoc added. [ruby-Patches-9762]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@15725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/mkmf.rb127
1 files changed, 123 insertions, 4 deletions
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index 7422a11a50..ea4d680753 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -63,6 +63,8 @@ $beos = /beos/ =~ RUBY_PLATFORM
$solaris = /solaris/ =~ RUBY_PLATFORM
$dest_prefix_pattern = (File::PATH_SEPARATOR == ';' ? /\A([[:alpha:]]:)?/ : /\A/)
+# :stopdoc:
+
def config_string(key, config = CONFIG)
s = config[key] and !s.empty? and block_given? ? yield(s) : s
end
@@ -132,14 +134,18 @@ CPPOUTFILE = CONFIG['CPPOUTFILE']
CONFTEST_C = "conftest.c"
class String
+ # Wraps a string in escaped quotes if it contains whitespace.
def quote
- /\s/ =~ self ? "\"#{self}\"" : self
+ /\s/ =~ self ? "\"#{self}\"" : "#{self}"
end
+
+ # Generates a string used as cpp macro name.
def tr_cpp
strip.upcase.tr_s("^A-Z0-9_", "_")
end
end
class Array
+ # Wraps all strings in escaped quotes if they contain whitespace.
def quote
map {|s| s.quote}
end
@@ -149,6 +155,8 @@ def rm_f(*files)
FileUtils.rm_f(Dir[files.join("\0")])
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)
(t = File.mtime(target)) rescue return nil
Array === times or times = [times]
@@ -171,6 +179,12 @@ def merge_libs(*libs)
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
@log = nil
@logfile = 'mkmf.log'
@@ -485,6 +499,7 @@ ensure
log_src(src)
end
+# This is used internally by the have_macro? method.
def macro_defined?(macro, src, opt = "", &b)
src = src.sub(/[^\n]\z/, "\\&\n")
try_compile(src + <<"SRC", opt, &b)
@@ -552,7 +567,7 @@ def install_rb(mfile, dest, srcdir = nil)
install_files(mfile, [["lib/**/*.rb", dest, "lib"]], nil, srcdir)
end
-def append_library(libs, lib)
+def append_library(libs, lib) # :no-doc:
format(LIBARG, lib) + " " + libs
end
@@ -563,6 +578,11 @@ def message(*s)
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)
f = caller[0][/in `(.*)'$/, 1] and f << ": " #` for vim
m = "checking #{/\Acheck/ =~ f ? '' : 'for '}#{m}... "
@@ -592,6 +612,8 @@ def checking_message(target, place = nil, opt = nil)
end
end
+# :startdoc:
+
# Returns whether or not +macro+ is defined either in the common header
# files or within any +headers+ you provide.
#
@@ -611,7 +633,7 @@ end
# If +headers+ are provided, it will include those header files as the
# 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.
#
def have_library(lib, func = nil, headers = nil, &b)
@@ -752,7 +774,7 @@ end
# If found, a macro is passed as a preprocessor constant to the compiler using
# the member name, in uppercase, prepended with 'HAVE_ST_'.
#
-# For example, if have_struct_member('foo', 'bar') returned true, then the
+# For example, if have_struct_member('struct foo', 'bar') returned true, then the
# HAVE_ST_BAR preprocessor macro would be passed to the compiler.
#
def have_struct_member(type, member, headers = nil, &b)
@@ -888,6 +910,10 @@ def check_sizeof(type, headers = nil, &b)
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)
try_compile(<<"SRC", &b) # pointer
#{COMMON_HEADERS}
@@ -899,6 +925,8 @@ int t() {return (int)(1-*(conftestval#{member ? ".#{member}" : ""}));}
SRC
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)
try_compile(<<"SRC", &b) # pointer
#{COMMON_HEADERS}
@@ -942,6 +970,10 @@ def what_type?(type, member = nil, headers = nil, &b)
end
end
+# This method is used internally by the find_executable method.
+#
+# Internal use only.
+#
def find_executable0(bin, path = nil)
ext = config_string('EXEEXT')
if File.expand_path(bin) == bin
@@ -962,18 +994,45 @@ def find_executable0(bin, path = nil)
nil
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)
checking_for checking_message(bin, path) do
find_executable0(bin, path)
end
end
+# :stopdoc:
+
def arg_config(config, *defaults, &block)
$arg_config << [config, *defaults]
defaults << nil if !block and defaults.empty?
$configure_args.fetch(config.tr('_', '-'), *defaults, &block)
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, *defaults)
config = config.sub(/^--with[-_]/, '')
val = arg_config("--with-"+config) do
@@ -995,6 +1054,18 @@ def with_config(config, *defaults)
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, *defaults)
if arg_config("--enable-"+config)
true
@@ -1007,6 +1078,32 @@ def enable_config(config, *defaults)
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")
message "creating %s\n", header
sym = header.tr("a-z./\055", "A-Z___")
@@ -1074,6 +1171,10 @@ def dir_config(target, idefault=nil, ldefault=nil)
[idir, ldir]
end
+# :stopdoc:
+
+# Handles meta information about installed libraries. Uses your platform's
+# pkg-config program if it has one.
def pkg_config(pkg)
if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig)
# iff package specific config command is given
@@ -1111,6 +1212,10 @@ def with_destdir(dir)
/\A\$[\(\{]/ =~ dir ? dir : "$(DESTDIR)"+dir
end
+# Converts forward slashes to backslashes. Aimed at MS Windows.
+#
+# Internal use only.
+#
def winsep(s)
s.tr('/', '\\')
end
@@ -1224,6 +1329,7 @@ all install static install-so install-rb: Makefile
RULES
end
+# :startdoc:
# Generates the Makefile for your extension, passing along any options and
# preprocessor constants that you may have generated through other methods.
@@ -1273,6 +1379,10 @@ end
# instead of copying files around manually, because some third party
# 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)
$target = target
libpath = $DEFLIBPATH|$LIBPATH
@@ -1542,6 +1652,8 @@ ensure
mfile.close if mfile
end
+# :stopdoc:
+
def init_mkmf(config = CONFIG)
$makefile_created = false
$arg_config = []
@@ -1594,6 +1706,11 @@ details. You may need configuration options.
Provided configuration options:
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)
unless $makefile_created or File.exist?("Makefile")
opts = $arg_config.collect {|t, n| "\t#{t}#{n ? "=#{n}" : ""}\n"}
@@ -1601,6 +1718,8 @@ def mkmf_failed(path)
end
end
+# :startdoc:
+
init_mkmf
$make = with_config("make-prog", ENV["MAKE"] || "make")