build: Disable building examples by default

To enable examples, one need to use `--with-examples` configure flag.
Note about this added to the getting started instructions.

Change-Id: If9afb1fd3f298b634adb8bb3a4bcae151ac8f7af
diff --git a/docs/INSTALL.rst b/docs/INSTALL.rst
index e61cf24..3ed830a 100644
--- a/docs/INSTALL.rst
+++ b/docs/INSTALL.rst
@@ -139,6 +139,40 @@
 
 -  ``build/unit-tests``: A unit test binary for the library
 
+Build with examples
+-------------------
+
+By default, examples in ``examples/`` are not build.  To enable them, use
+``--with-examples`` configure option:
+
+::
+
+    ./waf configure --with-examples
+    ./waf
+
+To run examples:
+
+::
+
+    # trivial producer app
+    ./build/examples/producer
+
+    # trivial consumer app
+    ./build/examples/consumer
+
+    # trivial consumer app with timers
+    ./build/examples/consumer-with-timer
+
+If you want to test out a sample application, just create a ``.cpp`` file in ``examples/``
+folder and it will be compiled on the next run on ``./waf``.  For example:
+
+::
+
+    cp examples/consumer.cpp examples/my-new-consumer-app.cpp
+    ./waf
+    ./build/examples/my-new-consumer-app
+
+
 Debug symbols
 ~~~~~~~~~~~~~
 
diff --git a/wscript b/wscript
index e397ee9..a9d75f7 100644
--- a/wscript
+++ b/wscript
@@ -25,6 +25,9 @@
     opt.add_option('--without-tools', action='store_false', default=True, dest='with_tools',
                    help='''Do not build tools''')
 
+    opt.add_option('--with-examples', action='store_true', default=False, dest='with_examples',
+                   help='''Build examples''')
+
     opt.add_option('--without-sqlite-locking', action='store_false', default=True,
                    dest='with_sqlite_locking',
                    help='''Disable filesystem locking in sqlite3 database '''
@@ -42,6 +45,7 @@
 
     conf.env['WITH_TESTS'] = conf.options.with_tests
     conf.env['WITH_TOOLS'] = conf.options.with_tools
+    conf.env['WITH_EXAMPLES'] = conf.options.with_examples
 
     conf.find_program('sh', var='SH', mandatory=True)
 
@@ -190,8 +194,9 @@
         bld.recurse('tests-integrated')
 
     if bld.env['WITH_TOOLS']:
-        bld.recurse("tools examples")
-    else:
+        bld.recurse("tools")
+
+    if bld.env['WITH_EXAMPLES']:
         bld.recurse("examples")
 
     headers = bld.path.ant_glob(['src/**/*.hpp'])