homebrew-core/Formula/glib.rb

129 lines
4.5 KiB
Ruby

class Glib < Formula
include Language::Python::Shebang
desc "Core application library for C"
homepage "https://developer.gnome.org/glib/"
url "https://download.gnome.org/sources/glib/2.64/glib-2.64.5.tar.xz"
sha256 "9cbd5bd2715ead1c28d53c46f7b7b6ff6166f5887b772c1a9e3bf2910cfecc11"
license "LGPL-2.1-or-later"
livecheck do
url :stable
end
bottle do
sha256 "6d8c705b5feee37976530563cac6c959bd3a028e8b94fb7417c44f59eebe360f" => :catalina
sha256 "f20d990dd43d5732761adb780b9cf5a421a93337f81ddabdc9fc4a03f2f5537f" => :mojave
sha256 "e478a3f8bede892aa299589d722546dc0a94072f1f4b3d042a0a7f3400a5cade" => :high_sierra
end
depends_on "meson" => :build
depends_on "ninja" => :build
depends_on "pkg-config" => :build
depends_on "gettext"
depends_on "libffi"
depends_on "pcre"
depends_on "python@3.8"
on_linux do
depends_on "util-linux"
end
# https://bugzilla.gnome.org/show_bug.cgi?id=673135 Resolved as wontfix,
# but needed to fix an assumption about the location of the d-bus machine
# id file.
patch do
url "https://raw.githubusercontent.com/Homebrew/formula-patches/6164294a75541c278f3863b111791376caa3ad26/glib/hardcoded-paths.diff"
sha256 "a57fec9e85758896ff5ec1ad483050651b59b7b77e0217459ea650704b7d422b"
end
# Fixes a runtime error on ARM and PowerPC Macs.
# Can be removed in the next release.
# https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1566
patch do
url "https://gitlab.gnome.org/GNOME/glib/-/commit/c60d6599c9182ce44fdfaa8dde2955f55fc0d628.patch"
sha256 "9e3de41571edaa4bce03959abf885aad4edd069a622a5b642bf40294d748792e"
end
# Enables G_GNUC_FALLTHROUGH on clang.
# Necessary for pango to build on recent versions of clang.
# Will be in the next release.
patch do
url "https://gitlab.gnome.org/GNOME/glib/-/commit/5f38ae5ffca3213addc5b279a46d537792d031db.patch"
sha256 "12128966a693dd45d2e20286437aea13b1fe554aed0907cbc33131d3b76be890"
end
def install
inreplace %w[gio/gdbusprivate.c gio/xdgmime/xdgmime.c glib/gutils.c],
"@@HOMEBREW_PREFIX@@", HOMEBREW_PREFIX
# Disable dtrace; see https://trac.macports.org/ticket/30413
args = std_meson_args + %W[
-Diconv=auto
-Dgio_module_dir=#{HOMEBREW_PREFIX}/lib/gio/modules
-Dbsymbolic_functions=false
-Ddtrace=false
]
mkdir "build" do
system "meson", *args, ".."
system "ninja", "-v"
system "ninja", "install", "-v"
bin.find { |f| rewrite_shebang detected_python_shebang, f }
end
# ensure giomoduledir contains prefix, as this pkgconfig variable will be
# used by glib-networking and glib-openssl to determine where to install
# their modules
inreplace lib/"pkgconfig/gio-2.0.pc",
"giomoduledir=#{HOMEBREW_PREFIX}/lib/gio/modules",
"giomoduledir=${libdir}/gio/modules"
# `pkg-config --libs glib-2.0` includes -lintl, and gettext itself does not
# have a pkgconfig file, so we add gettext lib and include paths here.
gettext = Formula["gettext"].opt_prefix
inreplace lib+"pkgconfig/glib-2.0.pc" do |s|
s.gsub! "Libs: -L${libdir} -lglib-2.0 -lintl",
"Libs: -L${libdir} -lglib-2.0 -L#{gettext}/lib -lintl"
s.gsub! "Cflags: -I${includedir}/glib-2.0 -I${libdir}/glib-2.0/include",
"Cflags: -I${includedir}/glib-2.0 -I${libdir}/glib-2.0/include -I#{gettext}/include"
end
# `pkg-config --print-requires-private gobject-2.0` includes libffi,
# but that package is keg-only so it needs to look for the pkgconfig file
# in libffi's opt path.
libffi = Formula["libffi"].opt_prefix
inreplace lib+"pkgconfig/gobject-2.0.pc" do |s|
s.gsub! "Requires.private: libffi",
"Requires.private: #{libffi}/lib/pkgconfig/libffi.pc"
end
bash_completion.install Dir["gio/completion/*"]
end
def post_install
(HOMEBREW_PREFIX/"lib/gio/modules").mkpath
end
test do
(testpath/"test.c").write <<~EOS
#include <string.h>
#include <glib.h>
int main(void)
{
gchar *result_1, *result_2;
char *str = "string";
result_1 = g_convert(str, strlen(str), "ASCII", "UTF-8", NULL, NULL, NULL);
result_2 = g_convert(result_1, strlen(result_1), "UTF-8", "ASCII", NULL, NULL, NULL);
return (strcmp(str, result_2) == 0) ? 0 : 1;
}
EOS
system ENV.cc, "-o", "test", "test.c", "-I#{include}/glib-2.0",
"-I#{lib}/glib-2.0/include", "-L#{lib}", "-lglib-2.0"
system "./test"
end
end