homebrew-core/Formula/libsigrok.rb

160 lines
4.8 KiB
Ruby

class Libsigrok < Formula
desc "Drivers for logic analyzers and other supported devices"
homepage "https://sigrok.org/"
# libserialport is LGPL3+
# fw-fx2lafw is GPL-2.0-or-later and LGPL-2.1-or-later"
license all_of: ["GPL-3.0-or-later", "LGPL-3.0-or-later", "GPL-2.0-or-later", "LGPL-2.1-or-later"]
revision 2
stable do
url "https://sigrok.org/download/source/libsigrok/libsigrok-0.5.2.tar.gz"
sha256 "4d341f90b6220d3e8cb251dacf726c41165285612248f2c52d15df4590a1ce3c"
resource "libserialport" do
url "https://sigrok.org/download/source/libserialport/libserialport-0.1.1.tar.gz"
sha256 "4a2af9d9c3ff488e92fb75b4ba38b35bcf9b8a66df04773eba2a7bbf1fa7529d"
end
resource "fw-fx2lafw" do
url "https://sigrok.org/download/source/sigrok-firmware-fx2lafw/sigrok-firmware-fx2lafw-0.1.7.tar.gz"
sha256 "a3f440d6a852a46e2c5d199fc1c8e4dacd006bc04e0d5576298ee55d056ace3b"
end
end
livecheck do
url "https://sigrok.org/wiki/Downloads"
regex(/href=.*?libsigrok[._-]v?(\d+(?:\.\d+)+)\.t/i)
end
bottle do
sha256 arm64_monterey: "0059b4748c625a8e8590ac4bd27742f4a47c993040cc2751ba960b624adfafc8"
sha256 arm64_big_sur: "eca861528f8bc6206197610352453e8425654149605909f24629d53b06bd2a1c"
sha256 monterey: "5c03e75f006610869417865c7c806a16c185bb07fcc62c779f19bb13c55b31ad"
sha256 big_sur: "2f9c59d665ce7a58aa6a821f33ace35d2173f30f7fbfab05033928de8ab3625d"
sha256 catalina: "8ad76c73526a5b575d1c3e9cfea57d5bb50d16bfe1afb656d70bfa3255417634"
sha256 x86_64_linux: "23f156f296014fd03d2cb8f2ef7fc7bc302b135df2b1b91094b9889439946477"
end
head do
url "git://sigrok.org/libsigrok", branch: "master"
resource "libserialport" do
url "git://sigrok.org/libserialport", branch: "master"
end
resource "fw-fx2lafw" do
url "git://sigrok.org/sigrok-firmware-fx2lafw", branch: "master"
end
end
depends_on "autoconf" => :build
depends_on "autoconf-archive" => :build
depends_on "automake" => :build
depends_on "doxygen" => :build
depends_on "graphviz" => :build
depends_on "libtool" => :build
depends_on "pkg-config" => [:build, :test]
depends_on "sdcc" => :build
depends_on "swig" => :build
depends_on "glib"
depends_on "glibmm@2.66"
depends_on "hidapi"
depends_on "libftdi"
depends_on "libusb"
depends_on "libzip"
depends_on "nettle"
depends_on "numpy"
depends_on "pygobject3"
depends_on "python@3.10"
resource "fw-fx2lafw" do
url "https://sigrok.org/download/binary/sigrok-firmware-fx2lafw/sigrok-firmware-fx2lafw-bin-0.1.7.tar.gz"
sha256 "c876fd075549e7783a6d5bfc8d99a695cfc583ddbcea0217d8e3f9351d1723af"
end
def install
python = "python3.10"
resource("fw-fx2lafw").stage do
if build.head?
system "./autogen.sh"
else
system "autoreconf", "--force", "--install", "--verbose"
end
mkdir "build" do
system "../configure", *std_configure_args
system "make", "install"
end
end
resource("libserialport").stage do
if build.head?
system "./autogen.sh"
else
system "autoreconf", "--force", "--install", "--verbose"
end
mkdir "build" do
system "../configure", *std_configure_args
system "make", "install"
end
end
# We need to use the Makefile to generate all of the dependencies
# for setup.py, so the easiest way to make the Python libraries
# work is to adjust setup.py's arguments here.
prefix_site_packages = prefix/Language::Python.site_packages(python)
inreplace "Makefile.am" do |s|
s.gsub!(/^(setup_py =.*setup\.py .*)/, "\\1 --no-user-cfg")
s.gsub!(
/(\$\(setup_py\) install)/,
"\\1 --single-version-externally-managed --record=installed.txt --install-lib=#{prefix_site_packages}",
)
end
if build.head?
system "./autogen.sh"
else
system "autoreconf", "--force", "--install", "--verbose"
end
mkdir "build" do
ENV["PYTHON"] = python
ENV.prepend_path "PKG_CONFIG_PATH", lib/"pkgconfig"
args = %w[
--disable-java
--disable-ruby
]
system "../configure", *std_configure_args, *args
system "make"
system "make", "install"
end
end
test do
(testpath/"test.c").write <<~EOS
#include <libsigrok/libsigrok.h>
int main() {
struct sr_context *ctx;
if (sr_init(&ctx) != SR_OK) {
exit(EXIT_FAILURE);
}
if (sr_exit(ctx) != SR_OK) {
exit(EXIT_FAILURE);
}
return 0;
}
EOS
flags = shell_output("#{Formula["pkg-config"].opt_bin}/pkg-config --cflags --libs libsigrok").strip.split
system ENV.cc, "test.c", "-o", "test", *flags
system "./test"
system Formula["python@3.10"].opt_bin/"python3.10", "-c", <<~EOS
import sigrok.core as sr
sr.Context_create()
EOS
end
end