Merge pull request #672 from mrdeep1/examples

examples: Provide standalone source and simple Makefile for examples
This commit is contained in:
obgm authored and GitHub committed 2021-05-11 15:46:50 +02:00
commit b4f9302b21
4 files changed
+85

No files matched your search

+15
View File
@@ -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
+18
View File
@@ -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
+43
View File
@@ -0,0 +1,43 @@
# Makefile for libcoap standalone examples
#
# Copyright (C) 2021 Olaf Bergmann <bergmann@tzi.org>
#
# 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
+9
View File
@@ -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.