diff options
Diffstat (limited to 'lib/mkmf.rb')
| -rw-r--r-- | lib/mkmf.rb | 688 |
1 files changed, 467 insertions, 221 deletions
diff --git a/lib/mkmf.rb b/lib/mkmf.rb index eabccd48eb..37ee4a70d9 100644 --- a/lib/mkmf.rb +++ b/lib/mkmf.rb @@ -7,9 +7,7 @@ require 'rbconfig' require 'fileutils' require 'shellwords' -class String - # :stopdoc: - +class String # :nodoc: # Wraps a string in escaped quotes if it contains whitespace. def quote /\s/ =~ self ? "\"#{self}\"" : "#{self}" @@ -32,26 +30,37 @@ class String def sans_arguments self[/\A[^()]+/] end - - # :startdoc: end -class Array - # :stopdoc: - +class Array # :nodoc: # Wraps all strings in escaped quotes if they contain whitespace. def quote map {|s| s.quote} end - - # :startdoc: end ## -# mkmf.rb is used by Ruby C extensions to generate a Makefile which will +# \Module \MakeMakefile is used by Ruby C extensions to generate a Makefile which will # correctly compile and link the C extension to Ruby and a third-party # library. module MakeMakefile + + target_rbconfig = nil + ARGV.delete_if do |arg| + opt = arg.delete_prefix("--target-rbconfig=") + unless opt == arg + target_rbconfig = opt + end + end + if target_rbconfig + # Load the RbConfig for the target platform into this module. + # Cross-compiling needs the same version of Ruby. + Kernel.load target_rbconfig, self + else + # The RbConfig for the target platform where the built extension runs. + RbConfig = ::RbConfig + end + #### defer until this module become global-state free. # def self.extended(obj) # obj.init_mkmf @@ -67,6 +76,9 @@ module MakeMakefile # The makefile configuration using the defaults from when Ruby was built. CONFIG = RbConfig::MAKEFILE_CONFIG + + ## + # The saved original value of +LIB+ environment variable ORIG_LIBPATH = ENV['LIB'] ## @@ -75,7 +87,7 @@ module MakeMakefile C_EXT = %w[c m] ## - # Extensions for files complied with a C++ compiler + # Extensions for files compiled with a C++ compiler CXX_EXT = %w[cc mm cxx cpp] unless File.exist?(File.join(*File.split(__FILE__).tap {|d, b| b.swapcase})) @@ -97,26 +109,16 @@ module MakeMakefile unless defined? $configure_args $configure_args = {} - args = CONFIG["configure_args"] - if ENV["CONFIGURE_ARGS"] - args << " " << ENV["CONFIGURE_ARGS"] + args = CONFIG["configure_args"].shellsplit + if arg = ENV["CONFIGURE_ARGS"] + args.push(*arg.shellsplit) end - for arg in Shellwords::shellwords(args) + args.delete_if {|a| /\A--(?:top(?:src)?|src|cur)dir(?=\z|=)/ =~ a} + for arg in args.concat(ARGV) arg, val = arg.split('=', 2) next unless arg arg.tr!('_', '-') - if arg.sub!(/^(?!--)/, '--') - val or next - arg.downcase! - end - next if /^--(?:top|topsrc|src|cur)dir$/ =~ arg - $configure_args[arg] = val || true - end - for arg in ARGV - arg, val = arg.split('=', 2) - next unless arg - arg.tr!('_', '-') - if arg.sub!(/^(?!--)/, '--') + if arg.sub!(/\A(?!--)/, '--') val or next arg.downcase! end @@ -207,8 +209,8 @@ module MakeMakefile ['RUBYCOMMONDIR', '$(vendordir)$(target_prefix)'], ['RUBYLIBDIR', '$(vendorlibdir)$(target_prefix)'], ['RUBYARCHDIR', '$(vendorarchdir)$(target_prefix)'], - ['HDRDIR', '$(rubyhdrdir)/ruby$(target_prefix)'], - ['ARCHHDRDIR', '$(rubyhdrdir)/$(arch)/ruby$(target_prefix)'], + ['HDRDIR', '$(vendorhdrdir)$(target_prefix)'], + ['ARCHHDRDIR', '$(vendorarchhdrdir)$(target_prefix)'], ] else dirs = [ @@ -216,8 +218,8 @@ module MakeMakefile ['RUBYCOMMONDIR', '$(sitedir)$(target_prefix)'], ['RUBYLIBDIR', '$(sitelibdir)$(target_prefix)'], ['RUBYARCHDIR', '$(sitearchdir)$(target_prefix)'], - ['HDRDIR', '$(rubyhdrdir)/ruby$(target_prefix)'], - ['ARCHHDRDIR', '$(rubyhdrdir)/$(arch)/ruby$(target_prefix)'], + ['HDRDIR', '$(sitehdrdir)$(target_prefix)'], + ['ARCHHDRDIR', '$(sitearchhdrdir)$(target_prefix)'], ] end dirs << ['target_prefix', (target_prefix ? "/#{target_prefix}" : "")] @@ -263,12 +265,16 @@ MESSAGE CSRCFLAG = CONFIG['CSRCFLAG'] CPPOUTFILE = config_string('CPPOUTFILE') {|str| str.sub(/\bconftest\b/, CONFTEST)} + # :startdoc: + + # Removes _files_. def rm_f(*files) opt = (Hash === files.last ? [files.pop] : []) FileUtils.rm_f(Dir[*files.flatten], *opt) end module_function :rm_f + # Removes _files_ recursively. def rm_rf(*files) opt = (Hash === files.last ? [files.pop] : []) FileUtils.rm_rf(Dir[*files.flatten], *opt) @@ -283,8 +289,11 @@ MESSAGE t if times.all? {|n| n <= t} end + # :stopdoc: + def split_libs(*strs) - strs.map {|s| s.split(/\s+(?=-|\z)/)}.flatten + sep = $mswin ? /\s+/ : /\s+(?=-|\z)/ + strs.flat_map {|s| s.lstrip.split(sep)} end def merge_libs(*libs) @@ -385,41 +394,82 @@ MESSAGE end end - def xsystem command, opts = nil + def expand_command(commands, envs = libpath_env) varpat = /\$\((\w+)\)|\$\{(\w+)\}/ - if varpat =~ command - vars = Hash.new {|h, k| h[k] = ENV[k]} - command = command.dup - nil while command.gsub!(varpat) {vars[$1||$2]} + vars = nil + expand = proc do |command| + case command + when Array + command.map(&expand) + when String + if varpat =~ command + vars ||= Hash.new {|h, k| h[k] = ENV[k]} + command = command.dup + nil while command.gsub!(varpat) {vars[$1||$2]} + end + command + else + command + end + end + if Array === commands + env, *commands = commands if Hash === commands.first + envs.merge!(env) if env end + + # disable ASAN leak reporting - conftest programs almost always don't bother + # to free their memory. + envs['LSAN_OPTIONS'] = "detect_leaks=0" unless ENV.key?('LSAN_OPTIONS') + + return envs, expand[commands] + end + + def env_quote(envs) + envs.map {|e, v| "#{e}=#{v.quote}"} + end + + # :startdoc: + + # call-seq: + # xsystem(command, werror: false) -> true or false + # + # Executes _command_ with expanding variables, and returns the exit + # status like as Kernel#system. If _werror_ is true and the error + # output is not empty, returns +false+. The output will logged. + def xsystem(command, werror: false) + env, command = expand_command(command) Logging::open do - puts command.quote - if opts and opts[:werror] + puts [env_quote(env), command.quote].join(' ') + if werror result = nil Logging.postpone do |log| - output = IO.popen(libpath_env, command, &:read) + output = IO.popen(env, command, &:read) result = ($?.success? and File.zero?(log.path)) output end result else - system(libpath_env, command) + system(env, *command) end end end + # Executes _command_ similarly to xsystem, but yields opened pipe. def xpopen command, *mode, &block + env, commands = expand_command(command) + command = [env_quote(env), command].join(' ') Logging::open do case mode[0] - when nil, /^r/ + when nil, Hash, /^r/ puts "#{command} |" else puts "| #{command}" end - IO.popen(libpath_env, command, *mode, &block) + IO.popen(env, commands, *mode, &block) end end + # Logs _src_ def log_src(src, heading="checked program was") src = src.split(/^/) fmt = "%#{src.size.to_s.size}d: %s" @@ -434,10 +484,15 @@ EOM EOM end + # Returns the language-dependent source file name for configuration + # checks. def conftest_source CONFTEST_C end + # Creats temporary source file from +COMMON_HEADERS+ and _src_. + # Yields the created source string and uses the returned string as + # the source code, if the block is given. def create_tmpsrc(src) src = "#{COMMON_HEADERS}\n#{src}" src = yield(src) if block_given? @@ -446,7 +501,7 @@ EOM src.sub!(/[^\n]\z/, "\\&\n") count = 0 begin - open(conftest_source, "wb") do |cfile| + File.open(conftest_source, "wb") do |cfile| cfile.print src end rescue Errno::EACCES @@ -458,6 +513,8 @@ EOM src end + # :stopdoc: + def have_devel? unless defined? $have_devel $have_devel = true @@ -466,7 +523,7 @@ EOM $have_devel end - def try_do(src, command, *opts, &b) + def try_do(src, command, **opts, &b) unless have_devel? raise <<MSG The compiler failed to generate an executable file. @@ -475,7 +532,7 @@ MSG end begin src = create_tmpsrc(src, &b) - xsystem(command, *opts) + xsystem(command, **opts) ensure log_src(src) end @@ -516,52 +573,57 @@ MSG conf) end - def cpp_command(outfile, opt="") + def cpp_config(opt) conf = cc_config(opt) if $universal and (arch_flag = conf['ARCH_FLAG']) and !arch_flag.empty? conf['ARCH_FLAG'] = arch_flag.gsub(/(?:\G|\s)-arch\s+\S+/, '') end + conf + end + + def cpp_command(outfile, opt="") + conf = cpp_config(opt) RbConfig::expand("$(CPP) #$INCFLAGS #$CPPFLAGS #$CFLAGS #{opt} #{CONFTEST_C} #{outfile}", conf) end def libpathflag(libpath=$DEFLIBPATH|$LIBPATH) + libpathflags = nil libpath.map{|x| case x when "$(topdir)", /\A\./ LIBPATHFLAG else - LIBPATHFLAG+RPATHFLAG + libpathflags ||= [LIBPATHFLAG, RPATHFLAG].grep(/\S/).join(" ") end % x.quote - }.join + }.join(" ") + end + + def werror_flag(opt = nil) + config_string("WERRORFLAG") {|flag| opt = opt && !opt.empty? ? "#{opt} #{flag}" : flag} + opt end def with_werror(opt, opts = nil) - if opts - if opts[:werror] and config_string("WERRORFLAG") {|flag| opt = opt ? "#{opt} #{flag}" : flag} - (opts = opts.dup).delete(:werror) - end - yield(opt, opts) - else - yield(opt) - end + opt = werror_flag(opt) if opts and (opts = opts.dup).delete(:werror) + yield(opt, opts) end - def try_link0(src, opt="", *opts, &b) # :nodoc: + def try_link0(src, opt = "", ldflags: "", **opts, &b) # :nodoc: exe = CONFTEST+$EXEEXT - cmd = link_command("", opt) + cmd = link_command(ldflags, opt) if $universal require 'tmpdir' Dir.mktmpdir("mkmf_", oldtmpdir = ENV["TMPDIR"]) do |tmpdir| begin ENV["TMPDIR"] = tmpdir - try_do(src, cmd, *opts, &b) + try_do(src, cmd, **opts, &b) ensure ENV["TMPDIR"] = oldtmpdir end end else - try_do(src, cmd, *opts, &b) + try_do(src, cmd, **opts, &b) end and File.executable?(exe) or return nil exe ensure @@ -570,31 +632,32 @@ MSG # Returns whether or not the +src+ can be compiled as a C source and linked # with its depending libraries successfully. +opt+ is passed to the linker - # as options. Note that +$CFLAGS+ and +$LDFLAGS+ are also passed to the - # linker. + # as options. Note that <tt>$CFLAGS</tt> and <tt>$LDFLAGS</tt> are also + # passed to the linker. # # If a block given, it is called with the source before compilation. You can # modify the source in the block. # # [+src+] a String which contains a C source # [+opt+] a String which contains linker options - def try_link(src, opt="", *opts, &b) - exe = try_link0(src, opt, *opts, &b) or return false + def try_link(src, opt = "", **opts, &b) + exe = try_link0(src, opt, **opts, &b) or return false MakeMakefile.rm_f exe true end # Returns whether or not the +src+ can be compiled as a C source. +opt+ is - # passed to the C compiler as options. Note that +$CFLAGS+ is also passed to - # the compiler. + # passed to the C compiler as options. Note that <tt>$CFLAGS</tt> is also + # passed to the compiler. # # If a block given, it is called with the source before compilation. You can # modify the source in the block. # # [+src+] a String which contains a C source # [+opt+] a String which contains compiler options - def try_compile(src, opt="", *opts, &b) - with_werror(opt, *opts) {|_opt, *| try_do(src, cc_command(_opt), *opts, &b)} and + def try_compile(src, opt = "", werror: nil, **opts, &b) + opt = werror_flag(opt) if werror + try_do(src, cc_command(opt), werror: werror, **opts, &b) and File.file?("#{CONFTEST}.#{$OBJEXT}") ensure MakeMakefile.rm_f "#{CONFTEST}*" @@ -602,21 +665,21 @@ MSG # Returns whether or not the +src+ can be preprocessed with the C # preprocessor. +opt+ is passed to the preprocessor as options. Note that - # +$CFLAGS+ is also passed to the preprocessor. + # <tt>$CFLAGS</tt> is also passed to the preprocessor. # # If a block given, it is called with the source before preprocessing. You # can modify the source in the block. # # [+src+] a String which contains a C source # [+opt+] a String which contains preprocessor options - def try_cpp(src, opt="", *opts, &b) - try_do(src, cpp_command(CPPOUTFILE, opt), *opts, &b) and + def try_cpp(src, opt = "", **opts, &b) + try_do(src, cpp_command(CPPOUTFILE, opt), **opts, &b) and File.file?("#{CONFTEST}.i") ensure MakeMakefile.rm_f "#{CONFTEST}*" end - alias_method :try_header, (config_string('try_header') || :try_cpp) + alias try_header try_compile def cpp_include(header) if header @@ -627,6 +690,14 @@ MSG end end + # :startdoc: + + # Sets <tt>$CPPFLAGS</tt> to _flags_ and yields. If the block returns a + # falsy value, <tt>$CPPFLAGS</tt> is reset to its previous value, remains + # set to _flags_ otherwise. + # + # [+flags+] a C preprocessor flag as a +String+ + # def with_cppflags(flags) cppflags = $CPPFLAGS $CPPFLAGS = flags.dup @@ -635,20 +706,29 @@ MSG $CPPFLAGS = cppflags unless ret end - def try_cppflags(flags, opts = {}) - try_header(MAIN_DOES_NOTHING, flags, {:werror => true}.update(opts)) + # :nodoc: + def try_cppflags(flags, werror: true, **opts) + try_header(MAIN_DOES_NOTHING, flags, werror: werror, **opts) end - def append_cppflags(flags, *opts) + # Check whether each given C preprocessor flag is acceptable and append it + # to <tt>$CPPFLAGS</tt> if so. + # + # [+flags+] a C preprocessor flag as a +String+ or an +Array+ of them + # + def append_cppflags(flags, **opts) Array(flags).each do |flag| if checking_for("whether #{flag} is accepted as CPPFLAGS") { - try_cppflags(flag, *opts) + try_cppflags(flag, **opts) } $CPPFLAGS << " " << flag end end end + # Sets <tt>$CFLAGS</tt> to _flags_ and yields. If the block returns a falsy + # value, <tt>$CFLAGS</tt> is reset to its previous value, remains set to + # _flags_ otherwise. def with_cflags(flags) cflags = $CFLAGS $CFLAGS = flags.dup @@ -657,20 +737,14 @@ MSG $CFLAGS = cflags unless ret end - def try_cflags(flags, opts = {}) - try_compile(MAIN_DOES_NOTHING, flags, {:werror => true}.update(opts)) - end - - def append_cflags(flags, *opts) - Array(flags).each do |flag| - if checking_for("whether #{flag} is accepted as CFLAGS") { - try_cflags(flag, *opts) - } - $CFLAGS << " " << flag - end - end + # :nodoc: + def try_cflags(flags, werror: true, **opts) + try_compile(MAIN_DOES_NOTHING, flags, werror: werror, **opts) end + # Sets <tt>$LDFLAGS</tt> to _flags_ and yields. If the block returns a + # falsy value, <tt>$LDFLAGS</tt> is reset to its previous value, remains set + # to _flags_ otherwise. def with_ldflags(flags) ldflags = $LDFLAGS $LDFLAGS = flags.dup @@ -679,21 +753,30 @@ MSG $LDFLAGS = ldflags unless ret end - def try_ldflags(flags, opts = {}) - opts = {:werror => true}.update(opts) if $mswin - try_link(MAIN_DOES_NOTHING, flags, opts) + # :nodoc: + def try_ldflags(flags, werror: $mswin, **opts) + try_link(MAIN_DOES_NOTHING, "", ldflags: flags, werror: werror, **opts) end - def append_ldflags(flags, *opts) + # :startdoc: + + # Check whether each given linker flag is acceptable and append it to + # <tt>$LDFLAGS</tt> if so. + # + # [+flags+] a linker flag as a +String+ or an +Array+ of them + # + def append_ldflags(flags, **opts) Array(flags).each do |flag| if checking_for("whether #{flag} is accepted as LDFLAGS") { - try_ldflags(flag, *opts) + try_ldflags(flag, **opts) } $LDFLAGS << " " << flag end end end + # :stopdoc: + def try_static_assert(expr, headers = nil, opt = "", &b) headers = cpp_include(headers) try_compile(<<SRC, opt, &b) @@ -770,11 +853,20 @@ int main() {printf("%"PRI_CONFTEST_PREFIX"#{neg ? 'd' : 'u'}\\n", conftest_const # files. def try_func(func, libs, headers = nil, opt = "", &b) headers = cpp_include(headers) + prepare = String.new case func when /^&/ decltype = proc {|x|"const volatile void *#{x}"} when /\)$/ - call = func + strvars = [] + call = func.gsub(/""/) { + v = "s#{strvars.size + 1}" + strvars << v + v + } + unless strvars.empty? + prepare << "char " << strvars.map {|v| %[#{v}[1024] = ""]}.join(", ") << "; " + end when nil call = "" else @@ -784,7 +876,7 @@ int main() {printf("%"PRI_CONFTEST_PREFIX"#{neg ? 'd' : 'u'}\\n", conftest_const if opt and !opt.empty? [[:to_str], [:join, " "], [:to_s]].each do |meth, *args| if opt.respond_to?(meth) - break opt = opt.send(meth, *args) + break opt = opt.__send__(meth, *args) end end opt = "#{opt} #{libs}" @@ -804,7 +896,7 @@ SRC extern int t(void); #{MAIN_DOES_NOTHING 't'} #{"extern void #{call};" if decltype} -int t(void) { #{call}; return 0; } +int t(void) { #{prepare}#{call}; return 0; } SRC end @@ -820,6 +912,8 @@ int t(void) { const volatile void *volatile p; p = &(&#{var})[0]; return !p; } SRC end + # :startdoc: + # Returns whether or not the +src+ can be preprocessed with the C # preprocessor and matches with +pat+. # @@ -837,20 +931,12 @@ SRC xpopen(cpp_command('', opt)) do |f| if Regexp === pat puts(" ruby -ne 'print if #{pat.inspect}'") - f.grep(pat) {|l| + !f.grep(pat) {|l| puts "#{f.lineno}: #{l}" - return true - } - false + }.empty? else puts(" egrep '#{pat}'") - begin - stdin = $stdin.dup - $stdin.reopen(f) - system("egrep", pat) - ensure - $stdin.reopen(stdin) - end + system("egrep", pat, in: f) end end ensure @@ -858,6 +944,8 @@ SRC log_src(src) end + # :stopdoc: + # This is used internally by the have_macro? method. def macro_defined?(macro, src, opt = "", &b) src = src.sub(/[^\n]\z/, "\\&\n") @@ -877,8 +965,8 @@ SRC # * the linked file can be invoked as an executable # * and the executable exits successfully # - # +opt+ is passed to the linker as options. Note that +$CFLAGS+ and - # +$LDFLAGS+ are also passed to the linker. + # +opt+ is passed to the linker as options. Note that <tt>$CFLAGS</tt> and + # <tt>$LDFLAGS</tt> are also passed to the linker. # # If a block given, it is called with the source before compilation. You can # modify the source in the block. @@ -950,6 +1038,10 @@ SRC format(LIBARG, lib) + " " + libs end + # Prints messages to $stdout, if verbose mode. + # + # Internal use only. + # def message(*s) unless Logging.quiet and not $VERBOSE printf(*s) @@ -963,7 +1055,11 @@ SRC # Internal use only. # def checking_for(m, fmt = nil) - f = caller[0][/in `([^<].*)'$/, 1] and f << ": " #` for vim #' + if f = caller_locations(1, 1).first.base_label and /\A\w/ =~ f + f += ": " + else + f = "" + end m = "checking #{/\Acheck/ =~ f ? '' : 'for '}#{m}... " message "%s", m a = r = nil @@ -977,12 +1073,16 @@ SRC r end + # Build a message for checking. + # + # Internal use only. + # def checking_message(target, place = nil, opt = nil) [["in", place], ["with", opt]].inject("#{target}") do |msg, (pre, noun)| if noun [[:to_str], [:join, ","], [:to_s]].each do |meth, *args| if noun.respond_to?(meth) - break noun = noun.send(meth, *args) + break noun = noun.__send__(meth, *args) end end unless noun.empty? @@ -996,6 +1096,21 @@ SRC # :startdoc: + # Check whether each given C compiler flag is acceptable and append it + # to <tt>$CFLAGS</tt> if so. + # + # [+flags+] a C compiler flag as a +String+ or an +Array+ of them + # + def append_cflags(flags, **opts) + Array(flags).each do |flag| + if checking_for("whether #{flag} is accepted as CFLAGS") { + try_cflags(flag, **opts) + } + $CFLAGS << " " << flag + end + end + end + # Returns whether or not +macro+ is defined either in the common header # files or within any +headers+ you provide. # @@ -1047,7 +1162,7 @@ SRC def find_library(lib, func, *paths, &b) dir_config(lib) lib = with_config(lib+'lib', lib) - paths = paths.collect {|path| path.split(File::PATH_SEPARATOR)}.flatten + paths = paths.flat_map {|path| path.split(File::PATH_SEPARATOR)} checking_for checking_message(func && func.funcall_style, LIBARG%lib) do libpath = $LIBPATH libs = append_library($libs, lib) @@ -1223,6 +1338,7 @@ SRC end end + # :nodoc: # Returns whether or not the static type +type+ is defined. # # See also +have_type+ @@ -1280,6 +1396,7 @@ SRC end end + # :nodoc: # Returns whether or not the constant +const+ is defined. # # See also +have_const+ @@ -1323,8 +1440,10 @@ SRC # :stopdoc: STRING_OR_FAILED_FORMAT = "%s" - def STRING_OR_FAILED_FORMAT.%(x) # :nodoc: - x ? super : "failed" + class << STRING_OR_FAILED_FORMAT # :nodoc: + def %(x) + x ? super : "failed" + end end def typedef_expr(type, headers) @@ -1437,7 +1556,7 @@ SRC u = "unsigned " if signed > 0 prelude << "extern rbcv_typedef_ foo();" compat = UNIVERSAL_INTS.find {|t| - try_compile([prelude, "extern #{u}#{t} foo();"].join("\n"), opts, :werror=>true, &b) + try_compile([prelude, "extern #{u}#{t} foo();"].join("\n"), opts, werror: true, &b) } end if compat @@ -1461,7 +1580,7 @@ SRC # 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 + try_compile(<<"SRC", &b) #{cpp_include(headers)} /*top*/ volatile #{type} conftestval; @@ -1474,7 +1593,7 @@ SRC # 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 + try_compile(<<"SRC", &b) #{cpp_include(headers)} /*top*/ volatile #{type} conftestval; @@ -1496,6 +1615,10 @@ SRC end end + # :startdoc: + + # Returns a string represents the type of _type_, or _member_ of + # _type_ if _member_ is not +nil+. def what_type?(type, member = nil, headers = nil, &b) m = "#{type}" var = val = "*rbcv_var_" @@ -1555,6 +1678,8 @@ SRC end end + # :nodoc: + # # This method is used internally by the find_executable method. # # Internal use only. @@ -1593,8 +1718,6 @@ SRC 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. @@ -1727,8 +1850,8 @@ SRC hdr << "#endif\n" hdr = hdr.join("") log_src(hdr, "#{header} is") - unless (IO.read(header) == hdr rescue false) - open(header, "wb") do |hfile| + unless (File.read(header) == hdr rescue false) + File.open(header, "wb") do |hfile| hfile.write(hdr) end end @@ -1763,7 +1886,8 @@ SRC # application. # def dir_config(target, idefault=nil, ldefault=nil) - if conf = $config_dirs[target] + key = [target, idefault, ldefault].compact.join("\0") + if conf = $config_dirs[key] return conf end @@ -1773,9 +1897,13 @@ SRC end idir = with_config(target + "-include", idefault) - $arg_config.last[1] ||= "${#{target}-dir}/include" + if conf = $arg_config.assoc("--with-#{target}-include") + conf[1] ||= "${#{target}-dir}/include" + end ldir = with_config(target + "-lib", ldefault) - $arg_config.last[1] ||= "${#{target}-dir}/#{_libdir_basename}" + if conf = $arg_config.assoc("--with-#{target}-lib") + conf[1] ||= "${#{target}-dir}/#{_libdir_basename}" + end idirs = idir ? Array === idir ? idir.dup : idir.split(File::PATH_SEPARATOR) : [] if defaults @@ -1797,84 +1925,109 @@ SRC end $LIBPATH = ldirs | $LIBPATH - $config_dirs[target] = [idir, ldir] + $config_dirs[key] = [idir, ldir] end - # Returns compile/link information about an installed library in a - # tuple of <code>[cflags, ldflags, libs]</code>, by using the - # command found first in the following commands: + # Returns compile/link information about an installed library in a tuple of <code>[cflags, + # ldflags, libs]</code>, by using the command found first in the following commands: # # 1. If <code>--with-{pkg}-config={command}</code> is given via - # command line option: <code>{command} {option}</code> - # - # 2. <code>{pkg}-config {option}</code> - # - # 3. <code>pkg-config {option} {pkg}</code> - # - # Where {option} is, for instance, <code>--cflags</code>. - # - # The values obtained are appended to +$INCFLAGS+, +$CFLAGS+, +$LDFLAGS+ and - # +$libs+. - # - # If an <code>option</code> argument is given, the config command is - # invoked with the option and a stripped output string is returned - # without modifying any of the global values mentioned above. - def pkg_config(pkg, option=nil) - if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig) - # iff package specific config command is given - elsif ($PKGCONFIG ||= - (pkgconfig = with_config("pkg-config", ("pkg-config" unless CROSS_COMPILING))) && - find_executable0(pkgconfig) && pkgconfig) and - xsystem("#{$PKGCONFIG} --exists #{pkg}") - # default to pkg-config command - pkgconfig = $PKGCONFIG - get = proc {|opt| - opt = xpopen("#{$PKGCONFIG} --#{opt} #{pkg}", err:[:child, :out], &:read) - Logging.open {puts opt.each_line.map{|s|"=> #{s.inspect}"}} - opt.strip if $?.success? - } - elsif find_executable0(pkgconfig = "#{pkg}-config") - # default to package specific config command, as a last resort. - else - pkgconfig = nil - end - if pkgconfig - get ||= proc {|opt| - opt = xpopen("#{pkgconfig} --#{opt}", err:[:child, :out], &:read) - Logging.open {puts opt.each_line.map{|s|"=> #{s.inspect}"}} - opt.strip if $?.success? - } + # command line option: <code>{command} {options}</code> + # + # 2. <code>{pkg}-config {options}</code> + # + # 3. <code>pkg-config {options} {pkg}</code> + # + # Where +options+ is the option name without dashes, for instance <code>"cflags"</code> for the + # <code>--cflags</code> flag. + # + # The values obtained are appended to <code>$INCFLAGS</code>, <code>$CFLAGS</code>, + # <code>$LDFLAGS</code> and <code>$libs</code>. + # + # If one or more <code>options</code> argument is given, the config command is + # invoked with the options and a stripped output string is returned without + # modifying any of the global values mentioned above. + def pkg_config(pkg, *options) + fmt = "not found" + def fmt.%(x) + x ? x.inspect : self end - orig_ldflags = $LDFLAGS - if get and option - get[option] - elsif get and try_ldflags(ldflags = get['libs']) - if incflags = get['cflags-only-I'] - $INCFLAGS << " " << incflags - cflags = get['cflags-only-other'] - else - cflags = get['cflags'] - end - libs = get['libs-only-l'] - if cflags - $CFLAGS += " " << cflags - $CXXFLAGS += " " << cflags + + checking_for "pkg-config for #{pkg}", fmt do + _, ldir = dir_config(pkg) + if ldir + pkg_config_path = "#{ldir}/pkgconfig" + if File.directory?(pkg_config_path) + Logging.message("PKG_CONFIG_PATH = %s\n", pkg_config_path) + envs = ["PKG_CONFIG_PATH"=>[pkg_config_path, ENV["PKG_CONFIG_PATH"]].compact.join(File::PATH_SEPARATOR)] + end end - if libs - ldflags = (Shellwords.shellwords(ldflags) - Shellwords.shellwords(libs)).quote.join(" ") + if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig) + # if and only if package specific config command is given + elsif ($PKGCONFIG ||= + (pkgconfig = with_config("pkg-config") {config_string("PKG_CONFIG") || ENV["PKG_CONFIG"] || "pkg-config"}) && + find_executable0(pkgconfig) && pkgconfig) and + xsystem([*envs, $PKGCONFIG, "--exists", pkg]) + # default to pkg-config command + pkgconfig = $PKGCONFIG + args = [pkg] + elsif find_executable0(pkgconfig = "#{pkg}-config") + # default to package specific config command, as a last resort. else - libs, ldflags = Shellwords.shellwords(ldflags).partition {|s| s =~ /-l([^ ]+)/ }.map {|l|l.quote.join(" ")} + pkgconfig = nil + end + if pkgconfig + get = proc {|opts| + opts = Array(opts).map { |o| "--#{o}" } + opts = xpopen([*envs, pkgconfig, *opts, *args], err:[:child, :out], &:read) + Logging.open {puts opts.each_line.map{|s|"=> #{s.inspect}"}} + if $?.success? + opts = opts.strip + libarg, libpath = LIBARG, LIBPATHFLAG.strip + opts = opts.shellsplit.map { |s| + if s.start_with?('-l') + libarg % s[2..] + elsif s.start_with?('-L') + libpath % s[2..] + else + s + end + }.quote.join(" ") + opts + end + } end - $libs += " " << libs + orig_ldflags = $LDFLAGS + if get and !options.empty? + get[options] + elsif get and try_ldflags(ldflags = get['libs']) + if incflags = get['cflags-only-I'] + $INCFLAGS << " " << incflags + cflags = get['cflags-only-other'] + else + cflags = get['cflags'] + end + libs = get['libs-only-l'] + if cflags + $CFLAGS += " " << cflags + $CXXFLAGS += " " << cflags + end + if libs + ldflags = (Shellwords.shellwords(ldflags) - Shellwords.shellwords(libs)).quote.join(" ") + else + libs, ldflags = Shellwords.shellwords(ldflags).partition {|s| s =~ /-l([^ ]+)/ }.map {|l|l.quote.join(" ")} + end + $libs += " " << libs - $LDFLAGS = [orig_ldflags, ldflags].join(' ') - Logging::message "package configuration for %s\n", pkg - Logging::message "incflags: %s\ncflags: %s\nldflags: %s\nlibs: %s\n\n", - incflags, cflags, ldflags, libs - [[incflags, cflags].join(' '), ldflags, libs] - else - Logging::message "package configuration for %s is not found\n", pkg - nil + $LDFLAGS = [orig_ldflags, ldflags].join(' ') + Logging::message "package configuration for %s\n", pkg + Logging::message "incflags: %s\ncflags: %s\nldflags: %s\nlibs: %s\n\n", + incflags, cflags, ldflags, libs + [[incflags, cflags].join(' '), ldflags, libs] + else + Logging::message "package configuration for %s is not found\n", pkg + nil + end end end @@ -1908,7 +2061,7 @@ SRC path.sub!(/\A([A-Za-z]):(?=\/)/, '/\1') path end - when 'cygwin' + when 'cygwin', 'msys' if CONFIG['target_os'] != 'cygwin' def mkintpath(path) IO.popen(["cygpath", "-u", path], &:read).chomp @@ -1924,13 +2077,15 @@ SRC def configuration(srcdir) mk = [] + verbose = with_config('verbose') ? "1" : (CONFIG['MKMF_VERBOSE'] || "0") vpath = $VPATH.dup CONFIG["hdrdir"] ||= $hdrdir mk << %{ SHELL = /bin/sh # V=0 quiet, V=1 verbose. other values don't work. -V = 0 +V = #{verbose} +V0 = $(V:0=) Q1 = $(V:1=) Q = $(Q1:0=@) ECHO1 = $(V:1=@ #{CONFIG['NULLCMD']}) @@ -1942,7 +2097,7 @@ NULLCMD = #{CONFIG['NULLCMD']} srcdir = #{srcdir.gsub(/\$\((srcdir)\)|\$\{(srcdir)\}/) {mkintpath(CONFIG[$1||$2]).unspace}} topdir = #{mkintpath(topdir = $extmk ? CONFIG["topdir"] : $topdir).unspace} hdrdir = #{(hdrdir = CONFIG["hdrdir"]) == topdir ? "$(topdir)" : mkintpath(hdrdir).unspace} -arch_hdrdir = #{$arch_hdrdir.quote} +arch_hdrdir = #{mkintpath($arch_hdrdir).unspace} PATH_SEPARATOR = #{CONFIG['PATH_SEPARATOR']} VPATH = #{vpath.join(CONFIG['PATH_SEPARATOR'])} } @@ -1970,7 +2125,7 @@ VPATH = #{vpath.join(CONFIG['PATH_SEPARATOR'])} else sep = "" end - possible_command = (proc {|s| s if /top_srcdir/ !~ s} unless $extmk) + possible_command = (proc {|s| s if /top_srcdir|tooldir/ !~ s} unless $extmk) extconf_h = $extconf_h ? "-DRUBY_EXTCONF_H=\\\"$(RUBY_EXTCONF_H)\\\" " : $defs.join(" ") << " " headers = %w[ $(hdrdir)/ruby.h @@ -2021,7 +2176,9 @@ ARCH_FLAG = #{$ARCH_FLAG} DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG) LDSHARED = #{CONFIG['LDSHARED']} LDSHAREDXX = #{config_string('LDSHAREDXX') || '$(LDSHARED)'} +POSTLINK = #{config_string('POSTLINK', RbConfig::CONFIG)} AR = #{CONFIG['AR']} +LD = #{CONFIG['LD']} EXEEXT = #{CONFIG['EXEEXT']} } @@ -2034,10 +2191,15 @@ sitearch = #{CONFIG['sitearch']} ruby_version = #{RbConfig::CONFIG['ruby_version']} ruby = #{$ruby.sub(%r[\A#{Regexp.quote(RbConfig::CONFIG['bindir'])}(?=/|\z)]) {'$(bindir)'}} RUBY = $(ruby#{sep}) +BUILTRUBY = #{if defined?($builtruby) && $builtruby + $builtruby + else + File.join('$(bindir)', CONFIG["RUBY_INSTALL_NAME"] + CONFIG['EXEEXT']) + end} ruby_headers = #{headers.join(' ')} RM = #{config_string('RM', &possible_command) || '$(RUBY) -run -e rm -- -f'} -RM_RF = #{'$(RUBY) -run -e rm -- -rf'} +RM_RF = #{config_string('RMALL', &possible_command) || '$(RUBY) -run -e rm -- -rf'} RMDIRS = #{config_string('RMDIRS', &possible_command) || '$(RUBY) -run -e rmdir -- -p'} MAKEDIRS = #{config_string('MAKEDIRS', &possible_command) || '@$(RUBY) -run -e mkdir -- -p'} INSTALL = #{config_string('INSTALL', &possible_command) || '@$(RUBY) -run -e install -- -vp'} @@ -2068,7 +2230,7 @@ preload = #{defined?($preload) && $preload ? $preload.join(' ') : ''} end # :startdoc: - # creates a stub Makefile. + # Creates a stub Makefile. # def dummy_makefile(srcdir) configuration(srcdir) << <<RULES << CLEANINGS @@ -2216,13 +2378,26 @@ RULES # directory, i.e. the current directory. It is included as part of the # +VPATH+ and added to the list of +INCFLAGS+. # + # Yields the configuration part of the makefile to be generated, as an array + # of strings, if the block is given. The returned value will be used the + # new configuration part. + # + # create_makefile('foo') {|conf| + # [ + # *conf, + # "MACRO_YOU_NEED = something", + # ] + # } + # + # If "depend" file exist in the source directory, that content will be + # included in the generated makefile, with formatted by depend_rules method. def create_makefile(target, srcprefix = nil) $target = target libpath = $DEFLIBPATH|$LIBPATH message "creating Makefile\n" MakeMakefile.rm_f "#{CONFTEST}*" if CONFIG["DLEXT"] == $OBJEXT - for lib in libs = $libs.split + for lib in libs = $libs.split(' ') lib.sub!(/-l(.*)/, %%"lib\\1.#{$LIBEXT}"%) end $defs.push(format("-DEXTLIB='%s'", libs.join(","))) @@ -2239,7 +2414,7 @@ RULES RbConfig.expand(srcdir = srcprefix.dup) ext = ".#{$OBJEXT}" - orig_srcs = Dir[File.join(srcdir, "*.{#{SRC_EXT.join(%q{,})}}")].sort + orig_srcs = Dir[File.join(srcdir, "*.{#{SRC_EXT.join(%q{,})}}")] if not $objs srcs = $srcs || orig_srcs $objs = [] @@ -2249,7 +2424,7 @@ RULES h } unless objs.delete_if {|b, f| f.size == 1}.empty? - dups = objs.sort.map {|b, f| + dups = objs.map {|b, f| "#{b[/.*\./]}{#{f.collect {|n| n[/([^.]+)\z/]}.join(',')}}" } abort "source files duplication - #{dups.join(", ")}" @@ -2324,26 +2499,37 @@ TARGET_ENTRY = #{EXPORT_PREFIX || ''}Init_$(TARGET_NAME) DLLIB = #{dllib} EXTSTATIC = #{$static || ""} STATIC_LIB = #{staticlib unless $static.nil?} -#{!$extout && defined?($installed_list) ? "INSTALLED_LIST = #{$installed_list}\n" : ""} +#{!$extout && defined?($installed_list) ? %[INSTALLED_LIST = #{$installed_list}\n] : ""} TIMESTAMP_DIR = #{$extout && $extmk ? '$(extout)/.timestamp' : '.'} " #" # TODO: fixme install_dirs.each {|d| conf << ("%-14s= %s\n" % d) if /^[[:upper:]]/ =~ d[0]} sodir = $extout ? '$(TARGET_SO_DIR)' : '$(RUBYARCHDIR)' n = '$(TARGET_SO_DIR)$(TARGET)' + cleanobjs = ["$(OBJS)"] + cleanlibs = [] + if $extmk + %w[bc i s].each {|ex| cleanobjs << "$(OBJS:.#{$OBJEXT}=.#{ex})"} + end + if target + config_string('cleanobjs') {|t| cleanobjs << t.gsub(/\$\*/, "$(TARGET)#{deffile ? '-$(arch)': ''}")} + cleanlibs << '$(TARGET_SO)' + end + config_string('cleanlibs') {|t| cleanlibs << t.gsub(/\$\*/) {n}} conf << "\ TARGET_SO_DIR =#{$extout ? " $(RUBYARCHDIR)/" : ''} TARGET_SO = $(TARGET_SO_DIR)$(DLLIB) -CLEANLIBS = #{'$(TARGET_SO) ' if target}#{config_string('cleanlibs') {|t| t.gsub(/\$\*/) {n}}} -CLEANOBJS = *.#{$OBJEXT} #{config_string('cleanobjs') {|t| t.gsub(/\$\*/, "$(TARGET)#{deffile ? '-$(arch)': ''}")} if target} *.bak +CLEANLIBS = #{cleanlibs.join(' ')} +CLEANOBJS = #{cleanobjs.join(' ')} *.bak +TARGET_SO_DIR_TIMESTAMP = #{timestamp_file(sodir, target_prefix)} " #" conf = yield(conf) if block_given? - mfile = open("Makefile", "wb") + mfile = File.open("Makefile", "wb") mfile.puts(conf) mfile.print " all: #{$extout ? "install" : target ? "$(DLLIB)" : "Makefile"} -static: #{$extmk && !$static ? "all" : "$(STATIC_LIB)#{$extout ? " install-rb" : ""}"} +static: #{$extmk && !$static ? "all" : %[$(STATIC_LIB)#{$extout ? " install-rb" : ""}]} .PHONY: all install static install-so install-rb .PHONY: clean clean-so clean-static clean-rb " #" @@ -2369,11 +2555,12 @@ static: #{$extmk && !$static ? "all" : "$(STATIC_LIB)#{$extout ? " install-rb" : if target f = "$(DLLIB)" dest = "$(TARGET_SO)" - stamp = timestamp_file(dir, target_prefix) + stamp = '$(TARGET_SO_DIR_TIMESTAMP)' if $extout mfile.puts dest mfile.print "clean-so::\n" mfile.print "\t-$(Q)$(RM) #{fseprepl[dest]} #{fseprepl[stamp]}\n" + mfile.print "\t-$(Q)$(RM_RF) #{fseprepl['$(CLEANLIBS)']}\n" mfile.print "\t-$(Q)$(RMDIRS) #{fseprepl[dir]}#{$ignore_error}\n" else mfile.print "#{f} #{stamp}\n" @@ -2404,7 +2591,7 @@ static: #{$extmk && !$static ? "all" : "$(STATIC_LIB)#{$extout ? " install-rb" : dest = "#{dir}/#{File.basename(f)}" mfile.print("do-install-rb#{sfx}: #{dest}\n") mfile.print("#{dest}: #{f} #{timestamp_file(dir, target_prefix)}\n") - mfile.print("\t$(Q) $(#{$extout ? 'COPY' : 'INSTALL_DATA'}) #{f} $(@D)\n") + mfile.print("\t$(Q) $(#{$extout ? 'COPY' : 'INSTALL_DATA'}) #{f} $@\n") if defined?($installed_list) and !$extout mfile.print("\t@echo #{dest}>>$(INSTALLED_LIST)\n") end @@ -2438,7 +2625,9 @@ static: #{$extmk && !$static ? "all" : "$(STATIC_LIB)#{$extout ? " install-rb" : end end end - dirs.unshift(sodir) if target and !dirs.include?(sodir) + if target and !dirs.include?(sodir) + mfile.print "$(TARGET_SO_DIR_TIMESTAMP):\n\t$(Q) $(MAKEDIRS) $(@D) #{sodir}\n\t$(Q) $(TOUCH) $@\n" + end dirs.each do |d| t = timestamp_file(d, target_prefix) mfile.print "#{t}:\n\t$(Q) $(MAKEDIRS) $(@D) #{d}\n\t$(Q) $(TOUCH) $@\n" @@ -2482,7 +2671,7 @@ site-install-rb: install-rb mfile.print "$(TARGET_SO): " mfile.print "$(DEFFILE) " if makedef mfile.print "$(OBJS) Makefile" - mfile.print " #{timestamp_file(sodir, target_prefix)}" if $extout + mfile.print " $(TARGET_SO_DIR_TIMESTAMP)" if $extout mfile.print "\n" mfile.print "\t$(ECHO) linking shared-object #{target_prefix.sub(/\A\/(.*)/, '\1/')}$(DLLIB)\n" mfile.print "\t-$(Q)$(RM) $(@#{sep})\n" @@ -2496,7 +2685,7 @@ site-install-rb: install-rb mfile.print "$(ECHO) linking static-library $(@#{rsep})\n\t$(Q) " mfile.print "$(AR) #{config_string('ARFLAGS') || 'cru '}$@ $(OBJS)" config_string('RANLIB') do |ranlib| - mfile.print "\n\t-$(Q)#{ranlib} $(@) 2> /dev/null || true" + mfile.print "\n\t-$(Q)#{ranlib} $(@)#{$ignore_error}" end end mfile.print "\n\n" @@ -2530,7 +2719,7 @@ site-install-rb: install-rb if $warnflags = CONFIG['warnflags'] and CONFIG['GCC'] == 'yes' # turn warnings into errors only for bundled extensions. - config['warnflags'] = $warnflags.gsub(/(\A|\s)-Werror[-=]/, '\1-W') + config['warnflags'] = $warnflags.gsub(/(?:\A|\s)-W\Kerror[-=](?!implicit-function-declaration)/, '') if /icc\z/ =~ config['CC'] config['warnflags'].gsub!(/(\A|\s)-W(?:division-by-zero|deprecated-declarations)/, '\1') end @@ -2552,6 +2741,7 @@ site-install-rb: install-rb $INCFLAGS << " -I$(hdrdir)/ruby/backward" unless $extmk $INCFLAGS << " -I$(hdrdir) -I$(srcdir)" $DLDFLAGS = with_config("dldflags", arg_config("DLDFLAGS", config["DLDFLAGS"])).dup + config_string("ADDITIONAL_DLDFLAGS") {|flags| $DLDFLAGS << " " << flags} unless $extmk $LIBEXT = config['LIBEXT'].dup $OBJEXT = config["OBJEXT"].dup $EXEEXT = config["EXEEXT"].dup @@ -2640,7 +2830,7 @@ MESSAGE when $mswin $nmake = ?m if /nmake/i =~ make end - $ignore_error = $nmake ? '' : ' 2> /dev/null || true' + $ignore_error = " 2> #{File::NULL} || #{$mswin ? 'exit /b0' : 'true'}" RbConfig::CONFIG["srcdir"] = CONFIG["srcdir"] = $srcdir = arg_config("--srcdir", File.dirname($0)) @@ -2663,6 +2853,9 @@ MESSAGE split = Shellwords.method(:shellwords).to_proc + ## + # The prefix added to exported symbols automatically + EXPORT_PREFIX = config_string('EXPORT_PREFIX') {|s| s.strip} hdr = ['#include "ruby.h"' "\n"] @@ -2692,6 +2885,10 @@ MESSAGE # make compile rules COMPILE_RULES = config_string('COMPILE_RULES', &split) || %w[.%s.%s:] + + ## + # Substitution in rules for NMake + RULE_SUBST = config_string('RULE_SUBST') ## @@ -2736,7 +2933,11 @@ MESSAGE ## # Argument which will add a library path to the linker - LIBPATHFLAG = config_string('LIBPATHFLAG') || ' -L%s' + LIBPATHFLAG = config_string('LIBPATHFLAG') || '-L%s' + + ## + # Argument which will add a runtime library path to the linker + RPATHFLAG = config_string('RPATHFLAG') || '' ## @@ -2748,6 +2949,10 @@ MESSAGE # A C main function which does no work MAIN_DOES_NOTHING = config_string('MAIN_DOES_NOTHING') || "int main(int argc, char **argv)\n{\n return !!argv[argc];\n}" + + ## + # The type names for convertible_int + UNIVERSAL_INTS = config_string('UNIVERSAL_INTS') {|s| Shellwords.shellwords(s)} || %w[int short long long\ long] @@ -2762,14 +2967,14 @@ clean-rb-default:: clean-rb:: clean-so:: clean: clean-so clean-static clean-rb-default clean-rb -\t\t-$(Q)$(RM) $(CLEANLIBS#{sep}) $(CLEANOBJS#{sep}) $(CLEANFILES#{sep}) .*.time +\t\t-$(Q)$(RM_RF) $(CLEANLIBS#{sep}) $(CLEANOBJS#{sep}) $(CLEANFILES#{sep}) .*.time distclean-rb-default:: distclean-rb:: distclean-so:: distclean-static:: distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb -\t\t-$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) #{CONFTEST}.* mkmf.log +\t\t-$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) #{CONFTEST}.* mkmf.log#{' exts.mk' if $extmk} \t\t-$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES#{sep}) \t\t-$(Q)$(RMDIRS) $(DISTCLEANDIRS#{sep})#{$ignore_error} @@ -2778,18 +2983,32 @@ realclean: distclean @lang = Hash.new(self) + ## + # Retrieves the module for _name_ language. def self.[](name) @lang.fetch(name) end + ## + # Defines the module for _name_ language. def self.[]=(name, mod) @lang[name] = mod end - self["C++"] = Module.new do + ## + # The language that this module is for + LANGUAGE = -"C" + + self[self::LANGUAGE] = self + + cxx = Module.new do + # Module for C++ + include MakeMakefile extend self + # :stopdoc: + CONFTEST_CXX = "#{CONFTEST}.#{config_string('CXX_EXT') || CXX_EXT[0]}" TRY_LINK_CXX = config_string('TRY_LINK_CXX') || @@ -2811,18 +3030,45 @@ realclean: distclean def cc_command(opt="") conf = cc_config(opt) + cxx_command(opt, conf) RbConfig::expand("$(CXX) #$INCFLAGS #$CPPFLAGS #$CXXFLAGS #$ARCH_FLAG #{opt} -c #{CONFTEST_CXX}", conf) end + def cpp_command(outfile, opt="") + conf = cpp_config(opt) + cxx = cxx_command(opt, conf) + cpp = conf['CPP'].sub(/(\A|\s)#{Regexp.quote(conf['CC'])}(?=\z|\s)/) { + "#$1#{cxx}" + } + RbConfig::expand("#{cpp} #$INCFLAGS #$CPPFLAGS #$CXXFLAGS #{opt} #{CONFTEST_CXX} #{outfile}", + conf) + end + def link_command(ldflags, *opts) conf = link_config(ldflags, *opts) RbConfig::expand(TRY_LINK_CXX.dup, conf) end + + def cxx_command(opt="", conf = cc_config(opt)) + cxx = conf['CXX'] + raise Errno::ENOENT, "C++ compiler not found" if !cxx or cxx == 'false' + cxx + end + + # :startdoc: end + + cxx::LANGUAGE = -"C++" + self[cxx::LANGUAGE] = cxx end -include MakeMakefile +# MakeMakefile::Global = # +m = Module.new { + include(MakeMakefile) + private(*MakeMakefile.public_instance_methods(false)) +} +include m if not $extmk and /\A(extconf|makefile).rb\z/ =~ File.basename($0) END {mkmf_failed($0)} |
