diff --git a/configure.ac b/configure.ac index 9f88c147..052841cc 100644 --- a/configure.ac +++ b/configure.ac @@ -613,6 +613,16 @@ AC_ARG_ENABLE([examples], AM_CONDITIONAL(BUILD_EXAMPLES, [test "x$build_examples" = "xyes"]) +# configure options +# __examples-source +AC_ARG_ENABLE([examples-source], + [AS_HELP_STRING([--enable-examples-source], + [Enable installing example source to DATAROOTDIR/libcoap/examples [default=yes]])], + [build_examples_source="$enableval"], + [build_examples_source="yes"]) + +AM_CONDITIONAL(BUILD_EXAMPLES_SOURCE, [test "x$build_examples_source" = "xyes"]) + # configure options # __gcov__ AC_ARG_ENABLE([gcov], @@ -939,6 +949,11 @@ if test "x$build_examples" = "xyes"; then else AC_MSG_RESULT([ build examples : "no"]) fi +if test "x$build_examples_source" = "xyes"; then + AC_MSG_RESULT([ install examples source : "yes"]) +else + AC_MSG_RESULT([ install examples source : "no"]) +fi if test "x$build_gcov" = "xyes"; then AC_MSG_RESULT([ build with gcov support : "yes"]) else diff --git a/examples/Makefile.am b/examples/Makefile.am index e66f55a5..a743ec24 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -5,6 +5,8 @@ # This file is part of the CoAP C library libcoap. Please see README and # COPYING for terms of use. +EXTRA_DIST = share.libcoap.examples.Makefile share.libcoap.examples.README + # just do nothing if 'BUILD_EXAMPLES' isn't defined if BUILD_EXAMPLES @@ -34,3 +36,19 @@ coap_tiny_SOURCES = tiny.c coap_tiny_LDADD = $(DTLS_LIBS) $(top_builddir)/.libs/libcoap-$(LIBCOAP_NAME_SUFFIX).la endif # BUILD_EXAMPLES + +if BUILD_EXAMPLES_SOURCE +EXAMPLES_DIR = $(DESTDIR)$(datadir)/libcoap/examples +EXAMPLES_SRC = coap-client.c coap-server.c + +## Install example files +install-exec-hook: + $(MKDIR_P) $(EXAMPLES_DIR) + (cd $(top_srcdir)/examples ; \ + $(INSTALL_DATA) $(EXAMPLES_SRC) ../LICENSE ../COPYING $(EXAMPLES_DIR) ; \ + $(INSTALL_DATA) share.libcoap.examples.Makefile $(EXAMPLES_DIR)/Makefile; \ + $(INSTALL_DATA) share.libcoap.examples.README $(EXAMPLES_DIR)/README) + +uninstall-hook: + rm -rf $(DESTDIR)$(datadir)/libcoap/examples +endif # BUILD_EXAMPLES_SOURCE diff --git a/examples/share.libcoap.examples.Makefile b/examples/share.libcoap.examples.Makefile new file mode 100644 index 00000000..4801c953 --- /dev/null +++ b/examples/share.libcoap.examples.Makefile @@ -0,0 +1,43 @@ +# Makefile for libcoap standalone examples +# +# Copyright (C) 2021 Olaf Bergmann +# +# This file is part of the CoAP C library libcoap. Please see README and +# COPYING for terms of use. + +# Set external variable LIBCOAP if you need a specific libcoap library. +# E.g. libcoap-3-openssl, libcoap-3-gnutls, libcoap-3-mbedtls or libcoap-3-notls +# +LIBCOAP?=libcoap-3 + +WARNING_CFLAGS= \ + -pedantic \ + -Wall \ + -Wcast-qual \ + -Wextra \ + -Wformat-security \ + -Winline \ + -Wmissing-declarations \ + -Wmissing-prototypes \ + -Wnested-externs \ + -Wpointer-arith \ + -Wshadow \ + -Wstrict-prototypes \ + -Wswitch-default \ + -Wswitch-enum \ + -Wunused \ + -Wwrite-strings + +pkgconfig=$(shell pkg-config $(1) $(2)) + +CPPFLAGS=-D_GNU_SOURCE $(WARNING_CFLAGS) $(call pkgconfig,--cflags,$(LIBCOAP)) +CFLAGS=-std=c99 +LDLIBS=$(call pkgconfig,--libs-only-l,$(LIBCOAP)) +libdirs=$(call pkgconfig,--libs-only-L,$(LIBCOAP)) +rpath=$(shell echo "$(libdirs)" | sed -e 's/^-L/-Wl,--rpath /') +LDFLAGS=$(libdirs) $(rpath) + +all: coap-client coap-server + +clean: + rm -f *.o coap-client coap-server diff --git a/examples/share.libcoap.examples.README b/examples/share.libcoap.examples.README new file mode 100644 index 00000000..f4b586cc --- /dev/null +++ b/examples/share.libcoap.examples.README @@ -0,0 +1,9 @@ +This directory contains some example libcoap code for a client or server which +can easily be modified as per your requirements. + +The provided code is the same as used to build the installed binaries +coap-client and coap-server. + +Simply 'cd' into this directory and then run 'make' to build the executables. + +