From 999c0e723240ee783bca17942f77a9d05bbfc168 Mon Sep 17 00:00:00 2001
From: Josh Morman <mormjb@gmail.com>
Date: Thu, 23 Apr 2020 15:03:55 -0400
Subject: utils: add functionality to generate bindings

This currently exists in two places
1) Bindtool (longevity TBD) which calls blocktool to parse the public
header file in the include directory
2) Modtool - binding of headers added to add and bind.  rm, update,
info, etc still TODO
---
 gr-utils/bindtool/scripts/bind_gr_module.py | 60 +++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
 create mode 100644 gr-utils/bindtool/scripts/bind_gr_module.py

(limited to 'gr-utils/bindtool/scripts/bind_gr_module.py')

diff --git a/gr-utils/bindtool/scripts/bind_gr_module.py b/gr-utils/bindtool/scripts/bind_gr_module.py
new file mode 100644
index 0000000000..5b3c691461
--- /dev/null
+++ b/gr-utils/bindtool/scripts/bind_gr_module.py
@@ -0,0 +1,60 @@
+import argparse
+import os
+from gnuradio.bindtool import BindingGenerator
+import pathlib
+
+parser = argparse.ArgumentParser(description='Bind a GR In-Tree Module')
+parser.add_argument('names', type=str, nargs='+',
+                    help='Names of gr modules to bind (e.g. fft digital analog)')
+
+parser.add_argument('--output_dir', default='/tmp',
+                    help='Output directory of generated bindings')
+parser.add_argument('--prefix', help='Prefix of Installed GNU Radio')
+parser.add_argument('--src', help='Directory of gnuradio source tree',
+                    default=os.path.dirname(os.path.abspath(__file__))+'/../../..')
+parser.add_argument(
+    '--include', help='Additional Include Dirs, comma separated', default='')
+args = parser.parse_args()
+
+# NOTES:
+# To generate QTGUI requires adding the QT headers as --include, e.g.
+# bind_gr_module.py --prefix /share/gnuradio/grpybind --output_dir /share/tmp/take5
+#   --include /usr/include/x86_64-linux-gnu/qt5/QtGui,/usr/include/x86_64-linux-gnu/qt5,
+#   /usr/include/x86_64-linux-gnu/qt5/QtCore,/usr/include/x86_64-linux-gnu/qt5/QtWidgets,/usr/include/qwt qtgui
+
+# To generate UHD requires adding the UHD headers, e.g.
+# python3 /share/gnuradio/grpybind/src/gnuradio/gr-utils/python/bindtool/scripts/bind_gr_module.py 
+#   --prefix /share/gnuradio/grpybind 
+#   --include $UHD_PATH,$UHD_PATH/utils,$UHD_PATH/types,$UHD_PATH/transport,$UHD_PATH/usrp_clock,$UHD_PATH/rfnoc 
+#   --output_dir /share/tmp/take5 uhd
+
+
+print(pathlib.Path(__file__).parent.absolute())
+print(args)
+
+prefix = args.prefix
+output_dir = args.output_dir
+includes = args.include
+for name in args.names:
+    if name not in ['gr', 'pmt']:
+        namespace = ['gr', name]
+        module_dir = os.path.abspath(
+            os.path.join(args.src, 'gr-'+name, 'include'))
+        prefix_include_root = 'gnuradio/'+name  # pmt, gnuradio/digital, etc.
+    else:
+        namespace = [name]
+        module_dir = os.path.abspath(os.path.join(
+            args.src, 'gnuradio-runtime', 'include'))
+        if name == 'gr':
+            prefix_include_root = 'gnuradio'
+            module_dir = os.path.join(module_dir, 'gnuradio')
+        elif name == 'pmt':
+            prefix_include_root = 'pmt'
+            module_dir = os.path.join(module_dir, 'pmt')
+
+    import warnings
+    with warnings.catch_warnings():
+        warnings.filterwarnings("ignore", category=DeprecationWarning)
+        bg = BindingGenerator(prefix, namespace, prefix_include_root,
+                              output_dir, addl_includes=includes, match_include_structure=True)
+        bg.gen_bindings(module_dir)
-- 
cgit v1.2.3


From 7842e287b56950ea95e7f1961992b6e2d38ca27f Mon Sep 17 00:00:00 2001
From: Josh Morman <mormjb@gmail.com>
Date: Mon, 1 Jun 2020 13:42:05 -0400
Subject: pybind11: update binding generation scripts

---
 cmake/Modules/GrPybind.cmake                | 4 ++++
 gr-utils/bindtool/scripts/bind_gr_module.py | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

(limited to 'gr-utils/bindtool/scripts/bind_gr_module.py')

diff --git a/cmake/Modules/GrPybind.cmake b/cmake/Modules/GrPybind.cmake
index 4f9fee6eba..5486296a36 100644
--- a/cmake/Modules/GrPybind.cmake
+++ b/cmake/Modules/GrPybind.cmake
@@ -119,6 +119,10 @@ SET(MODULE_NAME ${name})
 if (${name} STREQUAL gr)
     SET(MODULE_NAME "runtime")
 endif()
+if (${name} STREQUAL video_sdl)
+    SET(MODULE_NAME "video-sdl")
+endif()
+
 
 if(ENABLE_DOXYGEN)
     add_custom_command( 
diff --git a/gr-utils/bindtool/scripts/bind_gr_module.py b/gr-utils/bindtool/scripts/bind_gr_module.py
index 5b3c691461..271ce62765 100644
--- a/gr-utils/bindtool/scripts/bind_gr_module.py
+++ b/gr-utils/bindtool/scripts/bind_gr_module.py
@@ -37,7 +37,7 @@ output_dir = args.output_dir
 includes = args.include
 for name in args.names:
     if name not in ['gr', 'pmt']:
-        namespace = ['gr', name]
+        namespace = ['gr', name.replace("-","_")]
         module_dir = os.path.abspath(
             os.path.join(args.src, 'gr-'+name, 'include'))
         prefix_include_root = 'gnuradio/'+name  # pmt, gnuradio/digital, etc.
@@ -56,5 +56,5 @@ for name in args.names:
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore", category=DeprecationWarning)
         bg = BindingGenerator(prefix, namespace, prefix_include_root,
-                              output_dir, addl_includes=includes, match_include_structure=True)
+                              output_dir, addl_includes=includes, match_include_structure=True, write_json_output=True)
         bg.gen_bindings(module_dir)
-- 
cgit v1.2.3