114 lines
4.0 KiB
Ruby
114 lines
4.0 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.70/glib-2.70.4.tar.xz"
|
|
sha256 "ab3d176f3115dcc4e5d02db795984e04e4f4b48d836252e23e8c468e9d423c33"
|
|
license "LGPL-2.1-or-later"
|
|
|
|
bottle do
|
|
sha256 arm64_monterey: "d6d450ed10ffc54d85d5be7b1029a3475ab5def492a657a68efaa6b4738b9489"
|
|
sha256 arm64_big_sur: "9b2c85257af95a8e161f1dcb8b7f97462d3c8ee9d7781df4535cab8a39ca5d98"
|
|
sha256 monterey: "8aaa25bb60faa33abaa815a75692e51269726eb899e16752ba7f50fe6a57611f"
|
|
sha256 big_sur: "90ca5b48db7baf9d5add465b0204be9d7941a753e2c0762213a85c864b3991c3"
|
|
sha256 catalina: "44a34119c03e1996edd239d969b7da1b7d229f1431bae79dfb690981df2ba28f"
|
|
sha256 x86_64_linux: "b6c62a984b0be44a85279d40157303c75ba8b9377854405c18fb351ebb3c13a2"
|
|
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.9"
|
|
|
|
on_linux do
|
|
depends_on "util-linux"
|
|
end
|
|
|
|
# replace several hardcoded paths with homebrew counterparts
|
|
patch do
|
|
url "https://raw.githubusercontent.com/Homebrew/formula-patches/43467fd8dfc0e8954892ecc08fab131242dca025/glib/hardcoded-paths.diff"
|
|
sha256 "d81c9e8296ec5b53b4ead6917f174b06026eeb0c671dfffc4965b2271fb6a82c"
|
|
end
|
|
|
|
def install
|
|
inreplace %w[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[
|
|
--default-library=both
|
|
--localstatedir=#{var}
|
|
-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"
|
|
rewrite_shebang detected_python_shebang, *bin.children
|
|
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"
|
|
|
|
if OS.mac?
|
|
# `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
|
|
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
|