# eliaskanelis/gnumakefile4tdd architecture

> Architecture diagram of the GitHub repository eliaskanelis/gnumakefile4tdd, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/eliaskanelis/gnumakefile4tdd
- Repository: https://github.com/eliaskanelis/gnumakefile4tdd

## Overview

##### 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

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Developer / CI
    DevCI["Developer / CI System"]:::tools
    DevCI -->|triggers| MakeCore

    %% Build Orchestrator
    MakeCore["Makefile + compiler.mk + tests.mk"]:::tools
    click DevCI "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/.drone.yml"
    click MakeCore "https://github.com/eliaskanelis/gnumakefile4tdd/tree/master/Makefile"
    click MakeCore "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/compiler.mk"
    click MakeCore "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/tests.mk"

    %% Source Layer
    subgraph "Source Code" 
        direction TB
        Apps["apps/demo/main.c"]:::code
        CoreLib["src/"]:::code
    end
    click Apps "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/apps/demo/main.c"
    click CoreLib "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/src/.gitkeep"

    %% Port Abstraction Layer
    subgraph "Port Abstraction Layer" 
        direction TB
        POSIX["port/posix"]:::code
        STM32["port/stm32f072rb"]:::code
        TM4C["port/tm4c123gh6pm"]:::code
    end
    click POSIX "https://github.com/eliaskanelis/gnumakefile4tdd/tree/master/port/posix/Makefile"
    click POSIX "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/port/posix/bsp.c"
    click STM32 "https://github.com/eliaskanelis/gnumakefile4tdd/tree/master/port/stm32f072rb/Makefile"
    click STM32 "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/port/stm32f072rb/bsp.c"
    click STM32 "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/port/stm32f072rb/sys/startup_stm32f072xb.s"
    click STM32 "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/port/stm32f072rb/sys/STM32F072RBTx_FLASH.ld"
    click STM32 "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/port/stm32f072rb/sys/system_stm32f0xx.c"
    click STM32 "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/port/stm32f072rb/syscalls.c"
    click TM4C "https://github.com/eliaskanelis/gnumakefile4tdd/tree/master/port/tm4c123gh6pm/Makefile"
    click TM4C "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/port/tm4c123gh6pm/bsp.c"
    click TM4C "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/port/tm4c123gh6pm/sys/startup_TM4C123GH6PM.c"
    click TM4C "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/port/tm4c123gh6pm/sys/TM4C123GH6PM.ld"
    click TM4C "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/port/tm4c123gh6pm/sys/system_TM4C123GH6PM.c"
    click TM4C "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/port/tm4c123gh6pm/syscalls.c"

    %% Third-Party Library
    thirdparty["thirdparty/CMSIS"]:::config
    click thirdparty "https://github.com/eliaskanelis/gnumakefile4tdd/tree/master/thirdparty/CMSIS/Include"
    click thirdparty "https://github.com/eliaskanelis/gnumakefile4tdd/tree/master/thirdparty/CMSIS/Device/ST/STM32F0xx"
    click thirdparty "https://github.com/eliaskanelis/gnumakefile4tdd/tree/master/thirdparty/CMSIS/Device/TI/TM4C"

    %% Configuration Profiles
    subgraph "Configuration Profiles" 
        direction TB
        CPPCHECK_CONF["conf/cppcheck"]:::config
        DOXY_CONF["conf/doxygen"]:::config
        JLINK_CONF["conf/jlink"]:::config
        OZONE_CONF["conf/ozone"]:::config
        PCLINT_CONF["conf/pc-lint"]:::config
    end

    %% Scripts
    subgraph "Build & Utility Scripts"
        direction TB
        SC_CPCHECK["scripts/cppcheck.sh"]:::tools
        SC_DOXY["scripts/doxygen.sh"]:::tools
        SC_VER["scripts/get_version.sh"]:::tools
        SC_FLASH["scripts/flash*"]:::tools
        SC_PCLINT["scripts/pclint_settings"]:::tools
        SC_PMCCABE["scripts/pmccabe.sh"]:::tools
        SC_SHELLCHK["scripts/shellcheck.sh"]:::tools
        SC_DOS2UNIX["scripts/dos2unix.sh"]:::tools
    end

    click SC_CPCHECK "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/scripts/cppcheck.sh"
    click SC_DOXY "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/scripts/doxygen.sh"
    click SC_VER "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/scripts/get_version.sh"
    click SC_FLASH "https://github.com/eliaskanelis/gnumakefile4tdd/tree/master/scripts/flash*"
    click SC_PCLINT "https://github.com/eliaskanelis/gnumakefile4tdd/tree/master/scripts/pclint_settings"
    click SC_PMCCABE "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/scripts/pmccabe.sh"
    click SC_SHELLCHK "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/scripts/shellcheck.sh"
    click SC_DOS2UNIX "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/scripts/dos2unix.sh"

    %% Test Framework
    subgraph "Test Framework"
        direction TB
        TestsMK["tests.mk"]:::tools
        AllTests["tests/AllTests.cpp"]:::code
        Cheatsheet["tests/cheatsheet/cheatsheet_test.cpp"]:::code
    end
    click TestsMK "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/tests.mk"
    click AllTests "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/tests/AllTests.cpp"
    click Cheatsheet "https://github.com/eliaskanelis/gnumakefile4tdd/blob/master/tests/cheatsheet/cheatsheet_test.cpp"

    %% Toolchain
    Toolchain["cross-gcc/linker/objcopy"]:::tools

    %% Artifacts & Debug
    Artifacts["Firmware.bin + map files"]:::artifact
    Debug["JLink / Ozone / gdb"]:::tools

    %% Build Flow
    MakeCore -->|compiles| Apps
    MakeCore -->|compiles| CoreLib
    MakeCore -->|includes| POSIX
    MakeCore -->|includes| STM32
    MakeCore -->|includes| TM4C
    MakeCore -->|uses| thirdparty
    MakeCore -->|reads| CPPCHECK_CONF
    MakeCore -->|reads| DOXY_CONF
    MakeCore -->|reads| JLINK_CONF
    MakeCore -->|reads| OZONE_CONF
    MakeCore -->|reads| PCLINT_CONF
    MakeCore -->|invokes| SC_CPCHECK
    MakeCore -->|invokes| SC_DOXY
    MakeCore -->|invokes| SC_VER
    MakeCore -->|invokes| SC_FLASH
    MakeCore -->|invokes| SC_PCLINT
    MakeCore -->|invokes| SC_PMCCABE
    MakeCore -->|invokes| SC_SHELLCHK
    MakeCore -->|invokes| SC_DOS2UNIX
    MakeCore -->|runs| TestsMK
    TestsMK -->|compiles| AllTests
    TestsMK -->|compiles| Cheatsheet
    MakeCore -->|calls| Toolchain
    Toolchain -->|generates| Artifacts
    Artifacts -->|flashed/debugged| Debug
    Debug -->|uses| JLINK_CONF
    Debug -->|uses| OZONE_CONF

    %% Styles
    classDef code fill:#cce5ff,stroke:#333;
    classDef tools fill:#d4edda,stroke:#333;
    classDef config fill:#fff3cd,stroke:#333;
    classDef artifact fill:#e2e3e5,stroke:#333;
```
