1c87c5fbaSopenharmony_ci# Makefile 2c87c5fbaSopenharmony_ci# 3c87c5fbaSopenharmony_ci# Copyright (C) 2010-2023 Olaf Bergmann <bergmann@tzi.org> and others 4c87c5fbaSopenharmony_ci# 5c87c5fbaSopenharmony_ci# SPDX-License-Identifier: BSD-2-Clause 6c87c5fbaSopenharmony_ci# 7c87c5fbaSopenharmony_ci# This file is part of the CoAP C library libcoap. Please see README and 8c87c5fbaSopenharmony_ci# COPYING for terms of use. 9c87c5fbaSopenharmony_ci 10c87c5fbaSopenharmony_cilibcoap_dir = ../.. 11c87c5fbaSopenharmony_ci 12c87c5fbaSopenharmony_ciLIBCOAP_API_VERSION = $(shell if [ -f $(libcoap_dir)/configure.ac ]; then \ 13c87c5fbaSopenharmony_ci sed -ne 's/^LIBCOAP_API_VERSION=\([0-9]\+\).*$$/\1/p' $(libcoap_dir)/configure.ac; \ 14c87c5fbaSopenharmony_ci else echo -n "3"; fi) 15c87c5fbaSopenharmony_ci 16c87c5fbaSopenharmony_cicoap_include_dir = $(libcoap_dir)/include/coap$(LIBCOAP_API_VERSION) 17c87c5fbaSopenharmony_ci 18c87c5fbaSopenharmony_ciWITH_LWIP_BRANCH=STABLE-2_1_3_RELEASE 19c87c5fbaSopenharmony_ciWITH_LWIP_CONTRIB_BRANCH=STABLE-2_1_0_RELEASE 20c87c5fbaSopenharmony_ci# Update to latest TinyDTLS submodule as defined for libcoap 21c87c5fbaSopenharmony_ciWITH_TINYDTLS_BRANCH=f1d47d533b70ac10e4ff0ae3a088dfe4f265d242 22c87c5fbaSopenharmony_ci 23c87c5fbaSopenharmony_ci# Need to determine which library clock_gettime() resides in (as found by ./autogen.sh) 24c87c5fbaSopenharmony_ciLDLIBS := $(shell if [ -f $(libcoap_dir)/config.log ] ; then \ 25c87c5fbaSopenharmony_ci grep ac_cv_search_clock_gettime=- $(libcoap_dir)/config.log|cut -d= -f2 ; fi) 26c87c5fbaSopenharmony_ci 27c87c5fbaSopenharmony_ci# 28c87c5fbaSopenharmony_ci# Remove the 4 -dtls checks from "all" if you do not want DTLS included in 29c87c5fbaSopenharmony_ci# some of the built objects. 30c87c5fbaSopenharmony_ci# 31c87c5fbaSopenharmony_ciall: lwip \ 32c87c5fbaSopenharmony_ci lwip-contrib \ 33c87c5fbaSopenharmony_ci check-version \ 34c87c5fbaSopenharmony_ci check-tinydtls \ 35c87c5fbaSopenharmony_ci $(coap_include_dir)/coap.h \ 36c87c5fbaSopenharmony_ci lib-server \ 37c87c5fbaSopenharmony_ci server \ 38c87c5fbaSopenharmony_ci lib-client \ 39c87c5fbaSopenharmony_ci client \ 40c87c5fbaSopenharmony_ci lib-server-dtls \ 41c87c5fbaSopenharmony_ci server-dtls \ 42c87c5fbaSopenharmony_ci lib-client-dtls \ 43c87c5fbaSopenharmony_ci client-dtls 44c87c5fbaSopenharmony_ci 45c87c5fbaSopenharmony_cilwip: 46c87c5fbaSopenharmony_ci git clone --depth 1 https://git.savannah.nongnu.org/git/lwip.git -b $(WITH_LWIP_BRANCH) 47c87c5fbaSopenharmony_ci (cd lwip ; git checkout $(WITH_LWIP_BRANCH)) 48c87c5fbaSopenharmony_ci $(MAKE) 49c87c5fbaSopenharmony_ci 50c87c5fbaSopenharmony_cilwip-contrib: 51c87c5fbaSopenharmony_ci git clone --depth 1 https://git.savannah.nongnu.org/git/lwip/lwip-contrib.git -b $(WITH_LWIP_CONTRIB_BRANCH) 52c87c5fbaSopenharmony_ci (cd lwip-contrib ; git checkout $(WITH_LWIP_CONTRIB_BRANCH)) 53c87c5fbaSopenharmony_ci $(MAKE) 54c87c5fbaSopenharmony_ci 55c87c5fbaSopenharmony_cicheck-version: 56c87c5fbaSopenharmony_ci @(if [ -d lwip ] ; then \ 57c87c5fbaSopenharmony_ci cd lwip ; \ 58c87c5fbaSopenharmony_ci TAG=`git describe --tags --all`; \ 59c87c5fbaSopenharmony_ci if [ "$$TAG" != ${WITH_LWIP_BRANCH} ] ; then \ 60c87c5fbaSopenharmony_ci if [ "$$TAG" != "tags/${WITH_LWIP_BRANCH}" ] ; then \ 61c87c5fbaSopenharmony_ci echo "Updating lwip to ${WITH_LWIP_BRANCH}" ; \ 62c87c5fbaSopenharmony_ci cd .. ; \ 63c87c5fbaSopenharmony_ci rm -rf lwip ; \ 64c87c5fbaSopenharmony_ci ${MAKE}; \ 65c87c5fbaSopenharmony_ci fi ; \ 66c87c5fbaSopenharmony_ci fi ; \ 67c87c5fbaSopenharmony_ci fi) 68c87c5fbaSopenharmony_ci @(if [ -d lwip-contrib ] ; then \ 69c87c5fbaSopenharmony_ci cd lwip-contrib ; \ 70c87c5fbaSopenharmony_ci TAG=`git describe --tags`; \ 71c87c5fbaSopenharmony_ci if [ "$$TAG" != ${WITH_LWIP_CONTRIB_BRANCH} ] ; then \ 72c87c5fbaSopenharmony_ci if [ "$$TAG" != "tags/${WITH_LWIP_CONTRIB_BRANCH}" ] ; then \ 73c87c5fbaSopenharmony_ci echo "Updating lwip-contib to ${WITH_LWIP_CONTRIB_BRANCH}" ; \ 74c87c5fbaSopenharmony_ci cd .. ; \ 75c87c5fbaSopenharmony_ci rm -rf lwip-contrib ; \ 76c87c5fbaSopenharmony_ci ${MAKE}; \ 77c87c5fbaSopenharmony_ci fi ; \ 78c87c5fbaSopenharmony_ci fi ; \ 79c87c5fbaSopenharmony_ci fi) 80c87c5fbaSopenharmony_ci 81c87c5fbaSopenharmony_ci# base libcoap git has empty ext/tinydtls 82c87c5fbaSopenharmony_cicheck-tinydtls: 83c87c5fbaSopenharmony_ci @(if [ ! -d $(libcoap_dir)/ext/tinydtls ] ; then \ 84c87c5fbaSopenharmony_ci mkdir -p $(libcoap_dir)/ext ; \ 85c87c5fbaSopenharmony_ci (cd $(libcoap_dir)/ext ; git clone https://github.com/eclipse/tinydtls.git) ; \ 86c87c5fbaSopenharmony_ci (cd $(libcoap_dir)/ext/tinydtls ; git checkout ${WITH_TINYDTLS_BRANCH}) ; \ 87c87c5fbaSopenharmony_ci fi ; \ 88c87c5fbaSopenharmony_ci if [ ! -f $(libcoap_dir)/ext/tinydtls/dtls.c ] ; then \ 89c87c5fbaSopenharmony_ci IN_GIT=`git rev-parse --is-inside-work-tree` ; \ 90c87c5fbaSopenharmony_ci if [ "$$IN_GIT" = "true" ] ; then \ 91c87c5fbaSopenharmony_ci (cd $(libcoap_dir) ; git submodule init ; git submodule update) ; \ 92c87c5fbaSopenharmony_ci else \ 93c87c5fbaSopenharmony_ci (cd $(libcoap_dir)/ext ; git clone https://github.com/eclipse/tinydtls.git) ; \ 94c87c5fbaSopenharmony_ci (cd $(libcoap_dir)/ext/tinydtls ; git checkout ${WITH_TINYDTLS_BRANCH}) ; \ 95c87c5fbaSopenharmony_ci fi ; \ 96c87c5fbaSopenharmony_ci if [ ! -f $(libcoap_dir)/ext/tinydtls/dtls.c ] ; then \ 97c87c5fbaSopenharmony_ci exit 1 ; \ 98c87c5fbaSopenharmony_ci fi ; \ 99c87c5fbaSopenharmony_ci fi ; \ 100c87c5fbaSopenharmony_ci IN_GIT=`git rev-parse --is-inside-work-tree` ; \ 101c87c5fbaSopenharmony_ci if [ "$$IN_GIT" = "true" ] ; then \ 102c87c5fbaSopenharmony_ci PWDDIR=`pwd` ; \ 103c87c5fbaSopenharmony_ci cd $(libcoap_dir) ; TAG=`git ls-tree HEAD ext/tinydtls | cut -d\ -f3 | cut -f1` ;\ 104c87c5fbaSopenharmony_ci if [ ! -z "$$TAG" ] ; then \ 105c87c5fbaSopenharmony_ci if [ "$$TAG" != ${WITH_TINYDTLS_BRANCH} ] ; then \ 106c87c5fbaSopenharmony_ci echo "Update WITH_TINYDTLS_BRANCH in Makefile to $$TAG" >&2 ; \ 107c87c5fbaSopenharmony_ci exit 1 ; \ 108c87c5fbaSopenharmony_ci fi ;\ 109c87c5fbaSopenharmony_ci fi ;\ 110c87c5fbaSopenharmony_ci cd $$PWDDIR ; \ 111c87c5fbaSopenharmony_ci fi ;\ 112c87c5fbaSopenharmony_ci if [ ! -f $(libcoap_dir)/ext/tinydtls/dtls_config.h ] ; then \ 113c87c5fbaSopenharmony_ci (cd $(libcoap_dir)/ext/tinydtls ; ./autogen.sh ; ./configure) ; \ 114c87c5fbaSopenharmony_ci ${MAKE} ; \ 115c87c5fbaSopenharmony_ci fi) 116c87c5fbaSopenharmony_ci 117c87c5fbaSopenharmony_ci# lwip and coap opts (include early to shadow the lwip-contrib/ports/unix/proj/minimal/ file and any ../../config.h) 118c87c5fbaSopenharmony_ciCFLAGS += -DWITH_LWIP -iquote./config $(EXTRA_CFLAGS) 119c87c5fbaSopenharmony_ci 120c87c5fbaSopenharmony_ci# lwip library 121c87c5fbaSopenharmony_ci 122c87c5fbaSopenharmony_ciCFLAGS += -Ilwip/src/include/ -Ilwip/src/include/ipv4/ \ 123c87c5fbaSopenharmony_ci -Ilwip-contrib/ports/unix/port/include/ \ 124c87c5fbaSopenharmony_ci -Ilwip-contrib/ports/unix/proj/minimal/ 125c87c5fbaSopenharmony_ci 126c87c5fbaSopenharmony_ciLWIP_SRC = def.c init.c tapif.c etharp.c netif.c timeouts.c stats.c udp.c \ 127c87c5fbaSopenharmony_ci tcp.c pbuf.c ip4_addr.c ip4.c inet_chksum.c tcp_in.c tcp_out.c \ 128c87c5fbaSopenharmony_ci icmp.c raw.c ip4_frag.c sys_arch.c ethernet.c ip.c mem.c memp.c 129c87c5fbaSopenharmony_civpath %.c lwip/src/core/ lwip-contrib/ports/unix/proj/minimal/ \ 130c87c5fbaSopenharmony_ci lwip/src/netif/ lwip/src/core/ipv4/ lwip-contrib/ports/unix/port/ \ 131c87c5fbaSopenharmony_ci lwip-contrib/ports/unix/port/netif/ 132c87c5fbaSopenharmony_ci# CFLAGS += -DLWIP_UNIX_LINUX 133c87c5fbaSopenharmony_ci 134c87c5fbaSopenharmony_ci# if ipv6 is used 135c87c5fbaSopenharmony_civpath %.c lwip/src/core/ipv6/ 136c87c5fbaSopenharmony_ciLWIP_SRC += mld6.c ip6.c icmp6.c ethip6.c nd6.c ip6_addr.c ip6_frag.c 137c87c5fbaSopenharmony_ci 138c87c5fbaSopenharmony_ciCN_LWIP_OBJ =$(patsubst %.c,lib-client/%.o,$(LWIP_SRC)) 139c87c5fbaSopenharmony_ciSN_LWIP_OBJ =$(patsubst %.c,lib-server/%.o,$(LWIP_SRC)) 140c87c5fbaSopenharmony_ciCD_LWIP_OBJ =$(patsubst %.c,lib-client-dtls/%.o,$(LWIP_SRC)) 141c87c5fbaSopenharmony_ciSD_LWIP_OBJ =$(patsubst %.c,lib-server-dtls/%.o,$(LWIP_SRC)) 142c87c5fbaSopenharmony_ci 143c87c5fbaSopenharmony_ci# coap library 144c87c5fbaSopenharmony_ci 145c87c5fbaSopenharmony_ciCFLAGS += -std=gnu99 146c87c5fbaSopenharmony_ci 147c87c5fbaSopenharmony_ciCFLAGS += -I$(libcoap_dir)/include 148c87c5fbaSopenharmony_ci 149c87c5fbaSopenharmony_civpath %.c $(libcoap_dir)/src 150c87c5fbaSopenharmony_ci 151c87c5fbaSopenharmony_ciCOAP_SRC = coap_address.c \ 152c87c5fbaSopenharmony_ci coap_asn1.c \ 153c87c5fbaSopenharmony_ci coap_async.c \ 154c87c5fbaSopenharmony_ci coap_block.c \ 155c87c5fbaSopenharmony_ci coap_cache.c \ 156c87c5fbaSopenharmony_ci coap_debug.c \ 157c87c5fbaSopenharmony_ci coap_dtls.c \ 158c87c5fbaSopenharmony_ci coap_encode.c \ 159c87c5fbaSopenharmony_ci coap_hashkey.c \ 160c87c5fbaSopenharmony_ci coap_io.c \ 161c87c5fbaSopenharmony_ci coap_io_lwip.c \ 162c87c5fbaSopenharmony_ci coap_layers.c \ 163c87c5fbaSopenharmony_ci coap_net.c \ 164c87c5fbaSopenharmony_ci coap_netif.c \ 165c87c5fbaSopenharmony_ci coap_notls.c \ 166c87c5fbaSopenharmony_ci coap_option.c \ 167c87c5fbaSopenharmony_ci coap_oscore.c \ 168c87c5fbaSopenharmony_ci coap_pdu.c \ 169c87c5fbaSopenharmony_ci coap_resource.c \ 170c87c5fbaSopenharmony_ci coap_session.c \ 171c87c5fbaSopenharmony_ci coap_subscribe.c \ 172c87c5fbaSopenharmony_ci coap_tinydtls.c \ 173c87c5fbaSopenharmony_ci coap_str.c \ 174c87c5fbaSopenharmony_ci coap_tcp.c \ 175c87c5fbaSopenharmony_ci coap_uri.c \ 176c87c5fbaSopenharmony_ci coap_ws.c 177c87c5fbaSopenharmony_ci 178c87c5fbaSopenharmony_ciCN_COAP_OBJ =$(patsubst %.c,lib-client/%.o,$(COAP_SRC)) 179c87c5fbaSopenharmony_ciSN_COAP_OBJ =$(patsubst %.c,lib-server/%.o,$(COAP_SRC)) 180c87c5fbaSopenharmony_ciCD_COAP_OBJ =$(patsubst %.c,lib-client-dtls/%.o,$(COAP_SRC)) 181c87c5fbaSopenharmony_ciSD_COAP_OBJ =$(patsubst %.c,lib-server-dtls/%.o,$(COAP_SRC)) 182c87c5fbaSopenharmony_ci 183c87c5fbaSopenharmony_ci# tinydtls library 184c87c5fbaSopenharmony_ci 185c87c5fbaSopenharmony_civpath %.c $(libcoap_dir)/ext/tinydtls $(libcoap_dir)/ext/tinydtls/sha2 $(libcoap_dir)/ext/tinydtls/aes $(libcoap_dir)/ext/tinydtls/ecc 186c87c5fbaSopenharmony_ci 187c87c5fbaSopenharmony_ciTINYDTLS_CFLAGS = -I. -I$(libcoap_dir)/ext -I$(libcoap_dir)/ext/tinydtls -DDTLSv12 -DWITH_SHA256 -DSHA2_USE_INTTYPES_H -DDTLS_CHECK_CONTENTTYPE -DCOAP_WITH_LIBTINYDTLS -DHAVE_DTLS_SET_LOG_HANDLER=1 188c87c5fbaSopenharmony_ci 189c87c5fbaSopenharmony_ciDTLS_SRC = dtls.c \ 190c87c5fbaSopenharmony_ci dtls_debug.c \ 191c87c5fbaSopenharmony_ci crypto.c \ 192c87c5fbaSopenharmony_ci dtls_time.c \ 193c87c5fbaSopenharmony_ci hmac.c \ 194c87c5fbaSopenharmony_ci sha2.c \ 195c87c5fbaSopenharmony_ci session.c \ 196c87c5fbaSopenharmony_ci peer.c \ 197c87c5fbaSopenharmony_ci netq.c \ 198c87c5fbaSopenharmony_ci rijndael_wrap.c \ 199c87c5fbaSopenharmony_ci rijndael.c \ 200c87c5fbaSopenharmony_ci ecc.c \ 201c87c5fbaSopenharmony_ci ccm.c \ 202c87c5fbaSopenharmony_ci dtls_prng.c 203c87c5fbaSopenharmony_ci 204c87c5fbaSopenharmony_ciCN_DTLS_OBJ =$(patsubst %.c,lib-client/%.o,$(DTLS_SRC)) 205c87c5fbaSopenharmony_ciSN_DTLS_OBJ =$(patsubst %.c,lib-server/%.o,$(DTLS_SRC)) 206c87c5fbaSopenharmony_ciCD_DTLS_OBJ =$(patsubst %.c,lib-client-dtls/%.o,$(DTLS_SRC)) 207c87c5fbaSopenharmony_ciSD_DTLS_OBJ =$(patsubst %.c,lib-server-dtls/%.o,$(DTLS_SRC)) 208c87c5fbaSopenharmony_ci 209c87c5fbaSopenharmony_ciCFLAGS += -g3 -Wall -Wextra -pedantic -O0 210c87c5fbaSopenharmony_ci 211c87c5fbaSopenharmony_ciCN_APP_OBJ =$(patsubst %.c,lib-client/%.o,client.c client-coap.c) 212c87c5fbaSopenharmony_ciSN_APP_OBJ =$(patsubst %.c,lib-server/%.o,server.c server-coap.c) 213c87c5fbaSopenharmony_ciCD_APP_OBJ =$(patsubst %.c,lib-client-dtls/%.o,client.c client-coap.c) 214c87c5fbaSopenharmony_ciSD_APP_OBJ =$(patsubst %.c,lib-server-dtls/%.o,server.c server-coap.c) 215c87c5fbaSopenharmony_ci 216c87c5fbaSopenharmony_ci 217c87c5fbaSopenharmony_ciCN_OBJS = ${CN_APP_OBJ} ${CN_LWIP_OBJ} ${CN_COAP_OBJ} 218c87c5fbaSopenharmony_ciSN_OBJS = ${SN_APP_OBJ} ${SN_LWIP_OBJ} ${SN_COAP_OBJ} 219c87c5fbaSopenharmony_ciCD_OBJS = ${CD_APP_OBJ} ${CD_LWIP_OBJ} ${CD_COAP_OBJ} ${CD_DTLS_OBJ} 220c87c5fbaSopenharmony_ciSD_OBJS = ${SD_APP_OBJ} ${SD_LWIP_OBJ} ${SD_COAP_OBJ} ${SD_DTLS_OBJ} 221c87c5fbaSopenharmony_ci 222c87c5fbaSopenharmony_ci$(coap_include_dir)/coap.h: 223c87c5fbaSopenharmony_ci @(if [ ! -f $(coap_include_dir)/coap.h ] ; then \ 224c87c5fbaSopenharmony_ci (cd $(libcoap_dir) ; ./autogen.sh ; ./configure --disable-dtls --disable-man) ; \ 225c87c5fbaSopenharmony_ci ${MAKE}; \ 226c87c5fbaSopenharmony_ci fi) 227c87c5fbaSopenharmony_ci 228c87c5fbaSopenharmony_ci${SN_OBJS} ${SD_OBJS}: $(coap_include_dir)/coap.h server-coap.h 229c87c5fbaSopenharmony_ci 230c87c5fbaSopenharmony_ciserver: ${SN_OBJS} 231c87c5fbaSopenharmony_ci $(CC) $(CFLAGS) ${SN_OBJS} -o server ${LDLIBS} 232c87c5fbaSopenharmony_ci 233c87c5fbaSopenharmony_ciserver-dtls: ${SD_OBJS} 234c87c5fbaSopenharmony_ci $(CC) $(CFLAGS) ${SD_OBJS} -o server-dtls ${LDLIBS} 235c87c5fbaSopenharmony_ci 236c87c5fbaSopenharmony_ci${CN_OBJS} ${CD_OBJS}: $(coap_include_dir)/coap.h client-coap.h 237c87c5fbaSopenharmony_ci 238c87c5fbaSopenharmony_ciclient: ${CN_OBJS} 239c87c5fbaSopenharmony_ci $(CC) $(CFLAGS) ${CN_OBJS} -o client ${LDLIBS} 240c87c5fbaSopenharmony_ci 241c87c5fbaSopenharmony_ciclient-dtls: ${CD_OBJS} 242c87c5fbaSopenharmony_ci $(CC) $(CFLAGS) ${CD_OBJS} -o client-dtls ${LDLIBS} 243c87c5fbaSopenharmony_ci 244c87c5fbaSopenharmony_cilib-server: 245c87c5fbaSopenharmony_ci @mkdir -p $@ 246c87c5fbaSopenharmony_ci 247c87c5fbaSopenharmony_cilib-server/%.o: %.c config/lwipopts.h config/lwippools.h config/coap_config.h 248c87c5fbaSopenharmony_ci $(CC) ${CFLAGS} -DCOAP_SERVER_SUPPORT -c $< -o $@ 249c87c5fbaSopenharmony_ci 250c87c5fbaSopenharmony_cilib-server-dtls: 251c87c5fbaSopenharmony_ci @mkdir -p $@ 252c87c5fbaSopenharmony_ci 253c87c5fbaSopenharmony_cilib-server-dtls/%.o: %.c config/lwipopts.h config/lwippools.h config/coap_config.h 254c87c5fbaSopenharmony_ci $(CC) ${CFLAGS} ${TINYDTLS_CFLAGS} -DCOAP_SERVER_SUPPORT -c $< -o $@ 255c87c5fbaSopenharmony_ci 256c87c5fbaSopenharmony_cilib-client: 257c87c5fbaSopenharmony_ci @mkdir -p $@ 258c87c5fbaSopenharmony_ci 259c87c5fbaSopenharmony_cilib-client/%.o: %.c config/lwipopts.h config/lwippools.h config/coap_config.h 260c87c5fbaSopenharmony_ci $(CC) ${CFLAGS} -DCOAP_CLIENT_SUPPORT -c $< -o $@ 261c87c5fbaSopenharmony_ci 262c87c5fbaSopenharmony_cilib-client-dtls: 263c87c5fbaSopenharmony_ci @mkdir -p $@ 264c87c5fbaSopenharmony_ci 265c87c5fbaSopenharmony_cilib-client-dtls/%.o: %.c config/lwipopts.h config/lwippools.h config/coap_config.h 266c87c5fbaSopenharmony_ci $(CC) ${CFLAGS} ${TINYDTLS_CFLAGS} -DCOAP_CLIENT_SUPPORT -c $< -o $@ 267c87c5fbaSopenharmony_ci 268c87c5fbaSopenharmony_ciclean: 269c87c5fbaSopenharmony_ci rm -rf server server-dtls client client-dtls \ 270c87c5fbaSopenharmony_ci ${CN_OBJS} ${SN_OBJS} ${CD_OBJS} ${SD_OBJS} \ 271c87c5fbaSopenharmony_ci lib-server lib-server-dtls lib-client lib-client-dtls 272c87c5fbaSopenharmony_ci 273c87c5fbaSopenharmony_ci.PHONY: all clean 274