implement ConfigureOp#check_cfg - not tested yet

This commit is contained in:
Josh Holtrop 2018-11-14 23:28:00 -05:00
parent aba11155a4
commit ab4ca71ac7
3 changed files with 125 additions and 0 deletions

View File

@ -100,6 +100,11 @@ module Rscons
if cdc = @script.check_d_compiler
co.check_d_compiler(cdc)
end
if ccs = @script.check_cfgs
ccs.each do |cc|
co.check_cfg(*cc)
end
end
if cchs = @script.check_c_headers
cchs.each do |cch|
co.check_c_header(*cch)

View File

@ -98,6 +98,21 @@ module Rscons
end
end
# Check for a package or configure program output.
def check_cfg(options = {})
program = options[:program] || "pkg-config"
args = options[:args] || %w[--cflags --libs]
command = [program] + args
if options[:package]
command += [options[:package]]
end
stdout, _, status = log_and_test_command(command)
if status == 0
parse_flags(stdout)
end
common_config_checks(status, options)
end
# Check for a C header.
def check_c_header(header_name, options = {})
$stdout.write("Checking for C header '#{header_name}'... ")
@ -339,6 +354,24 @@ module Rscons
end
end
# Merge construction variables into the configured Environment.
#
# This method does the same thing as {#merge_vars}, except that Array
# values in +vars+ are appended to the end of Array construction variables
# instead of replacing their contents.
#
# @param vars [Hash]
# Hash containing the variables to merge.
def append_vars(vars)
vars.each_pair do |key, val|
if @env[key].is_a?(Array) and val.is_a?(Array)
@env[key] += val
else
@env[key] = val
end
end
end
# Perform processing common to several configure checks.
#
# @param status [Process::Status, Integer]
@ -397,5 +430,82 @@ module Rscons
end
end
# Parse compilation flags (from a program like pkg-config for example).
#
# @param flags [String]
# Compilation flags.
def parse_flags(flags)
vars = {}
words = Shellwords.split(flags)
skip = false
words.each_with_index do |word, i|
if skip
skip = false
next
end
append = lambda do |var, val|
vars[var] ||= []
vars[var] += val
end
handle = lambda do |var, val|
if val.nil? or val.empty?
val = words[i + 1]
skip = true
end
if val and not val.empty?
append[var, [val]]
end
end
if word == "-arch"
if val = words[i + 1]
append["CCFLAGS", ["-arch", val]]
append["LDFLAGS", ["-arch", val]]
end
skip = true
elsif word =~ /^#{@env["CPPDEFPREFIX"]}(.*)$/
handle["CPPDEFINES", $1]
elsif word == "-include"
if val = words[i + 1]
append["CCFLAGS", ["-include", val]]
end
skip = true
elsif word == "-isysroot"
if val = words[i + 1]
append["CCFLAGS", ["-isysroot", val]]
append["LDFLAGS", ["-isysroot", val]]
end
skip = true
elsif word =~ /^#{@env["INCPREFIX"]}(.*)$/
handle["CPPPATH", $1]
elsif word =~ /^#{@env["LIBLINKPREFIX"]}(.*)$/
handle["LIBS", $1]
elsif word =~ /^#{@env["LIBDIRPREFIX"]}(.*)$/
handle["LIBPATH", $1]
elsif word == "-mno-cygwin"
append["CCFLAGS", [word]]
append["LDFLAGS", [word]]
elsif word == "-mwindows"
append["LDFLAGS", [word]]
elsif word == "-pthread"
append["CCFLAGS", [word]]
append["LDFLAGS", [word]]
elsif word =~ /^-Wa,(.*)$/
append["ASFLAGS", $1.split(",")]
elsif word =~ /^-Wl,(.*)$/
append["LDFLAGS", $1.split(",")]
elsif word =~ /^-Wp,(.*)$/
append["CPPFLAGS", $1.split(",")]
elsif word.start_with?("-")
append["CCFLAGS", [word]]
elsif word.start_with?("+")
append["CCFLAGS", [word]]
append["LDFLAGS", [word]]
else
append["LIBS", [word]]
end
end
append_vars(vars)
end
end
end

View File

@ -42,6 +42,12 @@ module Rscons
@script.check_d_compiler = args
end
# Check for a package or configure program output.
def check_cfg(*args)
@script.check_cfgs ||= []
@script.check_cfgs << args
end
# Check for a C header.
def check_c_header(*args)
@script.check_c_headers ||= []
@ -89,6 +95,10 @@ module Rscons
# D compilers to check for.
attr_accessor :check_d_compiler
# @return [Array<Array>]
# Configs to check for.
attr_accessor :check_cfgs
# @return [Array<Array>]
# C headers to check for.
attr_accessor :check_c_headers