mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
mkmf: pkg_config accepts multiple options
This commit is contained in:
parent
24c7e75ded
commit
b90e56e624
Notes:
git
2022-01-29 15:23:13 +09:00
2 changed files with 32 additions and 23 deletions
48
lib/mkmf.rb
48
lib/mkmf.rb
|
|
@ -1836,26 +1836,26 @@ SRC
|
||||||
$config_dirs[target] = [idir, ldir]
|
$config_dirs[target] = [idir, ldir]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns compile/link information about an installed library in a
|
# Returns compile/link information about an installed library in a tuple of <code>[cflags,
|
||||||
# tuple of <code>[cflags, ldflags, libs]</code>, by using the
|
# ldflags, libs]</code>, by using the command found first in the following commands:
|
||||||
# command found first in the following commands:
|
|
||||||
#
|
#
|
||||||
# 1. If <code>--with-{pkg}-config={command}</code> is given via
|
# 1. If <code>--with-{pkg}-config={command}</code> is given via
|
||||||
# command line option: <code>{command} {option}</code>
|
# command line option: <code>{command} {options}</code>
|
||||||
#
|
#
|
||||||
# 2. <code>{pkg}-config {option}</code>
|
# 2. <code>{pkg}-config {options}</code>
|
||||||
#
|
#
|
||||||
# 3. <code>pkg-config {option} {pkg}</code>
|
# 3. <code>pkg-config {options} {pkg}</code>
|
||||||
#
|
#
|
||||||
# Where {option} is, for instance, <code>--cflags</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 +$INCFLAGS+, +$CFLAGS+, +$LDFLAGS+ and
|
# The values obtained are appended to <code>$INCFLAGS</code>, <code>$CFLAGS</code>,
|
||||||
# +$libs+.
|
# <code>$LDFLAGS</code> and <code>$libs</code>.
|
||||||
#
|
#
|
||||||
# If an <code>option</code> argument is given, the config command is
|
# If one or more <code>options</code> argument is given, the config command is
|
||||||
# invoked with the option and a stripped output string is returned
|
# invoked with the options and a stripped output string is returned without
|
||||||
# without modifying any of the global values mentioned above.
|
# modifying any of the global values mentioned above.
|
||||||
def pkg_config(pkg, option=nil)
|
def pkg_config(pkg, *options)
|
||||||
_, ldir = dir_config(pkg)
|
_, ldir = dir_config(pkg)
|
||||||
if ldir
|
if ldir
|
||||||
pkg_config_path = "#{ldir}/pkgconfig"
|
pkg_config_path = "#{ldir}/pkgconfig"
|
||||||
|
|
@ -1872,10 +1872,11 @@ SRC
|
||||||
xsystem([*envs, $PKGCONFIG, "--exists", pkg])
|
xsystem([*envs, $PKGCONFIG, "--exists", pkg])
|
||||||
# default to pkg-config command
|
# default to pkg-config command
|
||||||
pkgconfig = $PKGCONFIG
|
pkgconfig = $PKGCONFIG
|
||||||
get = proc {|opt|
|
get = proc {|opts|
|
||||||
opt = xpopen([*envs, $PKGCONFIG, "--#{opt}", pkg], err:[:child, :out], &:read)
|
opts = Array(opts).map { |o| "--#{o}" }
|
||||||
Logging.open {puts opt.each_line.map{|s|"=> #{s.inspect}"}}
|
opts = xpopen([*envs, $PKGCONFIG, *opts, pkg], err:[:child, :out], &:read)
|
||||||
opt.strip if $?.success?
|
Logging.open {puts opts.each_line.map{|s|"=> #{s.inspect}"}}
|
||||||
|
opts.strip if $?.success?
|
||||||
}
|
}
|
||||||
elsif find_executable0(pkgconfig = "#{pkg}-config")
|
elsif find_executable0(pkgconfig = "#{pkg}-config")
|
||||||
# default to package specific config command, as a last resort.
|
# default to package specific config command, as a last resort.
|
||||||
|
|
@ -1883,15 +1884,16 @@ SRC
|
||||||
pkgconfig = nil
|
pkgconfig = nil
|
||||||
end
|
end
|
||||||
if pkgconfig
|
if pkgconfig
|
||||||
get ||= proc {|opt|
|
get ||= proc {|opts|
|
||||||
opt = xpopen([*envs, pkgconfig, "--#{opt}"], err:[:child, :out], &:read)
|
opts = Array(opts).map { |o| "--#{o}" }
|
||||||
Logging.open {puts opt.each_line.map{|s|"=> #{s.inspect}"}}
|
opts = xpopen([*envs, pkgconfig, *opts], err:[:child, :out], &:read)
|
||||||
opt.strip if $?.success?
|
Logging.open {puts opts.each_line.map{|s|"=> #{s.inspect}"}}
|
||||||
|
opts.strip if $?.success?
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
orig_ldflags = $LDFLAGS
|
orig_ldflags = $LDFLAGS
|
||||||
if get and option
|
if get and !options.empty?
|
||||||
get[option]
|
get[options]
|
||||||
elsif get and try_ldflags(ldflags = get['libs'])
|
elsif get and try_ldflags(ldflags = get['libs'])
|
||||||
if incflags = get['cflags-only-I']
|
if incflags = get['cflags-only-I']
|
||||||
$INCFLAGS << " " << incflags
|
$INCFLAGS << " " << incflags
|
||||||
|
|
|
||||||
|
|
@ -57,5 +57,12 @@ class TestMkmf
|
||||||
actual = pkg_config("test1", "cflags").shellsplit.sort
|
actual = pkg_config("test1", "cflags").shellsplit.sort
|
||||||
assert_equal(expected, actual, MKMFLOG)
|
assert_equal(expected, actual, MKMFLOG)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_pkgconfig_with_multiple_options
|
||||||
|
pend("skipping because pkg-config is not installed") unless PKG_CONFIG
|
||||||
|
expected = ["-L#{@fixtures_lib_dir}", "-ltest1-public", "-ltest1-private"].sort
|
||||||
|
actual = pkg_config("test1", "libs", "static").shellsplit.sort
|
||||||
|
assert_equal(expected, actual, MKMFLOG)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue