From e25532d8ddff288a9ce6b7026b060b3a90ad5182 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 8 Sep 2024 16:49:08 +1000 Subject: [PATCH] waf: allow any custom build option to be specified in waf configure this makes it easy to configure with any option from build_options.py --- Tools/ardupilotwaf/boards.py | 19 +++++++++++-------- Tools/scripts/build_options.py | 16 ++++++++++++---- wscript | 31 ++++++++++++++++--------------- 3 files changed, 39 insertions(+), 27 deletions(-) diff --git a/Tools/ardupilotwaf/boards.py b/Tools/ardupilotwaf/boards.py index 3d8ac2f20856cd..dbc36967671627 100644 --- a/Tools/ardupilotwaf/boards.py +++ b/Tools/ardupilotwaf/boards.py @@ -16,6 +16,7 @@ # modify our search path: sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../libraries/AP_HAL_ChibiOS/hwdef/scripts')) import chibios_hwdef +import build_options class BoardMeta(type): def __init__(cls, name, bases, dct): @@ -159,8 +160,16 @@ def srcpath(path): ) cfg.msg("Enabled custom controller", 'no', color='YELLOW') - if cfg.options.enable_ppp: - env.CXXFLAGS += ['-DAP_NETWORKING_BACKEND_PPP=1'] + # support enabling any option in build_options.py + for opt in build_options.BUILD_OPTIONS: + enable_option = opt.config_option().replace("-","_") + disable_option = "disable_" + enable_option[len("enable-"):] + if getattr(cfg.options, enable_option, False): + env.CXXFLAGS += ['-D%s=1' % opt.define] + cfg.msg("Enabled %s" % opt.label, 'yes', color='GREEN') + elif getattr(cfg.options, disable_option, False): + env.CXXFLAGS += ['-D%s=0' % opt.define] + cfg.msg("Enabled %s" % opt.label, 'no', color='GREEN') if cfg.options.disable_networking: env.CXXFLAGS += ['-DAP_NETWORKING_ENABLED=0'] @@ -487,12 +496,6 @@ def configure_env(self, cfg, env): # We always want to use PRI format macros cfg.define('__STDC_FORMAT_MACROS', 1) - if cfg.options.enable_ekf2: - env.CXXFLAGS += ['-DHAL_NAVEKF2_AVAILABLE=1'] - - if cfg.options.disable_ekf3: - env.CXXFLAGS += ['-DHAL_NAVEKF3_AVAILABLE=0'] - if cfg.options.postype_single: env.CXXFLAGS += ['-DHAL_WITH_POSTYPE_DOUBLE=0'] diff --git a/Tools/scripts/build_options.py b/Tools/scripts/build_options.py index 65f111c8a4e7af..7e2e37d1334ffb 100644 --- a/Tools/scripts/build_options.py +++ b/Tools/scripts/build_options.py @@ -15,21 +15,29 @@ def __init__(self, define, description, default, - dependency): + dependency, + configure_option=None): self.category = category self.label = label self.define = define self.description = description self.default = default self.dependency = dependency + self.configure_option = configure_option + + def config_option(self): + conf_option = self.configure_option + if conf_option is None: + conf_option = "enable-" + self.label.replace(" ", "-") + return conf_option # list of build options to offer NOTE: the dependencies must be # written as a single string with commas and no spaces, # eg. 'dependency1,dependency2' BUILD_OPTIONS = [ - Feature('AHRS', 'EKF3', 'HAL_NAVEKF3_AVAILABLE', 'Enable EKF3', 1, None), - Feature('AHRS', 'EKF2', 'HAL_NAVEKF2_AVAILABLE', 'Enable EKF2', 0, None), + Feature('AHRS', 'EKF3', 'HAL_NAVEKF3_AVAILABLE', 'Enable EKF3', 1, None, "enable-ekf3"), + Feature('AHRS', 'EKF2', 'HAL_NAVEKF2_AVAILABLE', 'Enable EKF2', 0, None, "enable-ekf2"), Feature('AHRS', 'AHRS_EXT', 'HAL_EXTERNAL_AHRS_ENABLED', 'Enable External AHRS', 0, None), Feature('AHRS', 'MicroStrain5', 'AP_EXTERNAL_AHRS_MICROSTRAIN5_ENABLED', 'Enable MICROSTRAIN 5-series External AHRS', 0, "AHRS_EXT"), # noqa: E501 Feature('AHRS', 'MicroStrain7', 'AP_EXTERNAL_AHRS_MICROSTRAIN7_ENABLED', 'Enable MICROSTRAIN 7-series External AHRS', 0, "AHRS_EXT"), # noqa: E501 @@ -413,7 +421,7 @@ def __init__(self, Feature('Filesystem', 'FILESYSTEM_SYS', 'AP_FILESYSTEM_SYS_ENABLED', 'Enable @SYS/ filesystem', 0, None), Feature('Filesystem', 'APJ_TOOL_PARAMETERS', 'FORCE_APJ_DEFAULT_PARAMETERS', 'Enable apj_tool parameter area', 0, None), - Feature('Networking', 'PPP Support', 'AP_NETWORKING_BACKEND_PPP', 'Enable PPP networking', 0, None), + Feature('Networking', 'PPP Support', 'AP_NETWORKING_BACKEND_PPP', 'Enable PPP networking', 0, None, "enable-ppp"), Feature('DroneCAN', 'DroneCAN', 'HAL_ENABLE_DRONECAN_DRIVERS', 'Enable DroneCAN support', 0, None), ] diff --git a/wscript b/wscript index 3d4012787ea5f6..c90606ba5a36a3 100644 --- a/wscript +++ b/wscript @@ -10,10 +10,12 @@ import subprocess import json import fnmatch sys.path.insert(0, 'Tools/ardupilotwaf/') +sys.path.insert(0, 'Tools/scripts/') import ardupilotwaf import boards import shutil +import build_options from waflib import Build, ConfigSet, Configure, Context, Utils from waflib.Configure import conf @@ -204,11 +206,6 @@ def options(opt): default=False, help='enable OS level thread statistics.') - g.add_option('--enable-ppp', - action='store_true', - default=False, - help='enable PPP networking.') - g.add_option('--bootloader', action='store_true', default=False, @@ -388,16 +385,6 @@ configuration in order to save typing. default=False, help='Use flash storage emulation.') - g.add_option('--enable-ekf2', - action='store_true', - default=False, - help='Configure with EKF2.') - - g.add_option('--disable-ekf3', - action='store_true', - default=False, - help='Configure without EKF3.') - g.add_option('--ekf-double', action='store_true', default=False, @@ -446,6 +433,20 @@ configuration in order to save typing. action='store_true', default=False, help='enables checking of new to ensure NEW_NOTHROW is used') + + # support enabling any option in build_options.py + for opt in build_options.BUILD_OPTIONS: + enable_option = "--" + opt.config_option() + disable_option = enable_option.replace("--enable", "--disable") + g.add_option(enable_option, + action='store_true', + default=False, + help='enable %s' % opt.label) + g.add_option(disable_option, + action='store_true', + default=False, + help='disable %s' % opt.label) + def _collect_autoconfig_files(cfg): for m in sys.modules.values():