Implements ticket:401 and ticket:402.
authorjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Sat, 11 Jul 2009 02:34:31 +0000 (02:34 +0000)
committerjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Sat, 11 Jul 2009 02:34:31 +0000 (02:34 +0000)
Adds several API functions to determine build constants at runtime, and
a convenience command line program to display them:

From C++:

const std::string gr_prefix();
const std::string gr_sysconfdir();
const std::string gr_prefsdir();
const std::string gr_build_date();
const std::string gr_svn_date();
const std::string gr_svn_version();
const std::string gr_version();

From Python:

gr.prefix()
gr.sysconfdir()
gr.prefsdir()
gr.build_date()
gr.svn_date()
gr.svn_version()
gr.version()

The new binary is 'gnuradio' and installed on the path:

$ gnuradio
Program options: gnuradio [options]:
  -h [ --help ]         print help message
  --prefix              print gnuradio installation prefix
  --sysconfdir          print gnuradio system configuration directory
  --prefsdir            print gnuradio preferences directory
  --builddate           print gnuradio build date (RFC2822 format)
  -v [ --version ]      print gnuradio version
  --svnversion          print SVN repository version (SVN format)
  --svndate             print SVN repository date
$

git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11418 221aa14e-8319-0410-a670-987f0aec2ac5

21 files changed:
Makefile.common
config/grc_gnuradio_core.m4
configure.ac
gnuradio-core/Makefile.am
gnuradio-core/src/lib/Makefile.am
gnuradio-core/src/lib/general/Makefile.am
gnuradio-core/src/lib/general/general.i
gnuradio-core/src/lib/general/gr_constants.cc.in [new file with mode: 0644]
gnuradio-core/src/lib/general/gr_constants.h [new file with mode: 0644]
gnuradio-core/src/lib/general/gr_constants.i [new file with mode: 0644]
gnuradio-core/src/lib/general/gr_prefix.cc.in [deleted file]
gnuradio-core/src/lib/general/gr_prefix.h [deleted file]
gnuradio-core/src/lib/general/gr_prefix.i [deleted file]
gnuradio-core/src/lib/gnuradio.cc [new file with mode: 0644]
gnuradio-core/src/python/gnuradio/gr/prefs.py
gr-audio-alsa/Makefile.am
gr-audio-jack/Makefile.am
gr-audio-oss/Makefile.am
gr-audio-portaudio/Makefile.am
gr-wxgui/Makefile.am
grc/Makefile.am

index 14cbe26928141d7f40195f6ca32e59d8a1634944..138045353c109c7a2752b385cf88974867ddcf88 100644 (file)
@@ -115,7 +115,7 @@ docdir ?= $(datadir)/doc/$(PACKAGE)
 gr_docdir = $(docdir)-$(VERSION)
 
 # System configuration files
-gr_sysconfdir = $(sysconfdir)/$(PACKAGE)/conf.d
+gr_prefsdir = $(GR_PREFSDIR)
 
 # Other common defines; use "+=" to add to these
 STAMPS =
