From 52104bdd095af21956fd75492f650e8b74f45c31 Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Fri, 23 Aug 2024 17:07:40 -0400 Subject: [PATCH 1/3] pkg.m4 0.29.2 (new formula) --- Formula/p/pkg.m4.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Formula/p/pkg.m4.rb diff --git a/Formula/p/pkg.m4.rb b/Formula/p/pkg.m4.rb new file mode 100644 index 000000000000..310289a1f78c --- /dev/null +++ b/Formula/p/pkg.m4.rb @@ -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 From 4d2f32bf7c5374470cdf386672cb12600d0efbf3 Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Fri, 23 Aug 2024 18:53:44 -0400 Subject: [PATCH 2/3] pkg-config: split out `pkg.m4` To (at least temporarily) remove conflict with `pkgconf` so that it allows for migration. `pkgconf` has replaced `pkg-config` in major repositories like Debian and Fedora. --- Formula/p/pkg-config.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Formula/p/pkg-config.rb b/Formula/p/pkg-config.rb index 5ce99bd241ca..06b4628ef894 100644 --- a/Formula/p/pkg-config.rb +++ b/Formula/p/pkg-config.rb @@ -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/" @@ -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 @@ -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 @@ -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 From 2ee32e57864054ecec8410784eda808b28e717e1 Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Fri, 23 Aug 2024 19:18:31 -0400 Subject: [PATCH 3/3] pkgconf: use `pkg.m4` from `pkg-config` via split formula --- Formula/p/pkgconf.rb | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/Formula/p/pkgconf.rb b/Formula/p/pkgconf.rb index 259bbb1c1fe2..a897f0ca3062 100644 --- a/Formula/p/pkgconf.rb +++ b/Formula/p/pkgconf.rb @@ -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/" @@ -28,7 +29,7 @@ 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? @@ -36,27 +37,53 @@ def install 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