Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg-config: split out pkg.m4 #182175

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Formula/p/pkg-config.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class PkgConfig < Formula
desc "Manage compile and link flags for libraries"
homepage "https://freedesktop.org/wiki/Software/pkg-config/"
homepage "https://www.freedesktop.org/wiki/Software/pkg-config/"
url "https://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz"
mirror "http://fresh-center.net/linux/misc/pkg-config-0.29.2.tar.gz"
mirror "http://fresh-center.net/linux/misc/legacy/pkg-config-0.29.2.tar.gz"
sha256 "6fc69c01688c9458a57eb9a1664c9aba372ccda420a02bf4429fe610e7e7d591"
license "GPL-2.0-or-later"
revision 3
revision 4

livecheck do
url "https://pkg-config.freedesktop.org/releases/"
Expand All @@ -28,12 +28,12 @@ class PkgConfig < Formula
sha256 cellar: :any_skip_relocation, x86_64_linux: "3d9b8bf9b7b4bd08086be1104e3e18afb1c437dfaca03e6e7df8f2710b9c1c1a"
end

conflicts_with "pkgconf", because: "both install `pkg.m4` file"

# FIXME: The bottle is mistakenly considered relocatable on Linux.
# See https://github.com/Homebrew/homebrew-core/pull/85032.
pour_bottle? only_if: :default_prefix

depends_on "pkg.m4"

def install
pc_path = %W[
#{HOMEBREW_PREFIX}/lib/pkgconfig
Expand Down Expand Up @@ -65,6 +65,9 @@ def install
"--with-system-include-path=#{system_include_path}"
system "make"
system "make", "install"

# Move `pkg.m4` into libexec as using copy from formula. Keep to make sure identical.
libexec.install share/"aclocal/pkg.m4"
end

test do
Expand All @@ -86,5 +89,6 @@ def install
assert_equal "1.0.0\n", shell_output("#{bin}/pkg-config --modversion foo")
assert_equal "-lfoo\n", shell_output("#{bin}/pkg-config --libs foo")
assert_equal "-I/usr/include/foo\n", shell_output("#{bin}/pkg-config --cflags foo")
assert_equal (Formula["pkg.m4"].share/"aclocal/pkg.m4").read, (libexec/"pkg.m4").read
end
end
31 changes: 31 additions & 0 deletions Formula/p/pkg.m4.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class PkgM4 < Formula
# TODO: Switch to pkgconf source or merge back into pkgconf formula once migration is done
desc "Macros to locate and use pkg-config"
homepage "https://www.freedesktop.org/wiki/Software/pkg-config/"
url "https://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz"
mirror "http://fresh-center.net/linux/misc/pkg-config-0.29.2.tar.gz"
sha256 "6fc69c01688c9458a57eb9a1664c9aba372ccda420a02bf4429fe610e7e7d591"
license "GPL-2.0-or-later"

livecheck do
formula "pkg-config"
end

uses_from_macos "m4" => :test

def install
system "./configure", "--disable-host-tool",
"--disable-silent-rules",
"--with-internal-glib",
*std_configure_args
system "make", "install-m4DATA"
end

test do
(testpath/"test.m4").write <<~EOS
changequote([,])
include([#{share}/aclocal/pkg.m4])
EOS
assert_match "AC_DEFUN(PKG_CHECK_MODULES", shell_output("m4 --fatal-warnings test.m4")
end
end
41 changes: 34 additions & 7 deletions Formula/p/pkgconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Pkgconf < Formula
url "https://distfiles.ariadne.space/pkgconf/pkgconf-2.3.0.tar.xz"
sha256 "3a9080ac51d03615e7c1910a0a2a8df08424892b5f13b0628a204d3fcce0ea8b"
license "ISC"
revision 1

livecheck do
url "https://distfiles.ariadne.space/pkgconf/"
Expand All @@ -28,35 +29,61 @@ class Pkgconf < Formula
depends_on "libtool" => :build
end

conflicts_with "pkg-config", because: "both install `pkg.m4` file"
depends_on "pkg.m4"

def install
if build.head?
ENV["LIBTOOLIZE"] = "glibtoolize"
system "./autogen.sh"
end

system_prefix = "/usr"
pc_path = %W[
#{HOMEBREW_PREFIX}/lib/pkgconfig
#{HOMEBREW_PREFIX}/share/pkgconfig
]
pc_path << if OS.mac?
pc_path << "/usr/local/lib/pkgconfig"
system_prefix = "#{MacOS.sdk_path_if_needed}/usr"

pc_path << "/usr/local/lib/pkgconfig" if HOMEBREW_PREFIX.to_s != "/usr/local"
pc_path << "/usr/lib/pkgconfig"
"#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}"
else
"#{HOMEBREW_LIBRARY}/Homebrew/os/linux/pkgconfig"
end

pc_path = pc_path.uniq.join(File::PATH_SEPARATOR)

configure_args = std_configure_args + %W[
--with-pkg-config-dir=#{pc_path}
args = %W[
--with-pkg-config-dir=#{pc_path.uniq.join(File::PATH_SEPARATOR)}
--with-personality-dir=#{HOMEBREW_PREFIX}/share/pkgconfig/personality.d:#{etc}/pkgconfig/personality.d
--with-system-includedir=#{HOMEBREW_PREFIX}/include:#{system_prefix}/include
--with-system-libdir=#{HOMEBREW_PREFIX}/lib:#{system_prefix}/lib
--disable-silent-rules
]

system "./configure", *configure_args
system "./configure", *args, *std_configure_args
system "make"
system "make", "install"

# Move `pkg.m4` into libexec to make it easier for migration to `pkgconf`
libexec.install share/"aclocal/pkg.m4"

# TODO: Consider making `pkgconf` a drop-in replacement to `pkg-config` by adding
# symlink and restoring conflicts. Similar to Debian, Fedora, ArchLinux and MacPorts.
# Alternatively can keep separate non-conflicting commands and update `pkg.m4` to use
# `pkgconf` copy after sufficiently migrated.
# Ref: https://github.com/pkgconf/pkgconf/#pkg-config-symlink
# Ref: https://salsa.debian.org/debian/pkgconf/-/blob/debian/unstable/debian/pkgconf.links?ref_type=heads
#
# bin.install_symlink "pkgconf" => "pkg-config"
# man1.install_symlink "pkgconf.1" => "pkg-config.1"
end

def caveats
<<~EOS
To allow easier migration from `pkg-config` to `pkgconf`, the `pkgconf` formula
uses `pkg-config`'s pkg.m4 to avoid conflict. If you need the copy from `pkgconf`,
then it is available at #{libexec}/pkg.m4
EOS
end

test do
Expand Down
Loading