contiki: work without running configure

When building with contiki, 'CONTIKI' is defined and is used to detect contiki.
Configure options can be configured with:

    DTLS_CONF_ECC, DTLS_CONF_PSK, DTLS_CONF_NDEBUG

All files now include 'tinydtls.h' instead of 'dtls_config.h'.

Change-Id: I9a558a7d6bd777656d7b29028852bfc08911b8b7
Signed-off-by: Gaëtan Harter <gaetan.harter@inria.fr>
diff --git a/.gitignore b/.gitignore
index 589e947..a74d6cc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,7 +30,7 @@
 *.elf
 *.map
 obj_*
-tinydtls.h
+dtls_config.h.in
 dtls_config.h
 *.apple2enh
 *.atarixl
diff --git a/configure.in b/configure.in
index ebd5b58..5a76a1e 100644
--- a/configure.in
+++ b/configure.in
@@ -19,16 +19,9 @@
 AC_CONFIG_SRCDIR([dtls.c])
 dnl AC_CONFIG_HEADERS([config.h])
 
-AC_ARG_WITH(contiki,
-  [AS_HELP_STRING([--with-contiki],[build libtinydtls for the Contiki OS])],
-  [AC_DEFINE(WITH_CONTIKI,1,[Define to 1 if building for Contiki.])
-   WITH_CONTIKI=1],
-  [])
-
 AC_PATH_PROG(DOXYGEN, doxygen, [:])
 AC_PATH_PROG(ETAGS, etags, [/bin/false])
 
-if test "${with_contiki}" != "yes" ; then
 # Checks for programs.
 AC_PROG_MAKE_SET
 AC_PROG_CC
@@ -39,7 +32,6 @@
 # Checks for libraries.
 AC_SEARCH_LIBS([gethostbyname], [nsl])
 AC_SEARCH_LIBS([socket], [socket])
