How eliaskanelis/gnumakefile4tdd works
Project Type and Purpose
• This is an opinionated GNU Make–based build system for C/C++ with test‑driven development, cross‑compilation and multi‑architecture support.
• It targets embedded platforms (stm32f072rb, tm4c123gh6pm) but also supports Linux builds and host‑based unit testing.
• Key features: TDD with cppUTest, port abstraction, configuration profiles, flashing/debugging scripts, CMSIS third‑party support.
File Structure
• Top‑level build orchestrator:
• Makefile, compiler.mk, tests.mk, .drone.yml (CI)
• Source code:
• apps/…: main.c per application target
• src/, inc/ (if present): shared library code
• port/…: board‐support layers, startup, linker scripts—one subdirectory per MCU
• thirdparty/CMSIS: vendor device headers & system sources
• Tests:
• tests/AllTests.cpp, cheatsheet_test.cpp — host‑side cppUTest harness
• Configuration:
• conf/: tool configs (cppcheck, pc‑lint, doxygen, jlink, ozone)
• Scripts:
• scripts/*.sh & helpers for linting, doxygen, flashing, versioning
• CI/CD:
• .drone.yml drives builds/test in Docker, outputs artifacts
README for Additional Insights
• Workflow: developer/CI invokes make PORT_NAME=… → Makefile loads compiler.mk, tests.mk → selects port → runs compile/link → invokes unit tests → optionally lints, docs → scripts handle flashing/debugging.
• Dependencies: Docker image voidbuffer/devtools.
Main Components & Relationships
a. Components
• Developer / CI System
• Build Orchestrator (Makefile + compiler.mk + tests.mk)
• Source Code: apps/, src/, inc/
• Port Abstraction Layer: port/<board>/bsp.c, startup/*.s, linker scripts
• Third‑Party Library: CMSIS headers & system source
• Configuration Profiles: conf/ for tools (lint, docs, debug)
• Scripts: lint, doxygen, flash, versioning
• Toolchain: cross‑gcc, linker, objcopy, gdb
• Test Framework: cppUTest runner
• Output Artifacts: firmware binary, map files, test executables
• Hardware / Host: target MCU for firmware, host for tests
b. Interactions
1. Developer/CI triggers Make
2. Make parses configs, selects port, invokes compiler/linker
3. Source code + port layer + third‑party headers → compilation units
4. Linker → firmware.bin + debug symbols
5. Post‑build scripts:
– run host tests via cppUTest
– run static analysis (cppcheck/pc‑lint)
– generate docs (doxygen)
– flash/erase MCU via jlink/ozone scripts
– auto‑version stamping
6. Debugging: gdb or Ozone uses debug symbols and .svd
c. Architectural Patterns / Principles
– Layered architecture: core library (src) ↔ port layer ↔ hardware
– Single Makefile entrypoint with modular mk‑includes
– Separation of concerns: build vs. test vs. lint vs. docs vs. flash
– Config‑driven: port‑specific and tool‑specific configs under conf/
– CI/CD integration with containerized toolchain
d. Key Technologies
– GNU Make, shell scripts
– GCC cross‑compilers for ARM Cortex‑M0/M4 and x86_64
– cppUTest for unit testing
– CMSIS for hardware abstraction
– jlink/ozone for flashing/debug
– pc‑lint, cppcheck for static analysis
– drone CI