From dc020f256953bee52be1975387fc2c2a568d0855 Mon Sep 17 00:00:00 2001 From: orbea Date: Fri, 14 Dec 2018 13:56:58 -0800 Subject: [PATCH] qb: Support building with the system mbedtls. Fixes https://github.com/libretro/RetroArch/issues/7639 v2: Fix build failures with griffin. --- Makefile.common | 10 +++--- Makefile.ctr | 2 +- griffin/griffin.c | 2 ++ libretro-common/net/net_socket_ssl.c | 12 +++++++ pkg/apple/RetroArch.xcodeproj/project.pbxproj | 2 ++ qb/config.libs.sh | 32 +++++++++++++++++++ qb/config.params.sh | 5 +-- 7 files changed, 58 insertions(+), 7 deletions(-) diff --git a/Makefile.common b/Makefile.common index 40f94009ba..d504420eb8 100644 --- a/Makefile.common +++ b/Makefile.common @@ -394,10 +394,9 @@ ifeq ($(HAVE_LIBRETRODB), 1) endif ifneq ($(C89_BUILD), 1) - HAVE_GTKPLUS = 0 - - ifeq ($(HAVE_SSL), 1) - ifeq ($(HAVE_NETWORKING), 1) + ifeq ($(HAVE_NETWORKING), 1) + ifeq ($(HAVE_BUILTINMBEDTLS), 1) + HAVE_SSL = 1 DEFINES += -DHAVE_SSL ifeq ($(DEBUG), 1) @@ -482,6 +481,9 @@ ifneq ($(C89_BUILD), 1) deps/mbedtls/ssl_tls.o OBJ += $(OBJS_TLS_CRYPTO) $(OBJS_TLS_X509) $(OBJS_TLS) + else ifeq ($(HAVE_SSL), 1) + DEFINES += -DHAVE_SSL + LIBS += $(MBEDTLS_LIBS) $(MBEDX509_LIBS) $(MBEDCRYPTO_LIBS) endif endif endif diff --git a/Makefile.ctr b/Makefile.ctr index 2427e235cc..7080b7fb9c 100644 --- a/Makefile.ctr +++ b/Makefile.ctr @@ -53,7 +53,7 @@ ifeq ($(GRIFFIN_BUILD), 1) DEFINES += -DHAVE_GRIFFIN=1 -DHAVE_MENU -DHAVE_RGUI -DHAVE_XMB -DHAVE_MATERIALUI -DHAVE_LIBRETRODB -DHAVE_CC_RESAMPLER DEFINES += -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_RBMP -DHAVE_RTGA -DWANT_ZLIB #DEFINES += -DHAVE_NETWORKING -DHAVE_CHEEVOS -DRC_DISABLE_LUA -DHAVE_SOCKET_LEGACY -DHAVE_THREADS - #-DHAVE_SSL -DMBEDTLS_SSL_DEBUG_ALL + #-DHAVE_SSL -DHAVE_BUILTINMBEDTLS -DMBEDTLS_SSL_DEBUG_ALL #ssl is currently incompatible with griffin due to use of the "static" flag on repeating functions that will conflict when included in one file else HAVE_CC_RESAMPLER = 1 diff --git a/griffin/griffin.c b/griffin/griffin.c index d057b0a8f2..4589cafc12 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -1466,6 +1466,7 @@ SSL ============================================================ */ #if defined(HAVE_SSL) #if defined(HAVE_NETWORKING) +#if defined(HAVE_BUILTINMBEDTLS) #include "../deps/mbedtls/aes.c" #include "../deps/mbedtls/aesni.c" #include "../deps/mbedtls/arc4.c" @@ -1543,3 +1544,4 @@ SSL #include "../libretro-common/net/net_socket_ssl.c" #endif #endif +#endif diff --git a/libretro-common/net/net_socket_ssl.c b/libretro-common/net/net_socket_ssl.c index 04e0babad1..056e159284 100644 --- a/libretro-common/net/net_socket_ssl.c +++ b/libretro-common/net/net_socket_ssl.c @@ -25,6 +25,7 @@ #include #include +#if defined(HAVE_BUILTINMBEDTLS) #include "../../deps/mbedtls/mbedtls/config.h" #include "../../deps/mbedtls/mbedtls/certs.h" #include "../../deps/mbedtls/mbedtls/debug.h" @@ -33,7 +34,18 @@ #include "../../deps/mbedtls/mbedtls/ssl.h" #include "../../deps/mbedtls/mbedtls/ctr_drbg.h" #include "../../deps/mbedtls/mbedtls/entropy.h" +#else +#include +#include +#include +#include +#include +#include +#include +#include +#endif +/* Not part of the mbedtls upstream source */ #include "../../deps/mbedtls/cacert.h" #define DEBUG_LEVEL 0 diff --git a/pkg/apple/RetroArch.xcodeproj/project.pbxproj b/pkg/apple/RetroArch.xcodeproj/project.pbxproj index 4ecdb6839c..2c9be52f51 100644 --- a/pkg/apple/RetroArch.xcodeproj/project.pbxproj +++ b/pkg/apple/RetroArch.xcodeproj/project.pbxproj @@ -503,6 +503,7 @@ OTHER_CFLAGS = ( "-DHAVE_RUNAHEAD", "-DHAVE_SSL", + "-DHAVE_BUILTINMBEDTLS", "-DHAVE_GRIFFIN", "-DHAVE_FLAC", "-DHAVE_DR_FLAC", @@ -568,6 +569,7 @@ OTHER_CFLAGS = ( "-DHAVE_RUNAHEAD", "-DHAVE_SSL", + "-DHAVE_BUILTINMBEDTLS", "-DHAVE_GRIFFIN", "-DHAVE_FLAC", "-DHAVE_DR_FLAC", diff --git a/qb/config.libs.sh b/qb/config.libs.sh index 9542d643ab..7287d712c3 100644 --- a/qb/config.libs.sh +++ b/qb/config.libs.sh @@ -214,6 +214,7 @@ else HAVE_NETWORKGAMEPAD='no' HAVE_CHEEVOS='no' HAVE_DISCORD='no' + HAVE_SSL='no' fi check_lib '' STDIN_CMD "$CLIB" fcntl @@ -315,6 +316,37 @@ fi check_pkgconf FLAC flac check_val '' FLAC '-lFLAC' +if [ "$HAVE_SSL" = 'no' ]; then + HAVE_BUILTINMBEDTLS=no +fi + +if [ "$HAVE_SSL" != 'no' ]; then + check_header MBEDTLS \ + mbedtls/config.h \ + mbedtls/certs.h \ + mbedtls/debug.h \ + mbedtls/platform.h \ + mbedtls/net_sockets.h \ + mbedtls/ssl.h \ + mbedtls/ctr_drbg.h \ + mbedtls/entropy.h + + check_lib '' MBEDTLS -lmbedtls + check_lib '' MBEDX509 -lmbedx509 + check_lib '' MBEDCRYPTO -lmbedcrypto + + if [ "$HAVE_MBEDTLS" = 'no' ] || + [ "$HAVE_MBEDX509" = 'no' ] || + [ "$HAVE_MBEDCRYPTO" = 'no' ]; then + if [ "$HAVE_BUILTINMBEDTLS" != 'yes' ]; then + die : 'Notice: System mbedtls libraries not found, disabling SSL support.' + HAVE_SSL=no + fi + else + HAVE_SSL=yes + fi +fi + check_pkgconf LIBUSB libusb-1.0 1.0.13 check_val '' LIBUSB -lusb-1.0 libusb-1.0 diff --git a/qb/config.params.sh b/qb/config.params.sh index 9c1f3d7ef3..545af55b73 100644 --- a/qb/config.params.sh +++ b/qb/config.params.sh @@ -15,8 +15,9 @@ HAVE_STRIPES=no # Stripes menu HAVE_ZARCH=no # Zarch menu HAVE_NUKLEAR=no # Nuklear menu HAVE_RUNAHEAD=yes # Runahead support -HAVE_SSL=yes # SSL/mbedtls support -C89_SSL=no +HAVE_SSL=auto # SSL/mbedtls support +C89_SSL=no +HAVE_BUILTINMBEDTLS=yes # Bake in the mbedtls library HAVE_OVERLAY=yes # Overlay support HAVE_DYNAMIC=yes # Dynamic loading of libretro library HAVE_SDL=auto # SDL support