From: Guus Sliepen Date: Sat, 21 Jul 2018 15:52:07 +0000 (+0200) Subject: Allow compiling without support for Catta. X-Git-Url: http://git.meshlink.io/?p=meshlink;a=commitdiff_plain;h=f13d66f20a227a87075f6456f41b83ce269b67f4 Allow compiling without support for Catta. Configuring with --disable-catta will cause MeshLink to not be linked to the Catta library, and local discovery will not be available. --- diff --git a/Makefile.am b/Makefile.am index 8b39f753..93bc9632 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,13 @@ AUTOMAKE_OPTIONS = gnu -SUBDIRS = catta src doc test examples +if CATTA +MAYBE_CATTA = catta +endif + +SUBDIRS = $(MAYBE_CATTA) src doc test examples + +DIST_SUBDIRS = $(SUBDIRS) ACLOCAL_AMFLAGS = -I m4 diff --git a/configure.ac b/configure.ac index 8ef1e9ff..47656d73 100644 --- a/configure.ac +++ b/configure.ac @@ -5,7 +5,6 @@ AC_INIT([MeshLink], [0.1]) AM_INIT_AUTOMAKE([std-options subdir-objects nostdinc silent-rules -Wall]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIR([m4]) -AC_CONFIG_SUBDIRS([catta]) AM_SILENT_RULES([yes]) # Enable GNU extensions. @@ -79,6 +78,14 @@ AS_IF([test "x$enable_hardening" != "xno"], ] ); +dnl Allow building without Catta +AC_ARG_ENABLE([catta], AS_HELP_STRING([--disable-catta], [disable linking with the Catta library])) +AS_IF([test "x$enable_catta" != "xno"], + AC_DEFINE(HAVE_CATTA, 1, [Link with Catta]) + AC_CONFIG_SUBDIRS([catta]) +) +AM_CONDITIONAL(CATTA, test "x$enable_catta" != "xno") + dnl UTCP debug flags AC_ARG_ENABLE([utcp_debug], AS_HELP_STRING([--enable-utcp-debug], [compile utcp with debug output])) AS_IF([test "x$enable_utcp_debug" = "xyes"], diff --git a/examples/Makefile.am b/examples/Makefile.am index 5c7f2718..4d363657 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -4,16 +4,16 @@ AM_CPPFLAGS = $(PTHREAD_CFLAGS) -I${top_srcdir}/src -iquote. -Wall AM_LDFLAGS = $(PTHREAD_LIBS) meshlinkapp_SOURCES = meshlinkapp.c -meshlinkapp_LDADD = ${top_builddir}/src/libmeshlink.la ${top_builddir}/catta/src/libcatta.la +meshlinkapp_LDADD = ${top_builddir}/src/libmeshlink.la chat_SOURCES = chat.c -chat_LDADD = ${top_builddir}/src/libmeshlink.la ${top_builddir}/catta/src/libcatta.la +chat_LDADD = ${top_builddir}/src/libmeshlink.la chatpp_SOURCES = chatpp.cc -chatpp_LDADD = ${top_builddir}/src/libmeshlink.la ${top_builddir}/catta/src/libcatta.la +chatpp_LDADD = ${top_builddir}/src/libmeshlink.la manynodes_SOURCES = manynodes.c -manynodes_LDADD = ${top_builddir}/src/libmeshlink.la ${top_builddir}/catta/src/libcatta.la +manynodes_LDADD = ${top_builddir}/src/libmeshlink.la channels_SOURCES = channels.c -channels_LDADD = ${top_builddir}/src/libmeshlink.la ${top_builddir}/catta/src/libcatta.la +channels_LDADD = ${top_builddir}/src/libmeshlink.la diff --git a/src/Makefile.am b/src/Makefile.am index 1e203778..ef0d8d9e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,6 +4,9 @@ AM_CPPFLAGS = -Wall ed25519_SOURCES = \ ed25519/add_scalar.c \ + ed25519/ecdh.c \ + ed25519/ecdsa.c \ + ed25519/ecdsagen.c \ ed25519/ed25519.h \ ed25519/fe.c ed25519/fe.h \ ed25519/fixedint.h \ @@ -37,7 +40,6 @@ libmeshlink_la_SOURCES = \ conf.c conf.h \ connection.c connection.h \ crypto.c crypto.h \ - discovery.c discovery.h \ dropin.c dropin.h \ ecdh.h \ ecdsa.h \ @@ -80,16 +82,18 @@ libmeshlink_la_SOURCES = \ $(chacha_poly1305_SOURCES) \ $(utcp_SOURCES) -libmeshlink_la_CFLAGS = $(PTHREAD_CFLAGS) -fPIC -I${top_srcdir}/catta/include/ -iquote. +libmeshlink_la_CFLAGS = $(PTHREAD_CFLAGS) -fPIC -iquote. +libmeshlink_la_LDFLAGS += $(PTHREAD_LIBS) + +if CATTA +libmeshlink_la_SOURCES += \ + discovery.c discovery.h + +libmeshlink_la_CFLAGS += -I${top_srcdir}/catta/include/ if MINGW libmeshlink_la_CFLAGS += -I${top_srcdir}/catta/src/compat/windows/include/ endif -libmeshlink_la_LDFLAGS += $(PTHREAD_LIBS) libmeshlink_la_LIBADD = ${top_builddir}/catta/src/libcatta.la - -libmeshlink_la_SOURCES += \ - ed25519/ecdh.c \ - ed25519/ecdsa.c \ - ed25519/ecdsagen.c +endif diff --git a/src/meshlink.c b/src/meshlink.c index 573dfe49..c720c766 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1,6 +1,6 @@ /* meshlink.c -- Implementation of the MeshLink API. - Copyright (C) 2014, 2017 Guus Sliepen + Copyright (C) 2014-2018 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1215,9 +1215,11 @@ bool meshlink_start(meshlink_handle_t *mesh) { mesh->threadstarted = true; +#if HAVE_CATTA if(mesh->discovery) { discovery_start(mesh); } +#endif pthread_mutex_unlock(&(mesh->mesh_mutex)); return true; @@ -1232,10 +1234,12 @@ void meshlink_stop(meshlink_handle_t *mesh) { pthread_mutex_lock(&(mesh->mesh_mutex)); logger(mesh, MESHLINK_DEBUG, "meshlink_stop called\n"); +#if HAVE_CATTA // Stop discovery if(mesh->discovery) { discovery_stop(mesh); } +#endif // Shut down the main thread event_loop_stop(&mesh->loop); @@ -2653,6 +2657,7 @@ void update_node_status(meshlink_handle_t *mesh, node_t *n) { } void meshlink_enable_discovery(meshlink_handle_t *mesh, bool enable) { +#if HAVE_CATTA if(!mesh) { meshlink_errno = MESHLINK_EINVAL; return; @@ -2676,6 +2681,11 @@ void meshlink_enable_discovery(meshlink_handle_t *mesh, bool enable) { end: pthread_mutex_unlock(&mesh->mesh_mutex); +#else + (void)mesh; + (void)enable; + meshlink_errno = MESHLINK_ENOTSUP; +#endif } static void __attribute__((constructor)) meshlink_init(void) { diff --git a/src/meshlink.h b/src/meshlink.h index a0cb1187..37eeac81 100644 --- a/src/meshlink.h +++ b/src/meshlink.h @@ -3,7 +3,7 @@ /* meshlink.h -- MeshLink API - Copyright (C) 2014, 2017 Guus Sliepen + Copyright (C) 2014-2018 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -63,6 +63,7 @@ typedef enum { MESHLINK_ESTORAGE, ///< MeshLink coud not load or write data from/to disk MESHLINK_ENETWORK, ///< MeshLink encountered a network error MESHLINK_EPEER, ///< A peer caused an error + MESHLINK_ENOTSUP, ///< The operation is not supported in the current configuration of MeshLink } meshlink_errno_t; /// Device class