Build System Architecture
ML Defender uses a hierarchical build system with a single source of truth for compiler flags and build profiles.Design Principles
- Single Source of Truth: All compiler flags in root
Makefile(lines 50-98) - Profile-Aware Builds: Separate build directories per profile
- No Flag Hardcoding: CMakeLists.txt files receive flags from Makefile
- Reproducible Builds: Same profile = same binary
Build Profiles
Profile Definitions
From source/Makefile:50-98:Build Directory Structure
CMake Configuration
Correct Flag Handling
❌ WRONG - Do not hardcode flags:Component CMake Flow
From source/Makefile:277-290:Makefile Targets Reference
Core Build Targets
| Target | Description | Example |
|---|---|---|
make all | Build all components | make PROFILE=production all |
make proto | Regenerate Protobuf | make proto |
make sniffer | Build eBPF sniffer | make PROFILE=debug sniffer |
make ml-detector | Build ML detector | make PROFILE=tsan ml-detector |
make firewall | Build firewall agent | make firewall |
make etcd-server | Build etcd server | make etcd-server |
make tools | Build testing tools | make tools |
Library Targets
Clean Targets
Debian Packaging
Package Build
From source/debian/control:Package Structure
Debian Control File
From source/debian/control:Installation
Docker Builds
Multi-Service Architecture
From source/ directory:Docker Compose
docker-compose.yaml
Running
Build Dependencies
Dependency Graph
Build Order
Critical: Dependencies must be built in this order:- Protobuf:
make proto - crypto-transport:
make crypto-transport-build - etcd-client:
make etcd-client-build - Components:
make sniffer ml-detector firewall
Verifying Dependencies
Cross-Compilation
ARM64 Build (for Raspberry Pi)
Optimization Flags
Production Build Flags
From source/Makefile:60-61:| Flag | Purpose |
|---|---|
-O3 | Maximum optimization |
-march=native | CPU-specific optimizations |
-DNDEBUG | Disable assertions |
-flto | Link-time optimization |
-fno-omit-frame-pointer | Better stack traces (small perf cost) |
Performance Impact
TSAN/ASAN Builds
ThreadSanitizer
From source/Makefile:465-529:AddressSanitizer
Troubleshooting
Build Fails with Undefined References
Symptom:undefined reference to 'bpf_ringbuf_reserve'
Solution:
Protobuf Mismatch
Symptom:protobuf version mismatch
Solution:
Stale Build Cache
Next Steps
Testing
Run tests and validate builds
eBPF/XDP
Understand eBPF program compilation
Deployment
Deploy production builds
Performance
Optimize and benchmark