build+core: Add printing of version number in daemons and tools

This commit also changes how version number is handled.  Version is now
fully controlled from top-level wscript.  In addition to that, a new
NFD_VERSION_BUILD_STRING macro is set to include more detailed
information, including commit ID (e.g., "0.1.0-rc1-1-g5c86570").

Change-Id: I448eb627e0c42dc814de1107cf7bb0dc94fa2a89
Refs: #1575
diff --git a/tools/ndn-autoconfig.cpp b/tools/ndn-autoconfig.cpp
index 84a73d3..fe8ce19 100644
--- a/tools/ndn-autoconfig.cpp
+++ b/tools/ndn-autoconfig.cpp
@@ -22,6 +22,8 @@
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  **/
 
+#include "version.hpp"
+
 #include <ndn-cxx/face.hpp>
 #include <ndn-cxx/management/nfd-controller.hpp>
 #include <ndn-cxx/security/key-chain.hpp>
@@ -37,6 +39,15 @@
 
 namespace tools {
 
+void
+usage(const char* programName)
+{
+  std::cout << "Usage:\n" << programName  << " [-h] [-V]\n"
+            << "   -h  - print usage and exit\n"
+            << "   -V  - print version number and exit\n"
+            << std::endl;
+}
+
 class NdnAutoconfig
 {
 public:
@@ -311,17 +322,30 @@
 } // namespace tools
 
 int
-main()
+main(int argc, char** argv)
 {
-  try
-    {
-      tools::NdnAutoconfig autoConfigInstance;
+  int opt;
+  const char* programName = argv[0];
 
-      autoConfigInstance.discoverHubStage1();
+  while ((opt = getopt(argc, argv, "hV")) != -1) {
+    switch (opt) {
+    case 'h':
+      tools::usage(programName);
+      return 0;
+    case 'V':
+      std::cout << NFD_VERSION_BUILD_STRING << std::endl;
+      return 0;
     }
-  catch (const std::exception& error)
-    {
-      std::cerr << "ERROR: " << error.what() << std::endl;
-    }
+  }
+
+  try {
+    tools::NdnAutoconfig autoConfigInstance;
+
+    autoConfigInstance.discoverHubStage1();
+  }
+  catch (const std::exception& error) {
+    std::cerr << "ERROR: " << error.what() << std::endl;
+    return 1;
+  }
   return 0;
 }