mkmf.rb: Refine message from pkg_config
This commit is contained in:
parent
0d7bbfc941
commit
29dc9378d9
Notes:
git
2023-01-09 12:44:42 +00:00
123
lib/mkmf.rb
123
lib/mkmf.rb
@ -1849,66 +1849,73 @@ SRC
|
|||||||
# invoked with the options and a stripped output string is returned without
|
# invoked with the options and a stripped output string is returned without
|
||||||
# modifying any of the global values mentioned above.
|
# modifying any of the global values mentioned above.
|
||||||
def pkg_config(pkg, *options)
|
def pkg_config(pkg, *options)
|
||||||
_, ldir = dir_config(pkg)
|
fmt = "not found"
|
||||||
if ldir
|
def fmt.%(x)
|
||||||
pkg_config_path = "#{ldir}/pkgconfig"
|
x ? x.inspect : self
|
||||||
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
|
end
|
||||||
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") || "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
|
|
||||||
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}"}}
|
|
||||||
opts.strip if $?.success?
|
|
||||||
}
|
|
||||||
end
|
|
||||||
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(' ')
|
checking_for "pkg-config for #{pkg}", fmt do
|
||||||
Logging::message "package configuration for %s\n", pkg
|
_, ldir = dir_config(pkg)
|
||||||
Logging::message "incflags: %s\ncflags: %s\nldflags: %s\nlibs: %s\n\n",
|
if ldir
|
||||||
incflags, cflags, ldflags, libs
|
pkg_config_path = "#{ldir}/pkgconfig"
|
||||||
[[incflags, cflags].join(' '), ldflags, libs]
|
if File.directory?(pkg_config_path)
|
||||||
else
|
Logging.message("PKG_CONFIG_PATH = %s\n", pkg_config_path)
|
||||||
Logging::message "package configuration for %s is not found\n", pkg
|
envs = ["PKG_CONFIG_PATH"=>[pkg_config_path, ENV["PKG_CONFIG_PATH"]].compact.join(File::PATH_SEPARATOR)]
|
||||||
nil
|
end
|
||||||
|
end
|
||||||
|
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") || "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
|
||||||
|
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}"}}
|
||||||
|
opts.strip if $?.success?
|
||||||
|
}
|
||||||
|
end
|
||||||
|
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
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user