homebrew-core/Formula/gnuradio.rb

222 lines
7.6 KiB
Ruby

class Gnuradio < Formula
include Language::Python::Virtualenv
desc "SDK for signal processing blocks to implement software radios"
homepage "https://gnuradio.org/"
url "https://github.com/gnuradio/gnuradio/archive/refs/tags/v3.9.2.0.tar.gz"
sha256 "d7271022559bfb486a9462ed5e7d1ffb52a010a197f5dfdef27f70a931907dce"
license "GPL-3.0-or-later"
revision 2
head "https://github.com/gnuradio/gnuradio.git"
livecheck do
url :stable
regex(/^v?(\d+(?:\.\d+)+)$/i)
end
bottle do
sha256 cellar: :any, big_sur: "169b966d6e031d0270bfc2649ee48220bc54b9d3e5d2b01c29e874bcc06f2c86"
sha256 cellar: :any, catalina: "d33ce40c50bd7b50545671e68b9b16c95f425196b6696fce1e77b2d6f12ab727"
sha256 cellar: :any, mojave: "6849a16834c277e9e72021fb2d70a1a7ebab2f0c6ce55eb7ce073f5c33d4421d"
end
depends_on "cmake" => :build
depends_on "doxygen" => :build
depends_on "pkg-config" => :build
depends_on "pybind11" => :build
depends_on "adwaita-icon-theme"
depends_on "boost"
depends_on "fftw"
depends_on "gmp"
depends_on "gsl"
depends_on "gtk+3"
depends_on "jack"
depends_on "log4cpp"
depends_on "numpy"
depends_on "portaudio"
depends_on "pygobject3"
depends_on "pyqt@5"
depends_on "python@3.9"
depends_on "qt@5"
depends_on "qwt"
depends_on "six"
depends_on "soapyrtlsdr"
depends_on "uhd"
depends_on "volk"
depends_on "zeromq"
resource "Cheetah3" do
url "https://files.pythonhosted.org/packages/ee/6f/29c6d74d8536dede06815eeaebfad53699e3f3df0fb22b7a9801a893b426/Cheetah3-3.2.6.tar.gz"
sha256 "f1c2b693cdcac2ded2823d363f8459ae785261e61c128d68464c8781dba0466b"
end
resource "click" do
url "https://files.pythonhosted.org/packages/21/83/308a74ca1104fe1e3197d31693a7a2db67c2d4e668f20f43a2fca491f9f7/click-8.0.1.tar.gz"
sha256 "8c04c11192119b1ef78ea049e0a6f0463e4c48ef00a30160c704337586f3ad7a"
end
resource "click-plugins" do
url "https://files.pythonhosted.org/packages/5f/1d/45434f64ed749540af821fd7e42b8e4d23ac04b1eda7c26613288d6cd8a8/click-plugins-1.1.1.tar.gz"
sha256 "46ab999744a9d831159c3411bb0c79346d94a444df9a3a3742e9ed63645f264b"
end
resource "Mako" do
url "https://files.pythonhosted.org/packages/5c/db/2d2d88b924aa4674a080aae83b59ea19d593250bfe5ed789947c21736785/Mako-1.1.4.tar.gz"
sha256 "17831f0b7087c313c0ffae2bcbbd3c1d5ba9eeac9c38f2eb7b50e8c99fe9d5ab"
end
resource "PyYAML" do
url "https://files.pythonhosted.org/packages/a0/a4/d63f2d7597e1a4b55aa3b4d6c5b029991d3b824b5bd331af8d4ab1ed687d/PyYAML-5.4.1.tar.gz"
sha256 "607774cbba28732bfa802b54baa7484215f530991055bb562efbed5b2f20a45e"
end
resource "cppzmq" do
url "https://raw.githubusercontent.com/zeromq/cppzmq/46fc0572c5e9f09a32a23d6f22fd79b841f77e00/zmq.hpp"
sha256 "964031c0944f913933f55ad1610938105a6657a69d1ac5a6dd50e16a679104d5"
end
def install
ENV.cxx11
ENV["XML_CATALOG_FILES"] = etc/"xml/catalog"
venv_root = libexec/"venv"
xy = Language::Python.major_minor_version "python3"
ENV.prepend_create_path "PYTHONPATH", "#{venv_root}/lib/python#{xy}/site-packages"
venv = virtualenv_create(venv_root, "python3")
%w[Mako Cheetah3 PyYAML click click-plugins].each do |r|
venv.pip_install resource(r)
end
# Avoid references to the Homebrew shims directory
inreplace "CMakeLists.txt" do |s|
s.gsub! "${CMAKE_C_COMPILER}", ENV.cc
s.gsub! "${CMAKE_CXX_COMPILER}", ENV.cxx
end
resource("cppzmq").stage include.to_s
args = std_cmake_args + %W[
-DGR_PKG_CONF_DIR=#{etc}/gnuradio/conf.d
-DGR_PREFSDIR=#{etc}/gnuradio/conf.d
-DENABLE_DEFAULT=OFF
-DPYTHON_EXECUTABLE=#{venv_root}/bin/python
-DPYTHON_VERSION_MAJOR=3
-DQWT_LIBRARIES=#{Formula["qwt"].lib}/qwt.framework/qwt
-DQWT_INCLUDE_DIRS=#{Formula["qwt"].lib}/qwt.framework/Headers
-DCMAKE_PREFIX_PATH=#{Formula["qt@5"].opt_lib}
-DQT_BINARY_DIR=#{Formula["qt@5"].opt_bin}
-DENABLE_TESTING=OFF
-DENABLE_INTERNAL_VOLK=OFF
]
enabled = %w[GNURADIO_RUNTIME GR_ANALOG GR_AUDIO GR_BLOCKS GRC
GR_CHANNELS GR_DIGITAL GR_DTV GR_FEC GR_FFT GR_FILTER
GR_MODTOOL GR_NETWORK GR_QTGUI GR_SOAPY GR_TRELLIS
GR_UHD GR_UTILS GR_VOCODER GR_WAVELET GR_ZEROMQ PYTHON VOLK]
enabled.each do |c|
args << "-DENABLE_#{c}=ON"
end
mkdir "build" do
system "cmake", "..", *args
system "make"
system "make", "install"
end
mv Dir[lib/"python#{xy}/dist-packages/*"], lib/"python#{xy}/site-packages/"
rm_rf lib/"python#{xy}/dist-packages"
# Create a directory for Homebrew to put .pth files pointing to GNU Radio
# plugins installed by other packages. An automatically-loaded module adds
# this directory to the package search path.
plugin_pth_dir = etc/"gnuradio/plugins.d"
mkdir plugin_pth_dir
site_packages = lib/"python#{xy}/site-packages"
venv_site_packages = venv_root/"lib/python#{xy}/site-packages"
(venv_site_packages/"homebrew_gr_plugins.py").write <<~EOS
import site
site.addsitedir("#{plugin_pth_dir}")
EOS
pth_contents = "#{site_packages}\nimport homebrew_gr_plugins\n"
(venv_site_packages/"homebrew-gnuradio.pth").write pth_contents
# Patch the grc config to change the search directory for blocks
inreplace etc/"gnuradio/conf.d/grc.conf" do |s|
s.gsub! share.to_s, "#{HOMEBREW_PREFIX}/share"
end
rm bin.children.reject(&:executable?)
end
test do
assert_match version.to_s, shell_output("#{bin}/gnuradio-config-info -v")
(testpath/"test.c++").write <<~EOS
#include <gnuradio/top_block.h>
#include <gnuradio/blocks/null_source.h>
#include <gnuradio/blocks/null_sink.h>
#include <gnuradio/blocks/head.h>
#include <gnuradio/gr_complex.h>
class top_block : public gr::top_block {
public:
top_block();
private:
gr::blocks::null_source::sptr null_source;
gr::blocks::null_sink::sptr null_sink;
gr::blocks::head::sptr head;
};
top_block::top_block() : gr::top_block("Top block") {
long s = sizeof(gr_complex);
null_source = gr::blocks::null_source::make(s);
null_sink = gr::blocks::null_sink::make(s);
head = gr::blocks::head::make(s, 1024);
connect(null_source, 0, head, 0);
connect(head, 0, null_sink, 0);
}
int main(int argc, char **argv) {
top_block top;
top.run();
}
EOS
system ENV.cxx, "-std=c++11", "-L#{lib}", "-L#{Formula["boost"].opt_lib}",
"-lgnuradio-blocks", "-lgnuradio-runtime", "-lgnuradio-pmt",
"-lboost_system", "-L#{Formula["log4cpp"].opt_lib}", "-llog4cpp",
testpath/"test.c++", "-o", testpath/"test"
system "./test"
(testpath/"test.py").write <<~EOS
from gnuradio import blocks
from gnuradio import gr
class top_block(gr.top_block):
def __init__(self):
gr.top_block.__init__(self, "Top Block")
self.samp_rate = 32000
s = gr.sizeof_gr_complex
self.blocks_null_source_0 = blocks.null_source(s)
self.blocks_null_sink_0 = blocks.null_sink(s)
self.blocks_head_0 = blocks.head(s, 1024)
self.connect((self.blocks_head_0, 0),
(self.blocks_null_sink_0, 0))
self.connect((self.blocks_null_source_0, 0),
(self.blocks_head_0, 0))
def main(top_block_cls=top_block, options=None):
tb = top_block_cls()
tb.start()
tb.wait()
main()
EOS
system Formula["python@3.9"].opt_bin/"python3", testpath/"test.py"
end
end