-fi
 
 AC_ARG_WITH(debug,
   [AS_HELP_STRING([--without-debug],[disable all debug output and assertions])],
@@ -65,18 +57,14 @@
 
 AC_SUBST(OPT_OBJS)
 AC_SUBST(NDEBUG)
-AC_SUBST(WITH_CONTIKI)
 AC_SUBST(DTLS_ECC)
 AC_SUBST(DTLS_PSK)
 
-if test "${with_contiki}" = "yes" ; then
-  AC_MSG_NOTICE([skipping header checks for Contiki])
-else
-  # Checks for header files.
-  AC_CHECK_HEADERS([assert.h arpa/inet.h fcntl.h inttypes.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h strings.h sys/param.h sys/socket.h unistd.h])
+# Checks for header files.
+AC_CHECK_HEADERS([assert.h arpa/inet.h fcntl.h inttypes.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h strings.h sys/param.h sys/socket.h unistd.h])
 
-  AC_CHECK_HEADERS([sys/time.h time.h])
-  AC_CHECK_HEADERS([sys/types.h sys/stat.h])
+AC_CHECK_HEADERS([sys/time.h time.h])
+AC_CHECK_HEADERS([sys/types.h sys/stat.h])
 
 # Checks for typedefs, structures, and compiler characteristics.
 AC_C_INLINE
@@ -90,15 +78,9 @@
 # Checks for library functions.
 AC_FUNC_MALLOC
 AC_CHECK_FUNCS([memset select socket strdup strerror strnlen fls vprintf])
-fi
 
-AC_CONFIG_HEADERS([dtls_config.h tinydtls.h])
+AC_CONFIG_HEADERS([dtls_config.h])
 
-# Adds Contiki-specific definitions to the end of dtls_config.h
-AH_BOTTOM([
-#ifdef WITH_CONTIKI
-#include "platform-specific/platform.h"
-#endif])
 
 AC_CONFIG_FILES([Makefile
                  doc/Makefile
diff --git a/dtls_debug.c b/dtls_debug.c
index 2945b6c..a5f55b3 100644
--- a/dtls_debug.c
+++ b/dtls_debug.c
@@ -41,6 +41,7 @@
 
 static int maxlog = DTLS_LOG_WARN;	/* default maximum log level */
 
+#ifndef WITH_CONTIKI
 const char *dtls_package_name() {
   return PACKAGE_NAME;
 }
@@ -48,6 +49,7 @@
 const char *dtls_package_version() {
   return PACKAGE_VERSION;
 }
+#endif /* WITH_CONTIKI */
 
 log_t 
 dtls_get_log_level() {
diff --git a/dtls_debug.h b/dtls_debug.h
index 8d636f0..8cff829 100644
--- a/dtls_debug.h
+++ b/dtls_debug.h
@@ -57,11 +57,14 @@
        DTLS_LOG_NOTICE, DTLS_LOG_INFO, DTLS_LOG_DEBUG
 } log_t;
 
+#ifndef WITH_CONTIKI
+/* Contiki does not have the required PACKAGE_ variables configured */
 /** Returns a zero-terminated string with the name of this library. */
 const char *dtls_package_name();
 
 /** Returns a zero-terminated string with the library version. */
 const char *dtls_package_version();
+#endif /* WITH_CONTIKI */
 
 /** Returns the current log level. */
 log_t dtls_get_log_level();
diff --git a/platform-specific/platform.h b/platform-specific/platform.h
index 7418c0a..fd3214a 100644
--- a/platform-specific/platform.h
+++ b/platform-specific/platform.h
@@ -6,12 +6,37 @@
 #define _PLATFORM_H_ 1
 
 #ifdef CONTIKI
+#define WITH_CONTIKI 1
+
 #include "contiki.h"
 #include "contiki-lib.h"
 #include "contiki-net.h"
 
 #include "contiki-conf.h"
 
+/* support for TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 */
+#ifndef DTLS_CONF_ECC
+#define DTLS_CONF_ECC 1
+#endif
+#if DTLS_CONF_ECC
+#define DTLS_ECC
+#endif
+
+/* support for TLS_PSK_WITH_AES_128_CCM_8 */
+#ifndef DTLS_CONF_PSK
+#define DTLS_CONF_PSK 1
+#endif
+#if DTLS_CONF_PSK
+#define DTLS_PSK
+#endif
+
+/* Disable all debug output and assertions */
+#ifndef DTLS_CONF_NDEBUG
+#if DTLS_CONF_NDEBUG
+#define NDEBUG
+#endif
+#endif
+
 /* global constants for constrained devices running Contiki */
 #ifndef DTLS_PEER_MAX
 /** The maximum number DTLS peers (i.e. sessions). */
diff --git a/tinydtls.h.in b/tinydtls.h
similarity index 75%
rename from tinydtls.h.in
rename to tinydtls.h
index 5a69f45..6dd1ec9 100644
--- a/tinydtls.h.in
+++ b/tinydtls.h
@@ -1,3 +1,4 @@
+/* tinydtls.h.  Generated from tinydtls.h.in by configure.  */
 /*******************************************************************************
  *
  * Copyright (c) 2011, 2012, 2013, 2014, 2015 Olaf Bergmann (TZI) and others.
@@ -6,7 +7,7 @@
  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
  *
  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at 
+ * and the Eclipse Distribution License is available at
  * http://www.eclipse.org/org/documents/edl-v10.php.
  *
  * Contributors:
@@ -23,15 +24,10 @@
 #ifndef _DTLS_TINYDTLS_H_
 #define _DTLS_TINYDTLS_H_
 
-/** Defined to 1 if tinydtls is built with support for ECC */
-#undef DTLS_ECC
-
-/** Defined to 1 if tinydtls is built with support for PSK */
-#undef DTLS_PSK
-
-/** Defined to 1 if tinydtls is built for Contiki OS */
-#undef WITH_CONTIKI
-
+#ifndef CONTIKI
 #include "dtls_config.h"
+#else /* !CONTIKI */
+#include "platform-specific/platform.h"
+#endif /* !CONTIKI */
 
 #endif /* _DTLS_TINYDTLS_H_ */