Also search config.h near the script
By default, this script looks for include/mbedtls/config.h relative to
the current directory. This allows running config.py from outside the
build tree.
To support out-of-tree builds where config.h and config.py are in the
source tree and the current directory is in the build tree, also try
DIRECTORY_CONTAINING_SCRIPT/../include/mbedtls/config.h, and the
equivalent with symbolic links traversed.
diff --git a/scripts/config.py b/scripts/config.py
index 1a2b159..aaea484 100755
--- a/scripts/config.py
+++ b/scripts/config.py
@@ -24,6 +24,7 @@
##
## This file is part of Mbed TLS (https://tls.mbed.org)
+import os
import re
class Setting:
@@ -237,12 +238,20 @@
and modify the configuration.
"""
- default_path = 'include/mbedtls/config.h'
+ _path_in_tree = 'include/mbedtls/config.h'
+ default_path = [_path_in_tree,
+ os.path.join(os.path.dirname(__file__),
+ os.pardir,
+ _path_in_tree),
+ os.path.join(os.path.dirname(os.path.abspath(os.path.dirname(__file__))),
+ _path_in_tree)]
def __init__(self, filename=None):
"""Read the Mbed TLS configuration file."""
if filename is None:
- filename = self.default_path
+ for filename in self.default_path:
+ if os.path.lexists(filename):
+ break
super().__init__()
self.filename = filename
self.current_section = 'header'