# Commandline options

# To build updater-related targets, you need to set this option
AddOption(
    "--with-updater",
    dest="fullenv",
    action="store_true",
    help="Full firmware environment",
)

AddOption(
    "--options",
    dest="optionfile",
    type="string",
    nargs=1,
    action="store",
    default="fbt_options.py",
    help="Enviroment option file",
)

AddOption(
    "--extra-int-apps",
    action="store",
    dest="extra_int_apps",
    default="",
    help="List of applications to add to firmare's built-ins. Also see FIRMWARE_APP_SET and FIRMWARE_APPS",
)

AddOption(
    "--extra-ext-apps",
    action="store",
    dest="extra_ext_apps",
    default="",
    help="List of applications to forcefully build as standalone .elf",
)


# Construction environment variables

vars = Variables(GetOption("optionfile"), ARGUMENTS)

vars.AddVariables(
    BoolVariable(
        "VERBOSE",
        help="Print full commands",
        default=False,
    ),
    BoolVariable(
        "FORCE",
        help="Force target action (for supported targets)",
        default=False,
    ),
    BoolVariable(
        "DEBUG",
        help="Enable debug build",
        default=True,
    ),
    BoolVariable(
        "COMPACT",
        help="Optimize for size",
        default=False,
    ),
    EnumVariable(
        "TARGET_HW",
        help="Hardware target",
        default="7",
        allowed_values=[
            "7",
        ],
    ),
    BoolVariable(
        "DEBUG_TOOLS",
        help="Enable debug tools to be built",
        default=False,
    ),
)

vars.Add(
    "DIST_SUFFIX",
    help="Suffix for binaries in build output for dist targets",
    default="local",
)

vars.Add(
    "CUSTOM_FLIPPER_NAME",
    help="Replaces OTP flipper name with custom string of 8 chars",
    default="",
)

vars.Add(
    "UPDATE_VERSION_STRING",
    help="Version string for updater package",
    default="${DIST_SUFFIX}",
)


vars.Add(
    "COPRO_CUBE_VERSION",
    help="Cube version",
    default="",
)

vars.Add(
    "COPRO_STACK_ADDR",
    help="Core2 Firmware address",
    default="0",
)

vars.Add(
    "COPRO_STACK_BIN",
    help="Core2 Firmware file name",
    default="",
)

vars.Add(
    "COPRO_DISCLAIMER",
    help="Value to pass to bundling script to confirm dangerous operations",
    default="",
)

vars.AddVariables(
    PathVariable(
        "COPRO_OB_DATA",
        help="Path to OB reference data",
        validator=PathVariable.PathIsFile,
        default="",
    ),
    PathVariable(
        "COPRO_STACK_BIN_DIR",
        help="Path to ST-provided stacks",
        validator=PathVariable.PathIsDir,
        default="",
    ),
    PathVariable(
        "COPRO_CUBE_DIR",
        help="Path to Cube root",
        validator=PathVariable.PathIsDir,
        default="",
    ),
    EnumVariable(
        "COPRO_STACK_TYPE",
        help="Core2 stack type",
        default="ble_light",
        allowed_values=[
            "ble_full",
            "ble_light",
            "ble_basic",
        ],
    ),
    PathVariable(
        "SVD_FILE",
        help="Path to SVD file",
        validator=PathVariable.PathIsFile,
        default="",
    ),
    PathVariable(
        "OTHER_ELF",
        help="Path to prebuilt ELF file to debug",
        validator=PathVariable.PathAccept,
        default="",
    ),
)

vars.Add(
    "FBT_TOOLCHAIN_VERSIONS",
    help="Whitelisted toolchain versions (leave empty for no check)",
    default=tuple(),
)

vars.Add(
    "OPENOCD_OPTS",
    help="Options to pass to OpenOCD",
    default="",
)

vars.Add(
    "BLACKMAGIC",
    help="Blackmagic probe location",
    default="auto",
)

vars.Add(
    "UPDATE_SPLASH",
    help="Directory name with slideshow frames to render after installing update package",
    default="update_default",
)

vars.Add(
    "LOADER_AUTOSTART",
    help="Application name to automatically run on Flipper boot",
    default="",
)


vars.Add(
    "FIRMWARE_APPS",
    help="Map of (configuration_name->application_list)",
    default={
        "default": (
            # Svc
            "basic_services",
            # Apps
            "main_apps",
            "system_apps",
            # Settings
            "settings_apps",
            # Plugins
            # "basic_plugins",
            # Debug
            # "debug_apps",
        )
    },
)

vars.Add(
    "FIRMWARE_APP_SET",
    help="Application set to use from FIRMWARE_APPS",
    default="default",
)

vars.Add(
    "APPSRC",
    help="Application source directory for app to build & upload",
    default="",
)

# List of tuples (directory, add_to_global_include_path)
vars.Add(
    "APPDIRS",
    help="Directories to search for firmware components & external apps",
    default=[
        ("applications", False),
        ("applications/services", True),
        ("applications/main", True),
        ("applications/settings", False),
        ("applications/system", False),
        ("applications/debug", False),
        ("applications/plugins", False),
        ("applications_user", False),
    ],
)

Return("vars")
