travis: Update travis to do a `make distcheck` instead of just `make check` (#46)

* travis: Do a `make distcheck` instead of just `make check`

Doing a `make distcheck` instead of just a `make check` ensures that
the build system is sane and that the results from `make dist` have
everything needed.

* build-system: Fixes for `make distcheck`

This commit fixes the `distcheck` target by addressing the following
issues:

 *  Repaired ability to perform builds when the build directory is not
    the source directory.
 *  Addressed an issue with the tarball name that occurs the very
    first time `make` is run.
diff --git a/.travis.yml b/.travis.yml
index e9d7f3a..ba0495a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,4 +5,4 @@
 
 script:
   - ./bootstrap-configure --enable-minimum-set-of-tests
-  - make check
+  - make distcheck
diff --git a/Makefile.am b/Makefile.am
index 00f6ba2..897dccb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -30,6 +30,8 @@
 
 AM_MAKEFLAGS                        = --no-print-directory
 
+AM_DISTCHECK_CONFIGURE_FLAGS        = --enable-minimum-set-of-tests
+
 SUBDIRS                             = \
     include                           \
     src                               \
@@ -91,6 +93,14 @@
 PACKAGE_VERSION                    = $(OPENTHREAD_VERSION)
 VERSION                            = $(PACKAGE_VERSION)
 
+distdir = $(PACKAGE)-$(shell                                     \
+if [ "$(origin OPENTHREAD_VERSION)" != "file" ]; then            \
+    echo "$(OPENTHREAD_VERSION)" ;                               \
+else                                                             \
+    $(abs_top_nlbuild_autotools_dir)/scripts/mkversion           \
+        -b "$(OPENTHREAD_VERSION)" "$(top_srcdir)";              \
+fi )
+
 #
 # check-file-.local-version
 #
diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in
index 52403ec..2d42243 100644
--- a/doc/Doxyfile.in
+++ b/doc/Doxyfile.in
@@ -1116,7 +1116,7 @@
 # of the possible markers and block names see the documentation.
 # This tag requires that the tag GENERATE_HTML is set to YES.
 
-HTML_HEADER            = header.html
+HTML_HEADER            = @abs_srcdir@/header.html
 
 # The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each
 # generated HTML page. If the tag is left blank doxygen will generate a standard
diff --git a/examples/cli/Makefile.am b/examples/cli/Makefile.am
index 10bc590..1eb0492 100644
--- a/examples/cli/Makefile.am
+++ b/examples/cli/Makefile.am
@@ -39,12 +39,12 @@
     $(OPENTHREAD_TARGET_DEFINES)                                 \
     $(NULL)
 
-soc_LDADD                                                      = \
-    $(top_srcdir)/src/core/libopenthread.a                       \
-    $(top_srcdir)/src/cli/libopenthread-cli.a                    \
-    $(top_srcdir)/examples/platform/posix/libopenthread-posix.a  \
-    $(top_srcdir)/third_party/mbedtls/libmbedcrypto.a            \
-    -lpthread                                                    \
+soc_LDADD                                                      =  \
+    $(top_builddir)/src/core/libopenthread.a                      \
+    $(top_builddir)/src/cli/libopenthread-cli.a                   \
+    $(top_builddir)/examples/platform/posix/libopenthread-posix.a \
+    $(top_builddir)/third_party/mbedtls/libmbedcrypto.a           \
+    -lpthread                                                     \
     $(NULL)
 
 soc_SOURCES                                                    = \
diff --git a/tests/scripts/Makefile.am b/tests/scripts/Makefile.am
index 1342bd3..b55409f 100644
--- a/tests/scripts/Makefile.am
+++ b/tests/scripts/Makefile.am
@@ -192,7 +192,7 @@
 
 TESTS_ENVIRONMENT                                                  = \
     export                                                           \
-    top_srcdir='$(top_srcdir)'                                       \
+    top_builddir='$(top_builddir)'                                   \
     VERBOSE=1;                                                       \
     $(NULL)
 
diff --git a/tests/scripts/thread-cert/node.py b/tests/scripts/thread-cert/node.py
index c0b7558..a0d06a1 100755
--- a/tests/scripts/thread-cert/node.py
+++ b/tests/scripts/thread-cert/node.py
@@ -52,8 +52,8 @@
 
     def __init_sim(self, nodeid):
         """ Initialize a simulation node. """
-        if "top_srcdir" in os.environ.keys():
-            srcdir = os.environ['top_srcdir']
+        if "top_builddir" in os.environ.keys():
+            srcdir = os.environ['top_builddir']
             cmd = '%s/examples/cli/soc' % srcdir
         else:
             cmd = './soc'
diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am
index c83dc9d..5d0d16e 100644
--- a/tests/unit/Makefile.am
+++ b/tests/unit/Makefile.am
@@ -53,11 +53,11 @@
     -I$(top_srcdir)/third_party/mbedtls/repo/include             \
     $(NULL)
 
-COMMON_LDADD                                                   = \
-    $(top_srcdir)/src/core/libopenthread.a                       \
-    $(top_srcdir)/examples/platform/posix/libopenthread-posix.a  \
-    $(top_srcdir)/third_party/mbedtls/libmbedcrypto.a            \
-    -lpthread                                                    \
+COMMON_LDADD                                                   =  \
+    $(top_builddir)/src/core/libopenthread.a                      \
+    $(top_builddir)/examples/platform/posix/libopenthread-posix.a \
+    $(top_builddir)/third_party/mbedtls/libmbedcrypto.a           \
+    -lpthread                                                     \
     $(NULL)
 
 # Test applications that should be run when the 'check' target is run.