homebrew-core/Formula/libxml2.rb

125 lines
4.2 KiB
Ruby

class Libxml2 < Formula
desc "GNOME XML library"
homepage "http://xmlsoft.org/"
url "https://download.gnome.org/sources/libxml2/2.10/libxml2-2.10.3.tar.xz"
sha256 "5d2cc3d78bec3dbe212a9d7fa629ada25a7da928af432c93060ff5c17ee28a9c"
license "MIT"
revision 2
# We use a common regex because libxml2 doesn't use GNOME's "even-numbered
# minor is stable" version scheme.
livecheck do
url :stable
regex(/libxml2[._-]v?(\d+(?:\.\d+)+)\.t/i)
end
bottle do
sha256 cellar: :any, arm64_ventura: "a708bd03acce240aed84cf429ccb2af3bc6605bd728fc225dfb76ba47b93878f"
sha256 cellar: :any, arm64_monterey: "0d9e841c5e2713a739abec51f3404d158348454cdcb7f5134b4e31ed51fd3f53"
sha256 cellar: :any, arm64_big_sur: "a2dc1f53bda46e711a62f252ed6090746e7ce92a56656945401bc7f291fe0433"
sha256 cellar: :any, ventura: "e98c021d5e43e40ca2f88fe5628da02408282b8e7cf0e7a2f0b6625c309b1433"
sha256 cellar: :any, monterey: "33abb9294868acf28859d95d45ba1c962423c1863bd52ae3d4e5f340bca1d733"
sha256 cellar: :any, big_sur: "614e1c3cb83710861357deae2bc3ec16eeac9b3a27387d6a1c366f1c24a218cc"
sha256 cellar: :any_skip_relocation, x86_64_linux: "c707815a1730c8e83bea251ca7d95f027bd5e8f4914ad17f84df268a4582272b"
end
head do
url "https://gitlab.gnome.org/GNOME/libxml2.git", branch: "master"
depends_on "autoconf" => :build
depends_on "automake" => :build
depends_on "libtool" => :build
depends_on "pkg-config" => :build
end
keg_only :provided_by_macos
depends_on "python@3.10" => [:build, :test]
depends_on "python@3.11" => [:build, :test]
depends_on "python@3.9" => [:build, :test]
depends_on "pkg-config" => :test
depends_on "icu4c"
depends_on "readline"
uses_from_macos "zlib"
# Fix crash when using Python 3 using Fedora's patch.
# Reported upstream:
# https://bugzilla.gnome.org/show_bug.cgi?id=789714
# https://gitlab.gnome.org/GNOME/libxml2/issues/12
patch do
url "https://bugzilla.opensuse.org/attachment.cgi?id=746044"
sha256 "37eb81a8ec6929eed1514e891bff2dd05b450bcf0c712153880c485b7366c17c"
end
def pythons
deps.map(&:to_formula)
.select { |f| f.name.match?(/^python@\d\.\d+$/) }
.map { |f| f.opt_libexec/"bin/python" }
end
def install
system "autoreconf", "--force", "--install", "--verbose" if build.head?
system "./configure", *std_configure_args,
"--disable-silent-rules",
"--with-history",
"--with-icu",
"--without-python",
"--without-lzma"
system "make", "install"
cd "python" do
sdk_include = if OS.mac?
sdk = MacOS.sdk_path_if_needed
sdk/"usr/include" if sdk
else
HOMEBREW_PREFIX/"include"
end
includes = [include, sdk_include].compact.map do |inc|
"'#{inc}',"
end.join(" ")
# We need to insert our include dir first
inreplace "setup.py", "includes_dir = [",
"includes_dir = [#{includes}"
pythons.each do |python|
system python, *Language::Python.setup_install_args(prefix, python)
end
end
end
test do
(testpath/"test.c").write <<~EOS
#include <libxml/tree.h>
int main()
{
xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
xmlNodePtr root_node = xmlNewNode(NULL, BAD_CAST "root");
xmlDocSetRootElement(doc, root_node);
xmlFreeDoc(doc);
return 0;
}
EOS
# Test build with xml2-config
args = shell_output("#{bin}/xml2-config --cflags --libs").split
system ENV.cc, "test.c", "-o", "test", *args
system "./test"
# Test build with pkg-config
ENV.append "PKG_CONFIG_PATH", lib/"pkgconfig"
args = shell_output("#{Formula["pkg-config"].opt_bin}/pkg-config --cflags --libs libxml-2.0").split
system ENV.cc, "test.c", "-o", "test", *args
system "./test"
pythons.each do |python|
with_env(PYTHONPATH: prefix/Language::Python.site_packages(python)) do
system python, "-c", "import libxml2"
end
end
end
end