pkg_config(pkg, option=nil)
public
Returns compile/link information about an installed library in a tuple of
[cflags, ldflags, libs], by using the command found first in the following
commands:
-
If –with-{pkg}-config={command} is given via command line option:
{command} {option}
-
{pkg}-config {option}
-
pkg-config {option} {pkg}
Where {option} is, for instance, –cflags.
The values obtained are appended to +$CFLAGS+, +$LDFLAGS+ and +$libs+.
If an option 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.
Show source
def pkg_config(pkg, option=nil)
if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig)
elsif ($PKGCONFIG ||=
(pkgconfig = with_config("pkg-config", ("pkg-config" unless CROSS_COMPILING))) &&
find_executable0(pkgconfig) && pkgconfig) and
system("#{$PKGCONFIG} --exists #{pkg}")
pkgconfig = $PKGCONFIG
get = proc {|opt|
opt = IO.popen("#{$PKGCONFIG} --#{opt} #{pkg}", err[[:child, :out], &:read)
opt.strip if $?.success?
}
elsif find_executable0(pkgconfig = "#{pkg}-config")
else
pkgconfig = nil
end
if pkgconfig
get ||= proc {|opt|
opt = IO.popen("#{pkgconfig} --#{opt}", err[[:child, :out], &:read)
opt.strip if $?.success?
}
end
orig_ldflags = $LDFLAGS
if get and option
get[option]
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 "cflags: %s\nldflags: %s\nlibs: %s\n\n",
cflags, ldflags, libs
[cflags, ldflags, libs]
else
Logging::message "package configuration for %s is not found\n", pkg
nil
end
end