index a1724aea9de5ce53ec76d0ea2a248d78abd1af80..3e4cbdf4fcaa0831e4af5487785192f616fd9156 100644 (file)
@@ -86,7 +86,7 @@ AC_DEFUN([GRC_GNURADIO_CORE],[
         gnuradio-core/src/lib/filter/Makefile \
         gnuradio-core/src/lib/g72x/Makefile \
         gnuradio-core/src/lib/general/Makefile \
-        gnuradio-core/src/lib/general/gr_prefix.cc \
+        gnuradio-core/src/lib/general/gr_constants.cc \
         gnuradio-core/src/lib/gengen/Makefile \
         gnuradio-core/src/lib/io/Makefile \
         gnuradio-core/src/lib/missing/Makefile \
index 548cfdb13d706ead48d106d4ae2506bc64bb6a53..92de3e95ef090e85d698534c2bc76b631d64653a 100644 (file)
@@ -26,7 +26,10 @@ AC_CANONICAL_BUILD
 AC_CANONICAL_HOST
 AC_CANONICAL_TARGET
 
-AM_INIT_AUTOMAKE(gnuradio,3.3svn)
+
+VERSION=3.3svn
+AC_SUBST(VERSION)
+AM_INIT_AUTOMAKE(gnuradio,$VERSION)
 
 DEFINES=""
 AC_SUBST(DEFINES)
@@ -286,9 +289,25 @@ dnl AX_BOOST_WSERIALIZATION
 
 dnl If this is being done from a subversion tree, create variables
 GR_SUBVERSION
-BUILD_DATE=`date -R`
+BUILD_DATE=`date -R -u`
 AC_SUBST(BUILD_DATE)
 
+dnl SYSCONFDIR substitution
+if test "${sysconfdir}" == "\${prefix}/etc" ; then
+   if test "${prefix}" == "NONE" ; then
+      SYSCONFDIR=["$ac_default_prefix/etc"]
+   else
+      SYSCONFDIR=["${prefix}/etc"]
+   fi
+else
+   SYSCONFDIR=[${sysconfdir}]
+fi
+AC_SUBST(SYSCONFDIR)
+
+dnl System configuration files
+GR_PREFSDIR=[$SYSCONFDIR/${PACKAGE}/conf.d]
+AC_SUBST(GR_PREFSDIR)
+
 dnl Component specific configuration
 dnl The order of the GR_ macros determines the order of compilation
 dnl For -any- checks on $enable_all_components
index d5447c17a44e2aef905a4a18a25bb956df3eadba..107ff785b1fa47035e2b8965559d95edcd16c1d0 100644 (file)
@@ -29,5 +29,5 @@ SUBDIRS = src
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = gnuradio-core.pc
 
-etcdir = $(gr_sysconfdir)
+etcdir = $(gr_prefsdir)
 dist_etc_DATA = gnuradio-core.conf
index ef2b17f5ab44ac1dd5e0755a61f67c58bd917c8f..8b2dc82ccc35dc8e1ab907147d81796c01b4394a 100644 (file)
@@ -29,6 +29,8 @@ if PYTHON
 SUBDIRS += swig
 endif
 
+AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(WITH_INCLUDES)
+
 # generate libgnuradio-core.la from the convenience libraries in subdirs
 
 lib_LTLIBRARIES = libgnuradio-core.la libgnuradio-core-qa.la
@@ -64,3 +66,7 @@ libgnuradio_core_qa_la_LIBADD  =      \
        runtime/libruntime-qa.la        \
        libgnuradio-core.la             \
        $(CPPUNIT_LIBS)                 
+
+bin_PROGRAMS = gnuradio
+gnuradio_SOURCES = gnuradio.cc
+gnuradio_LDADD = libgnuradio-core.la $(BOOST_PROGRAM_OPTIONS_LIB)
index 5564ee3d4cd1ed71c1a0eef5ed157cf37beb91ce..9b070b8651487d85be89d015e2facf39662821e4 100644 (file)
@@ -31,7 +31,7 @@ BUILT_SOURCES =
 
 EXTRA_DIST =                           \
        gen_sine_table.py               \
-       gr_prefix.cc.in                 
+       gr_constants.cc.in                      
 
 libgeneral_la_SOURCES =                \
        gr_agc_cc.cc                    \
@@ -117,7 +117,7 @@ libgeneral_la_SOURCES =             \
        gr_pll_freqdet_cf.cc            \
        gr_pll_refout_cc.cc             \
        gr_pn_correlator_cc.cc          \
-       gr_prefix.cc                    \
+       gr_constants.cc                 \
        gr_prefs.cc                     \
        gr_probe_avg_mag_sqrd_c.cc      \
        gr_probe_avg_mag_sqrd_cf.cc     \
@@ -273,7 +273,7 @@ grinclude_HEADERS =                         \
        gr_pll_freqdet_cf.h             \
        gr_pll_refout_cc.h              \
        gr_pn_correlator_cc.h           \
-       gr_prefix.h                     \
+       gr_constants.h                  \
        gr_prefs.h                      \
        gr_probe_avg_mag_sqrd_c.h       \
        gr_probe_avg_mag_sqrd_cf.h      \
@@ -432,7 +432,7 @@ swiginclude_HEADERS =                       \
        gr_pll_freqdet_cf.i             \
        gr_pll_refout_cc.i              \
        gr_pn_correlator_cc.i           \
-       gr_prefix.i                     \
+       gr_constants.i                  \
        gr_prefs.i                      \
        gr_probe_avg_mag_sqrd_c.i       \
        gr_probe_avg_mag_sqrd_cf.i      \
index 0cb54870efc46627b68756b27e7341d98e5ff8fe..0684e63a55f7ae56d05a04d13a5d5b8f00a3915f 100644 (file)
 #include <gr_pa_2x2_phase_combiner.h>
 #include <gr_kludge_copy.h>
 #include <gr_prefs.h>
-#include <gr_prefix.h>
+#include <gr_constants.h>
 #include <gr_test_types.h>
 #include <gr_test.h>
 #include <gr_unpack_k_bits_bb.h>
 %include "gr_pa_2x2_phase_combiner.i"
 %include "gr_kludge_copy.i"
 %include "gr_prefs.i"
-%include "gr_prefix.i"
+%include "gr_constants.i"
 %include "gr_test_types.h"
 %include "gr_test.i"
 %include "gr_unpack_k_bits_bb.i"
diff --git a/gnuradio-core/src/lib/general/gr_constants.cc.in b/gnuradio-core/src/lib/general/gr_constants.cc.in
new file mode 100644 (file)
index 0000000..efb0f1c
--- /dev/null
@@ -0,0 +1,69 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006,2009 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gr_constants.h>
+
+const std::string
+gr_prefix()
+{
+  return "@prefix@";
+}
+
+const std::string
+gr_sysconfdir()
+{
+  return "@SYSCONFDIR@";
+}
+
+const std::string
+gr_prefsdir()
+{
+  return "@GR_PREFSDIR@";
+}
+
+const std::string
+gr_build_date()
+{
+  return "@BUILD_DATE@";
+}
+
+const std::string
+gr_svn_date()
+{
+  return "@SVNDATE@";
+}
+
+const std::string
+gr_svn_version()
+{
+  return "@SVNVERSION@";
+}
+
+const std::string
+gr_version()
+{
+  return "@VERSION@";
+}
diff --git a/gnuradio-core/src/lib/general/gr_constants.h b/gnuradio-core/src/lib/general/gr_constants.h
new file mode 100644 (file)
index 0000000..e44890b
--- /dev/null
@@ -0,0 +1,62 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006,2009 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+#ifndef INCLUDED_GR_CONSTANTS_H
+#define INCLUDED_GR_CONSTANTS_H
+
+#include <string>
+
+/*!
+ * \brief return ./configure --prefix argument.  Typically /usr/local
+ */
+const std::string gr_prefix();
+
+/*!
+ * \brief return ./configure --sysconfdir argument.  Typically $prefix/etc or /etc
+ */
+const std::string gr_sysconfdir();
+
+/*!
+ * \brief return preferences file directory.  Typically $sysconfdir/etc/conf.d
+ */
+const std::string gr_prefsdir();
+
+/*!
+ * \brief return date/time of build, as set when 'bootstrap' is run
+ */
+const std::string gr_build_date();
+
+/*!
+ * \brief return repository date as set when 'bootstrap' is run
+ */
+const std::string gr_svn_date();
+
+/*!
+ * \brief return repository version as set when 'bootstrap' is run
+ */
+const std::string gr_svn_version();
+
+/*!
+ * \brief return version string defined in configure.ac
+ */
+const std::string gr_version();
+
+#endif /* INCLUDED_GR_CONSTANTS_H */
diff --git a/gnuradio-core/src/lib/general/gr_constants.i b/gnuradio-core/src/lib/general/gr_constants.i
new file mode 100644 (file)
index 0000000..156af4a
--- /dev/null
@@ -0,0 +1,17 @@
+/* -*- c++ -*- */
+
+%rename(prefix) gr_prefix;
+%rename(sysconfdir) gr_sysconfdir;
+%rename(prefsdir) gr_prefsdir;
+%rename(build_date) gr_build_date;
+%rename(svn_date) gr_svn_date;
+%rename(svn_version) gr_svn_version;
+%rename(version) gr_version;
+
+const std::string gr_prefix();
+const std::string gr_sysconfdir();
+const std::string gr_prefsdir();
+const std::string gr_build_date();
+const std::string gr_svn_date();
+const std::string gr_svn_version();
+const std::string gr_version();
diff --git a/gnuradio-core/src/lib/general/gr_prefix.cc.in b/gnuradio-core/src/lib/general/gr_prefix.cc.in
deleted file mode 100644 (file)
index f03043c..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2006 Free Software Foundation, Inc.
- * 
- * This file is part of GNU Radio
- * 
- * GNU Radio is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3, or (at your option)
- * any later version.
- * 
- * GNU Radio is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with GNU Radio; see the file COPYING.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street,
- * Boston, MA 02110-1301, USA.
- */
-
-#include <gr_prefix.h>
-
-const std::string
-gr_prefix()
-{
-  return "@prefix@";
-}
diff --git a/gnuradio-core/src/lib/general/gr_prefix.h b/gnuradio-core/src/lib/general/gr_prefix.h
deleted file mode 100644 (file)
index 0a107b9..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2006 Free Software Foundation, Inc.
- * 
- * This file is part of GNU Radio
- * 
- * GNU Radio is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3, or (at your option)
- * any later version.
- * 
- * GNU Radio is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with GNU Radio; see the file COPYING.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street,
- * Boston, MA 02110-1301, USA.
- */
-#ifndef INCLUDED_GR_PREFIX_H
-#define INCLUDED_GR_PREFIX_H
-
-#include <string>
-
-/*!
- * \brief return ./configure --prefix argument.  Typically /usr/local
- */
-const std::string gr_prefix();
-
-
-#endif /* INCLUDED_GR_PREFIX_H */
diff --git a/gnuradio-core/src/lib/general/gr_prefix.i b/gnuradio-core/src/lib/general/gr_prefix.i
deleted file mode 100644 (file)
index 04e1899..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-/* -*- c++ -*- */
-
-%rename(prefix) gr_prefix;
-
-const std::string gr_prefix();
diff --git a/gnuradio-core/src/lib/gnuradio.cc b/gnuradio-core/src/lib/gnuradio.cc
new file mode 100644 (file)
index 0000000..df78ea2
--- /dev/null
@@ -0,0 +1,80 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gr_constants.h>
+#include <boost/program_options.hpp>
+#include <iostream>
+
+namespace po = boost::program_options;
+
+int
+main(int argc, char **argv)
+{
+  po::options_description desc("Program options: gnuradio [options]");
+  po::variables_map vm;
+
+  desc.add_options()
+    ("help,h", "print help message")
+    ("prefix", "print gnuradio installation prefix")
+    ("sysconfdir", "print gnuradio system configuration directory")
+    ("prefsdir", "print gnuradio preferences directory")
+    ("builddate", "print gnuradio build date (RFC2822 format)")
+    ("version,v", "print gnuradio version")
+    ("svnversion", "print SVN repository version (SVN format)")
+    ("svndate", "print SVN repository date")
+    ;
+
+  po::store(po::parse_command_line(argc, argv, desc), vm);
+  po::notify(vm);
+
+  if (vm.size() == 0 || vm.count("help")) {
+    std::cout << desc << std::endl;
+    return 1;
+  }
+      
+  if (vm.count("prefix"))
+    std::cout << gr_prefix() << std::endl;
+
+  if (vm.count("sysconfdir"))
+    std::cout << gr_sysconfdir() << std::endl;
+
+  if (vm.count("prefsdir"))
+    std::cout << gr_prefsdir() << std::endl;
+
+  if (vm.count("builddate"))
+    std::cout << gr_build_date() << std::endl;
+
+  if (vm.count("version"))
+    std::cout << gr_version() << std::endl;
+
+  if (vm.count("svnversion"))
+    std::cout << gr_svn_version() << std::endl;
+
+  if (vm.count("svndate"))
+    std::cout << gr_svn_date() << std::endl;
+
+  return 0;
+}
index 52f1ff64a6637b2b55014b251f9e68fe4b65e40f..9b31b772b3f4fb72c05905326a8078662180c2b8 100644 (file)
@@ -33,7 +33,7 @@ def _user_prefs_filename():
     return os.path.expanduser('~/.gnuradio/config.conf')
         
 def _sys_prefs_dirname():
-    return os.path.join(gsp.prefix(), 'etc/gnuradio/conf.d')
+    return gsp.prefsdir()
 
 def _bool(x):
     """
index 443bc32108513c03a5f46b81824499090bd5c31c..5bd92b0ff7595866b89a7d7c5e3d7891c5077e9c 100644 (file)
@@ -26,5 +26,5 @@ SUBDIRS = src
 pkgconfigdir = $(libdir)/pkgconfig
 dist_pkgconfig_DATA = gnuradio-audio-alsa.pc
 
-etcdir = $(gr_sysconfdir)
+etcdir = $(gr_prefsdir)
 dist_etc_DATA = gr-audio-alsa.conf
index 99cfe844777e8d35458d5e0941b5a98d19b6e625..cdc1433db6f29404cc3fbc56cdfdcd743162b891 100644 (file)
@@ -26,5 +26,5 @@ SUBDIRS = src
 pkgconfigdir = $(libdir)/pkgconfig
 dist_pkgconfig_DATA = gnuradio-audio-jack.pc
 
-etcdir = $(gr_sysconfdir)
+etcdir = $(gr_prefsdir)
 dist_etc_DATA = gr-audio-jack.conf
index 9f460bc3a8c4c2103f907f8873a1703b3a183cb4..c55d3ecb716643d8edd3b58d8a92be5ceb3ecea7 100644 (file)
@@ -26,5 +26,5 @@ SUBDIRS = src
 pkgconfigdir = $(libdir)/pkgconfig
 dist_pkgconfig_DATA = gnuradio-audio-oss.pc
 
-etcdir = $(gr_sysconfdir)
+etcdir = $(gr_prefsdir)
 dist_etc_DATA = gr-audio-oss.conf
index 8be2fa7346c208d9a8dd62e17f3fc7fea2293863..198d89f87932352e68dcaeeb084fc5302dc65ea8 100644 (file)
@@ -26,5 +26,5 @@ SUBDIRS = src
 pkgconfigdir = $(libdir)/pkgconfig
 dist_pkgconfig_DATA = gnuradio-audio-portaudio.pc
 
-etcdir = $(gr_sysconfdir)
+etcdir = $(gr_prefsdir)
 dist_etc_DATA = gr-audio-portaudio.conf
index e35ac649768cf87c012d3bbe8d5a9b7e2bed9e8d..335ebe43f8f8d06c72498b5924688c1cb10644fd 100644 (file)
@@ -29,7 +29,7 @@ EXTRA_DIST = \
 if PYTHON
 SUBDIRS = src
 
-etcdir = $(gr_sysconfdir)
+etcdir = $(gr_prefsdir)
 dist_etc_DATA = gr-wxgui.conf
 
 pkgconfigdir = $(libdir)/pkgconfig
index a921fdd35a5580e75c22fb714e51e0d6ce25ba31..4ffdee0b42150eb6d0ac5456a65ef186b2a0a8b5 100644 (file)
@@ -39,7 +39,7 @@ endif
 ourpythondir = $(grc_src_prefix)
 ourpython_PYTHON = __init__.py
 
-etcdir = $(gr_sysconfdir)
+etcdir = $(gr_prefsdir)
 dist_etc_DATA = grc.conf
 
 EXTRA_DIST = \