Avoid build failures on recent distros

Emit a warning and continue when OpenSSL is newer than expected. The
chroot still uses an older version.

BUG=b:245993083, b:246328810
BRANCH=none
TEST=make -C ~/cosarm/src/platform/vboot_reference/ USE_FLASHROM=0
See that the errors become warnings

Signed-off-by: Simon Glass <sjg@chromium.org>
Change-Id: I85afba4007da3bc7c37abc04d744185c3362ad99
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3887562
Reviewed-by: Yu-Ping Wu <yupingso@chromium.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
diff --git a/Makefile b/Makefile
index 467b00a..5e239dd 100644
--- a/Makefile
+++ b/Makefile
@@ -288,6 +288,9 @@
   CROSID_LIBS := $(shell ${PKG_CONFIG} --libs crosid)
 endif
 
+# Get major version of openssl (e.g. version 3.0.5 -> "3")
+OPENSSL_VERSION := $(shell ${PKG_CONFIG} --modversion openssl | cut -d. -f1)
+
 # Determine QEMU architecture needed, if any
 ifeq (${ARCH},${HOST_ARCH})
   # Same architecture; no need for QEMU
@@ -456,6 +459,14 @@
 # Intermediate library for the vboot_reference utilities to link against.
 UTILLIB = ${BUILD}/libvboot_util.a
 
+# Avoid build failures outside the chroot on Ubuntu 2022.04
+# e.g.:
+# host/lib/host_key2.c:103:17: error: ‘RSA_free’ is deprecated: Since OpenSSL 3.0
+# [-Werror=deprecated-declarations]
+ifeq ($(OPENSSL_VERSION),3)
+${UTILLIB}: CFLAGS += -Wno-error=deprecated-declarations
+endif
+
 UTILLIB_SRCS = \
 	cgpt/cgpt_add.c \
 	cgpt/cgpt_boot.c \
@@ -690,6 +701,14 @@
 
 ${FUTIL_OBJS}: INCLUDES += -Ihost/lib21/include
 
+# Avoid build failures outside the chroot on Ubuntu 2022.04
+# e.g.:
+# futility/cmd_create.c:161:9: warning: ‘RSA_free’ is deprecated: Since OpenSSL 3.0
+# [-Wdeprecated-declarations]
+ifeq ($(OPENSSL_VERSION),3)
+${FUTIL_OBJS}: CFLAGS += -Wno-error=deprecated-declarations
+endif
+
 ALL_OBJS += ${FUTIL_OBJS}