Skip to content

Conversation

@gilles-peskine-arm
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm commented Mar 10, 2021

This is a script to generate a Makefile for Mbed TLS or Mbed Crypto.

Salient features:

  • Correct dependency support. (Overeager, actually, but in a way that mostly shouldn't hurt.)
  • Supports both in-tree and out-of-tree builds.
  • Supports a different configuration in each build directory. The configuration can be defined either by copying and modifying the source config.h or as options to (un)set from whatever the source config.h is at build time.
  • Supports both Mbed TLS and Mbed Crypto development as well as the LTS branches.
  • Portable make (no reliance on GNU make). No recursive make.
  • As fast as make (and not slow like our cmakefiles).
  • Presets: mbedtls-prepare-build -p xxx creates a directory build-xxx with a commonly used configuration/build-flags/platform combination (run mbedtls-prepare-build --help for a list).
  • Run make V=1 to see what commands get executed.
  • Run make help to see the main available targets (in addition to all individual files).
  • Zsh completion function available in Zsh completion functions #9.

Sample usage:

scripts/mbedtls-prepare-build -d build-debug --cflags='-O0 -g3'
scripts/mbedtls-prepare-build -d build-full --config-name=full --cflags=-fsanitize=address
scripts/mbedtls-prepare-build -d build-restartable --config-set=MBEDTLS_ECP_RESTARTABLE
make -C build-debug & make -C build-full & make -C build-restartable
make -C build-debug tests/test_suite_ecp.run

Known limitations:

  • Probably breaks on Windows due to backslashes vs slashes.
  • Doesn't support all the existing makefile targets (yet).
  • Lacks a userguide-level documentation.

Create a build directory with subdirectories and symlinks.
Generate a makefile.

Collect dependencies by running `cpp -MM`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Create a build directory with subdirectories and symlinks.
Generate a makefile.

Collect dependencies by looking for #include directives without
consideration for the current configuration, so that the resulting
makefile doesn't need to be regenerated when the configuration
changes.

Work in progress. Test dependencies are wrong for submodules.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Create a build directory with subdirectories and symlinks.
Generate a makefile to build the library, sample programs and unit
tests.

Support both in-tree and out-of-tree builds.

Collect dependencies by looking for #include directives without
consideration for the current configuration, so that the resulting
makefile doesn't need to be regenerated when the configuration
changes.

Support changing the configuration when creating the build directory.
This can be done either by copying the configuration file and
modifying it, or by including the original configuratiom and modifying
it through additional #define and #undef.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Add support for presets, which set default values for certain options.
This allows creating a build directory for a commonly-used target by
passing a single command line option.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Document variables that can be set on the command line (make help-variables).

Document targets tests/test_suite_%.run and tests/test_suite_%.valgrind.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
The generated makefile compiles the unit tests from the root
directory. This has the advantage of not requiring different
paths (-I, -L). For the unit tests, unfortunately, this results in
incorrect debugging information for the common .function files that
get pulled in via the test generator rather than an #include
directive. For these files, the .c file to compile contains #line
directives with a path that's relative to the tests directory, and
therefore the debugging data lists them as e.g.
`.../build/suites/main_test.function` rather than
`.../source/tests/suites/main_test.function`.

As a workaround, create a symbolic link .../build/suites that points
to the correct directory. In fact, this is only the correct directory
if the test doesn't come from a submodule, so this is only a partial
workaround.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Simpler interface that lists the libraries for each program. Fixes at
least cert_app.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
When running tests, pass $(RUN) before the executable and $(RUNS)
afterwards. This allows executing tests via a runtime analysis tool
and passing extra arguments to the tool.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
These programs need to be linked with onefile.o.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Don't try to recover: this can mask errors. We're doing this correctly
in CMakeLists.txt but I hadn't copied that option.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Work around a double definition of a type due to the double includion
of check_config.h in config-mode=incude. This allows the build to pass
in strict c99 compliant mode (it worked before in gcc and clang).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Fix a bug in dependency analysis whereby if file A was first noticed
as a dependency of B, it could end up being considered a dependency of
itself.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This is work in progress. You need to manually pass -fPIC when
compiling the object files, otherwise the ld step will fail.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
It's only used in this class, and it will soon need to have access to
other methods in that class.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Support building tests with include files in tests/include and common
code in tests/src/*.c, as added in Mbed TLS 2.23.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Fix out-of-tree builds when there's an incompatible version of the
generated file in the source tree.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Run the program (assumed to be compiled with profiling support) and
save its profiling data.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This is very preliminary, like the work on driver wrapper generation.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Copy link
Contributor

@tom-daubney-arm tom-daubney-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice script! Thanks for this. LGTM.

@tom-daubney-arm tom-daubney-arm merged commit 0028540 into Mbed-TLS:main Apr 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants