Custom build scripts in mbed CLI

11 Aug 2016

With mbed OS 2, we had Yotta, which used CMake for builds. We were able to write our own .cmake scripts to add to the build process or overwrite the entire CMakeLists.txt for a fully custom build. And for simpler things like adding include folders or excluding certain files, you could make simple edits to the module.json file and add .yotta-ignore files.

Is such customization still available mbed OS 5? With the mbed CLI, is there still a way to specify ignored files or extra files to build, or extra include folders, or even custom compiler flags and other complex customizations? These options might be unnecessary for simple blinky-type apps, but they are sometimes needed for more complicated programs and libraries that have to be portable to multiple boards/environments.

11 Aug 2016

Looks like there is an equivalent of .yotta_ignore, .mbedignore: https://docs.mbed.com/docs/mbed-os-api/en/mbed-os-5.1.0/api/md_docs_ignoring_files_from_build.html.

The mbed-os library uses a set of Python scripts to implement the default mbed CLI build system: https://developer.mbed.org/handbook/mbed-tools. I haven't yet seen documentation on how to customize the system, but I would guess that it allows custom python scripts to be added to a library or program. I'll continue to explore.

12 Aug 2016

@Aaron Campbell:"I'll continue to explore."

Thank you for your exploration. I have applications developed with Mbed library version 2. I would like to move to version 5 but I have the same problem with the Makefile customization. Currently I use remote compiler to export blinky example application to GCC and then modify exported Makefile. Maybe the same process can be used for version 5.

12 Aug 2016

Well, I have not been able to find any way to customize the build system with additional scripts. There is a configuration system that allows you to define C macros (https://docs.mbed.com/docs/mbedmicro-api/en/latest/config_system/), and there is the .mbedignore file that I mentioned before. But I don't see any way to do the following:

  • Include source files that are in a separate directory (e.g. an application with a "yotta_project" folder for mbed OS 2 builds, an "mbed_cli_project" for mbed OS 5 builds, and a "source" folder with the source code)
  • Add an include folder from somewhere else on the host system.
  • Add a GCC compiler flag if compiling with GCC; etc
  • Perform further actions (e.g. copy or move files) before or after building

However, @Henryk Szal, there is still an option to export to Makefile, using the command mbed export -i gcc_arm. And of course a Makefile project can do all of the above.

16 Aug 2016

We're working on a way to pass options to the compiler through mbed-cli. That should help with most problems I guess. I'm running into the same issues :-)

24 Aug 2016

I cannot seem to find my source, but there is a command line option to the compile command (to mbed) that allows you to specify an additional source location.

$ mbed compile --source=/your/path

Other options to `compile` include:

$ mbed compile ?
usage: make.py [-h] [-m MCU] [-t TOOLCHAIN] [--color] [--cflags CFLAGS]
               [--asmflags ASMFLAGS] [--ldflags LDFLAGS] [-c] [-o OPTIONS]
               [-p PROGRAM] [-n PROGRAM] [-j JOBS] [-v] [--silent] [-D MACROS]
               [-S] [-f GENERAL_FILTER_REGEX] [--automated] [--host HOST_TEST]
               [--extra EXTRA] [--peripherals PERIPHERALS]
               [--dep DEPENDENCIES] [--source SOURCE_DIR]
               [--duration DURATION] [--build BUILD_DIR] [-N ARTIFACT_NAME]
               [-d DISK] [-s SERIAL] [-b BAUD] [-L] [--rtos] [--rpc] [--eth]
               [--usb_host] [--usb] [--dsp] [--fat] [--ublox] [--testlib]
               [-l LINKER_SCRIPT]