forked from tnishinaga/homebrew-sigrok
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlibsigrok.rb
125 lines (110 loc) · 3.48 KB
/
libsigrok.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
class Libsigrok < Formula
desc "Drivers for logic analyzers and other supported devices"
homepage "https://sigrok.org/"
# libserialport is LGPL3+
license all_of: ["GPL-3.0-or-later", "LGPL-3.0-or-later"]
stable do
url "https://github.com/sigrokproject/libsigrok/archive/refs/tags/libsigrok-0.5.2.zip"
sha256 "9f3d4ae6023787f3c00ccb2a81d9b124474fc57286ff91037d8a33e6124129f3"
resource "libserialport" do
url "https://github.com/sigrokproject/libserialport/archive/refs/tags/libserialport-0.1.1.zip"
sha256 "e25b278676cfd6819d7e323af4caad2e38c30bc4352b6fa27496b251c351aba1"
end
end
livecheck do
url "https://sigrok.org/wiki/Downloads"
regex(/href=.*?libsigrok[._-]v?(\d+(?:\.\d+)+)\.t/i)
end
head do
url "https://github.com/sigrokproject/libsigrok.git", branch: "master"
resource "libserialport" do
url "https://github.com/sigrokproject/libserialport.git", 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 "[email protected]"
depends_on "hidapi"
depends_on "libftdi"
depends_on "libusb"
depends_on "libzip"
depends_on "nettle"
depends_on "numpy"
depends_on "pygobject3"
depends_on "[email protected]"
def python3
"python3.11"
end
def install
resource("libserialport").stage do
if build.head? || !File.exist?("configure")
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(python3)
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? || !File.exist?("configure")
system "./autogen.sh"
else
system "autoreconf", "--force", "--install", "--verbose"
end
mkdir "build" do
ENV["PYTHON"] = python3
ENV.prepend_path "PKG_CONFIG_PATH", lib/"pkgconfig"
args = %w[
--disable-java
--disable-ruby
--enable-bindings
--enable-cxx
]
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 python3, "-c", <<~EOS
import sigrok.core as sr
sr.Context.create()
EOS
end
end