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/releases/download/v3.8.2.0/gnuradio-3.8.2.0.tar.gz" sha256 "3e293541a9ac8d78660762bae8b80c0f6195b3494e1c50c01a9fd79cc60bb624" license "GPL-3.0-or-later" head "https://github.com/gnuradio/gnuradio.git" bottle do sha256 "98259eec9c9f48ad0ab56f4a7df7846e317e14c59b265602323a0d40537d7c2d" => :catalina sha256 "42981d961cd48b0b4895bcf7d413117eaba87a26af936ada2f080ef39abfb496" => :mojave sha256 "01562ab671d875971f0e18b77a4610e5e11edb5d9004331fb466c7aba86e2248" => :high_sierra end depends_on "cmake" => :build depends_on "doxygen" => :build depends_on "pkg-config" => :build depends_on "swig" => :build depends_on "boost" depends_on "fftw" depends_on "gmp" depends_on "gsl" depends_on "gtk+3" depends_on "log4cpp" depends_on "numpy" depends_on "portaudio" depends_on "pygobject3" depends_on "pyqt" depends_on "python@3.8" depends_on "qt" depends_on "qwt" depends_on "uhd" depends_on "volk" depends_on "zeromq" resource "Cheetah" do url "https://files.pythonhosted.org/packages/50/d5/34b30f650e889d0d48e6ea9337f7dcd6045c828b9abaac71da26b6bdc543/Cheetah3-3.2.5.tar.gz" sha256 "ececc9ca7c58b9a86ce71eb95594c4619949e2a058d2a1af74c7ae8222515eb1" end resource "click" do url "https://files.pythonhosted.org/packages/27/6f/be940c8b1f1d69daceeb0032fee6c34d7bd70e3e649ccac0951500b4720e/click-7.1.2.tar.gz" sha256 "d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a" 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/72/89/402d2b4589e120ca76a6aed8fee906a0f5ae204b50e455edd36eda6e778d/Mako-1.1.3.tar.gz" sha256 "8195c8c1400ceb53496064314c6736719c6f25e7479cd24c77be3d9361cddc27" end resource "six" do url "https://files.pythonhosted.org/packages/6b/34/415834bfdafca3c5f451532e8a8d9ba89a21c9743a0c59fbd0205c7f9426/six-1.15.0.tar.gz" sha256 "30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259" end resource "PyYAML" do url "https://files.pythonhosted.org/packages/64/c2/b80047c7ac2478f9501676c988a5411ed5572f35d1beff9cae07d321512c/PyYAML-5.3.1.tar.gz" sha256 "b8eac752c5e14d3eca0e6dd9199cd627518cb5ec06add0de9d32baeee6fe645d" end resource "cppzmq" do url "https://raw.githubusercontent.com/zeromq/cppzmq/46fc0572c5e9f09a32a23d6f22fd79b841f77e00/zmq.hpp" sha256 "964031c0944f913933f55ad1610938105a6657a69d1ac5a6dd50e16a679104d5" end # patch for boost 1.73.0, remove after next release # https://github.com/gnuradio/gnuradio/pull/3566 patch do url "https://raw.githubusercontent.com/Homebrew/formula-patches/0d2af1812716a874d1e49268e999ea1a8ca9fc3c/gnuradio/boost-1.73.0.patch" sha256 "7e4abd08210d242d65807b7e2419f163a58b4630027a3beaff0e325d044266d7" end # Add -undefined dynamic_lookup linker flag back for macOS # https://github.com/gnuradio/gnuradio/pull/3674 patch do url "https://github.com/gnuradio/gnuradio/commit/80ba62cb11cf604495e87a5e302e68eaf441eea9.patch?full_index=1" sha256 "d12640f62b266b244950d84f2deb1544f41574229106a525e693159fb3fc80eb" end def install ENV.cxx11 ENV.prepend_path "PATH", Formula["qt"].opt_bin.to_s 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 six Cheetah 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"].opt_lib} -DQT_BINARY_DIR=#{Formula["qt"].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_QTGUI 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" site_packages = lib/"python#{xy}/site-packages" pth_contents = "import site; site.addsitedir('#{site_packages}')\n" (venv_root/"lib/python#{xy}/site-packages/homebrew-gnuradio.pth").write pth_contents 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 #include #include #include #include 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 "python3", testpath/"test.py" end end