summaryrefslogtreecommitdiff
path: root/lib/mkmf.rb
diff options
context:
space:
mode:
authorMike Dalessio <mike.dalessio@gmail.com>2022-01-18 08:13:48 -0500
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-01-29 15:22:52 +0900
commitb90e56e6243f4e6567991bfd2375e1f58b1414a0 (patch)
tree267ecc454514f733c8ba3d7bd95ace2896bd8601 /lib/mkmf.rb
parent24c7e75ded461446e7c8e83bbceecccf7bcb4d0e (diff)
mkmf: pkg_config accepts multiple options
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5436
Diffstat (limited to 'lib/mkmf.rb')
-rw-r--r--lib/mkmf.rb48
1 files changed, 25 insertions, 23 deletions
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index 118b81314c..e371522f21 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -1836,26 +1836,26 @@ SRC
$config_dirs[target] = [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>
+ # 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
- # +$libs+.
+ # The values obtained are appended to <code>$INCFLAGS</code>, <code>$CFLAGS</code>,
+ # <code>$LDFLAGS</code> and <code>$libs</code>.
#
- # 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 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)
_, ldir = dir_config(pkg)
if ldir
pkg_config_path = "#{ldir}/pkgconfig"
@@ -1872,10 +1872,11 @@ SRC
xsystem([*envs, $PKGCONFIG, "--exists", pkg])
# default to pkg-config command
pkgconfig = $PKGCONFIG
- get = proc {|opt|
- opt = xpopen([*envs, $PKGCONFIG, "--#{opt}", pkg], err:[:child, :out], &:read)
- Logging.open {puts opt.each_line.map{|s|"=> #{s.inspect}"}}
- opt.strip if $?.success?
+ get = proc {|opts|
+ opts = Array(opts).map { |o| "--#{o}" }
+ opts = xpopen([*envs, $PKGCONFIG, *opts, pkg], err:[:child, :out], &:read)
+ Logging.open {puts opts.each_line.map{|s|"=> #{s.inspect}"}}
+ opts.strip if $?.success?
}
elsif find_executable0(pkgconfig = "#{pkg}-config")
# default to package specific config command, as a last resort.
@@ -1883,15 +1884,16 @@ SRC
pkgconfig = nil
end
if pkgconfig
- get ||= proc {|opt|
- opt = xpopen([*envs, pkgconfig, "--#{opt}"], err:[:child, :out], &:read)
- Logging.open {puts opt.each_line.map{|s|"=> #{s.inspect}"}}
- opt.strip if $?.success?
+ get ||= proc {|opts|
+ opts = Array(opts).map { |o| "--#{o}" }
+ opts = xpopen([*envs, pkgconfig, *opts], 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 option
- get[option]
+ if get and !options.empty?
+ get[options]
elsif get and try_ldflags(ldflags = get['libs'])
if incflags = get['cflags-only-I']
$INCFLAGS << " " << incflags