modules: mbedtls: support extracting __FILE__ basename at buildtime

So far there was a runtime basename extraction of filenames passed to
mbedTLS debug hook. This has both runtime penalty as well as code size
penalty.

Introduce a buildtime support of extracting basename of source filenames
logged using logging subsystem, so that there is no need to do it at
runtime.

Provide Kconfig options for both buildtime and runtime basename extraction,
as in some cases the buildtime basename extraction might not work,
depending on toolchain used for building Zephyr. Default to buildtime when
using Zephyr SDK, as that is proven to work. Use runtime basename
extraction in other cases (other toolchains used).

This saves approximately 204 bytes of code footprint for sample
application with native TLS sockets built for nRF52840.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
diff --git a/modules/mbedtls/debug.c b/modules/mbedtls/debug.c
index 3a1a478..3b2ede3 100644
--- a/modules/mbedtls/debug.c
+++ b/modules/mbedtls/debug.c
@@ -12,7 +12,7 @@
 
 void zephyr_mbedtls_debug(void *ctx, int level, const char *file, int line, const char *str)
 {
-	const char *p, *basename;
+	const char *p, *basename = file;
 
 	ARG_UNUSED(ctx);
 
@@ -21,9 +21,11 @@
 	}
 
 	/* Extract basename from file */
-	for (p = basename = file; *p != '\0'; p++) {
-		if (*p == '/' || *p == '\\') {
-			basename = p + 1;
+	if (IS_ENABLED(CONFIG_MBEDTLS_DEBUG_EXTRACT_BASENAME_AT_RUNTIME)) {
+		for (p = basename = file; *p != '\0'; p++) {
+			if (*p == '/' || *p == '\\') {
+				basename = p + 1;
+			}
 		}
 	}