summaryrefslogtreecommitdiff
path: root/lib/mkmf.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-01-09 18:32:32 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-01-09 21:44:15 +0900
commit29dc9378d971a66ad3fcb21281aac23f0521afe5 (patch)
tree208d502b0d14708d05833e1d9649ae95be715b44 /lib/mkmf.rb
parent0d7bbfc9415aa066ea8c17b90dd06c5d47fed50b (diff)
mkmf.rb: Refine message from `pkg_config`
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7088
Diffstat (limited to 'lib/mkmf.rb')
-rw-r--r--lib/mkmf.rb113
1 files changed, 60 insertions, 53 deletions
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index 791838308c..245b0a44ce 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -1849,66 +1849,73 @@ SRC
# 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"
- 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
+ fmt = "not found"
+ def fmt.%(x)
+ x ? x.inspect : self
end
- if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig)
+
+ 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 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")
+ 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
+ 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
- if libs
- ldflags = (Shellwords.shellwords(ldflags) - Shellwords.shellwords(libs)).quote.join(" ")
+ 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
- libs, ldflags = Shellwords.shellwords(ldflags).partition {|s| s =~ /-l([^ ]+)/ }.map {|l|l.quote.join(" ")}
+ Logging::message "package configuration for %s is not found\n", pkg
+ nil
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