-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce activate(mkmf: true) with support for pkg-config
which will set $LDFLAGS and $CFLAGS according to the pkg-config file This should allow gems with C extensions that use mini_portile to pass in the pkg-config and everything should just work.
- Loading branch information
1 parent
eb88a08
commit 2bc8ae3
Showing
7 changed files
with
213 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ Gemfile.lock | |
pkg | ||
ports | ||
tmp | ||
mkmf.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# frozen-string-literal: false | ||
|
||
require "mkmf" | ||
|
||
module MakeMakefile | ||
# | ||
# this version of pkg_config is taken from ruby 29dc9378 (2023-01-09) | ||
# | ||
# specifically with the fix from b90e56e6 to support multiple pkg-config options | ||
# | ||
def pkg_config(pkg, *options) | ||
fmt = "not found" | ||
def fmt.%(x) | ||
x ? x.inspect : self | ||
end | ||
|
||
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") | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
prefix=/foo/libxml2/2.11.5 | ||
exec_prefix=${prefix} | ||
libdir=/foo/libxml2/2.11.5/lib | ||
includedir=${prefix}/include | ||
modules=1 | ||
|
||
Name: libXML | ||
Version: 2.11.5 | ||
Description: libXML library version2. | ||
Requires: | ||
Libs: -L${libdir} -lxml2 | ||
Libs.private: -L/foo/zlib/1.3/lib -lz -lm | ||
Cflags: -I${includedir}/libxml2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
prefix=/foo/libxslt/1.1.38 | ||
exec_prefix=${prefix} | ||
libdir=/foo/libxslt/1.1.38/lib | ||
includedir=${prefix}/include | ||
|
||
|
||
Name: libxslt | ||
Version: 1.1.38 | ||
Description: XSLT library version 2. | ||
Requires: libxml-2.0 | ||
Cflags: -I${includedir} | ||
Libs: -L${libdir} -lxslt | ||
Libs.private: -lm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters