nuttx-apps/crypto/mbedtls/Makefile
zhanghongyu b883eb5929 mbedtls: fix build error when libcxx is enabled.
if  !defined(unix) && !defined(__unix) && !defined(__unix__) && \
    !defined(__APPLE__) && !defined(_WIN32) && !defined(__QNXNTO__) && \
    !defined(__HAIKU__) && !defined(__midipix__)
error
   "Platform entropy sources only work on Unix and Windows, see MBEDTLS_NO_PLATFORM_ENTROPY in mbedtls_config.h"

nuttx/libs/libxx/libcxx/include/__config
nuttx/libs/libxx/libcxx/include/limits.h:40,
apps/crypto/mbedtls/mbedtls/include/mbedtls/check_config.h:31,
apps/crypto/mbedtls/mbedtls/include/mbedtls/build_info.h:151,
apps/crypto/mbedtls/mbedtls/library/common.h:26,
apps/crypto/mbedtls/mbedtls/library/entropy_poll.c:25

if defined(__NuttX__)
undef __linux__
undef __APPLE__
undef __FreeBSD__
undef __GLIBC__
undef __NetBSD__
undef _WIN32
undef __sun__
undef _AIX
/ For the current use of the __unix__ macro in this library,
/ NuttX is not __unix__.
/ This might need to be revisited in future.
undef __unix__
endif

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-08-22 01:27:59 +08:00

141 lines
4.1 KiB
Makefile

############################################################################
# apps/crypto/mbedtls/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(APPDIR)/Make.defs
# Mbed TLS crypto library
# Set up build configuration and environment
MBEDTLS_URL ?= "https://github.com/ARMmbed/mbedtls/archive"
MBEDTLS_VERSION = $(patsubst "%",%,$(strip $(CONFIG_MBEDTLS_VERSION)))
MBEDTLS_ZIP = v$(MBEDTLS_VERSION).zip
MBEDTLS_UNPACKNAME = mbedtls
UNPACK ?= unzip -q -o
MBEDTLS_UNPACKLIBDIR = $(MBEDTLS_UNPACKNAME)$(DELIM)library
MBEDTLS_UNPACKPROGDIR = $(MBEDTLS_UNPACKNAME)$(DELIM)programs
# This lets Mbed TLS better use some of the POSIX features we have
CFLAGS += ${DEFINE_PREFIX}unix
mbedtls/library/bignum.c_CFLAGS += -fno-lto
# Build break on Assemble compiler if -fno-omit-frame-pointer and -O3 enabled at same time
# {standard input}: Assembler messages:
# {standard input}:2560: Error: branch out of range
# make[2]: *** [apps/Application.mk:170: mbedtls/library/sha256.o] Error 1
ifeq ($(CONFIG_FRAME_POINTER),y)
ifeq ($(CONFIG_DEBUG_OPTLEVEL),"-O3")
mbedtls/library/sha256.c_CFLAGS += -O2
mbedtls/library/cmac.c_CFLAGS += -O2
endif
endif
ifeq ($(CONFIG_ARCH_SIM),y)
CFLAGS += -O0
endif
CSRCS = $(wildcard $(MBEDTLS_UNPACKLIBDIR)$(DELIM)*.c)
$(MBEDTLS_ZIP):
@echo "Downloading: $(MBEDTLS_URL)/$(MBEDTLS_ZIP)"
$(Q) curl -O -L $(MBEDTLS_URL)/$(MBEDTLS_ZIP)
$(MBEDTLS_UNPACKNAME): $(MBEDTLS_ZIP)
@echo "Unpacking: $(MBEDTLS_ZIP) -> $(MBEDTLS_UNPACKNAME)"
$(Q) $(UNPACK) $(MBEDTLS_ZIP)
$(Q) mv mbedtls-$(MBEDTLS_VERSION) $(MBEDTLS_UNPACKNAME)
$(Q) patch -p1 -d $(MBEDTLS_UNPACKNAME) < 0001-mbedtls-entropy_poll-use-getrandom-to-get-the-system.patch
$(Q) patch -p1 -d $(MBEDTLS_UNPACKNAME) < 0002-mbedtls-add-mbedtls-x509-crt-pool.patch
$(Q) touch $(MBEDTLS_UNPACKNAME)
# Download and unpack tarball if no git repo found
ifeq ($(wildcard $(MBEDTLS_UNPACKNAME)/.git),)
context:: $(MBEDTLS_UNPACKNAME)
distclean::
$(call DELDIR, $(MBEDTLS_UNPACKNAME))
$(call DELFILE, $(MBEDTLS_ZIP))
endif
# Configuration Applications
ifneq ($(CONFIG_MBEDTLS_APPS),)
MODULE = $(CONFIG_MBEDTLS_APPS)
ifeq ($(CONFIG_MBEDTLS_APP_BENCHMARK),y)
PROGNAME += $(CONFIG_MBEDTLS_APP_BENCHMARK_PROGNAME)
PRIORITY += $(CONFIG_MBEDTLS_APP_BENCHMARK_PRIORITY)
STACKSIZE += $(CONFIG_MBEDTLS_APP_BENCHMARK_STACKSIZE)
MAINSRC += $(MBEDTLS_UNPACKPROGDIR)/test/benchmark.c
endif
ifeq ($(CONFIG_MBEDTLS_APP_SELFTEST),y)
PROGNAME += $(CONFIG_MBEDTLS_APP_SELFTEST_PROGNAME)
PRIORITY += $(CONFIG_MBEDTLS_APP_SELFTEST_PRIORITY)
STACKSIZE += $(CONFIG_MBEDTLS_APP_SELFTEST_STACKSIZE)
MAINSRC += $(MBEDTLS_UNPACKPROGDIR)/test/selftest.c
endif
endif
# Configuration alternative implementation
ifeq ($(CONFIG_MBEDTLS_ENTROPY_HARDWARE_ALT),y)
CSRCS += $(APPDIR)/crypto/mbedtls/source/entropy_alt.c
endif
ifeq ($(CONFIG_MBEDTLS_ALT),y)
CSRCS += $(APPDIR)/crypto/mbedtls/source/dev_alt.c
ifeq ($(CONFIG_MBEDTLS_AES_ALT),y)
CSRCS += $(APPDIR)/crypto/mbedtls/source/aes_alt.c
endif
ifeq ($(CONFIG_MBEDTLS_MD5_ALT),y)
CSRCS += $(APPDIR)/crypto/mbedtls/source/md5_alt.c
endif
ifeq ($(CONFIG_MBEDTLS_SHA1_ALT),y)
CSRCS += $(APPDIR)/crypto/mbedtls/source/sha1_alt.c
endif
ifeq ($(CONFIG_MBEDTLS_SHA256_ALT),y)
CSRCS += $(APPDIR)/crypto/mbedtls/source/sha256_alt.c
endif
ifeq ($(CONFIG_MBEDTLS_SHA512_ALT),y)
CSRCS += $(APPDIR)/crypto/mbedtls/source/sha512_alt.c
endif
endif
include $(APPDIR)/Application.mk