Makefile System¶
This document provides a deep dive into the mk/*.mk files that form the core of the spksrc build system.
File Organization¶
The mk/ directory contains all makefile includes, organized by function:
Core Files¶
| File | Purpose |
|---|---|
spksrc.common.mk |
Base settings, utilities, parallel build config |
spksrc.common/directories.mk |
Work directory paths |
Rules¶
| File | Purpose |
|---|---|
spksrc.rules.mk |
Rules entry point (clean, smart-clean, changelog, rustup); aggregates dependency-tree.mk + generate-digests.mk |
spksrc.rules/dependency.mk |
Dependency resolution and build |
spksrc.rules/dependency-tree.mk |
Dependency graph |
spksrc.rules/generate-digests.mk |
Digests generation |
spksrc.rules/pre-check.mk |
Pre-build validation |
spksrc.rules/status.mk |
Build status tracking |
spksrc.rules/supported.mk |
Arch/version support (build-arch-* targets) |
spksrc.rules/tests.mk |
Test harness rules |
Build Pipeline¶
| File | Purpose |
|---|---|
spksrc.build.mk |
Standard build pipeline aggregator (download → install); included by spksrc.cross-cc.mk and spksrc.native-cc.mk |
spksrc.build/download.mk |
Source download from URLs/Git |
spksrc.build/checksum.mk |
Archive integrity verification |
spksrc.build/extract.mk |
Archive extraction |
spksrc.build/patch.mk |
Patch application |
spksrc.build/configure.mk |
Configure stage orchestration |
spksrc.build/compile.mk |
Compilation orchestration |
spksrc.build/install.mk |
Installation to staging |
spksrc.build/plist.mk |
Package list generation |
spksrc.build/archive.mk |
Optional post-install archive of the build output, for hosting/reuse (opt-in via ARCHIVE_NAME) |
Cross-Compilation¶
| File | Purpose |
|---|---|
spksrc.cross-cc.mk |
Main cross-compilation entry point |
spksrc.cross-install.mk |
Install-only cross build (skip configure/compile) |
spksrc.cross-virtual.mk |
Source-less cross package that only aggregates DEPENDS |
spksrc.cross/env-default.mk |
Cross-compilation environment setup |
Synology official toolchain and toolkit¶
| File | Purpose |
|---|---|
spksrc.toolchain.mk |
Toolchain download, extraction and patching |
spksrc.native-toolchain.mk |
Toolchain overlay producer (native/gcc-8.5, native/binutils-2.30, native/rustc-*): arch-<arch>-<dsm>, all-<dsm>, profile-guided builds |
spksrc.overlay.mk |
Overlay consumer: installs one overlay/ component beside its base toolchain (see Toolchain Overlays) |
spksrc.toolkit.mk |
Toolkit management |
Kernel Modules and Drivers¶
| File | Purpose |
|---|---|
spksrc.kernel.mk |
A kernel/ package: modules built in the Synology kernel source, one kernel per arch/DSM |
spksrc.driver.mk |
A driver/ package: an out-of-tree driver, built once per kernel against that kernel's source |
spksrc.kernel/ |
Kernel environment, configuration, headers, module build, requirements, download and version mapping |
Build System Adapters¶
| File | Purpose |
|---|---|
spksrc.cross-cmake.mk |
CMake cross-compilation |
spksrc.cross/env-cmake.mk |
CMake environment setup |
spksrc.cross/cmake-toolchainfile.mk |
CMake toolchain file generation |
spksrc.cross-meson.mk |
Meson cross-compilation |
spksrc.cross/env-meson.mk |
Meson environment setup |
spksrc.cross/meson-crossfile.mk |
Meson cross file generation |
spksrc.cross-go.mk |
Go cross-compilation |
spksrc.cross/env-go.mk |
Go environment setup |
spksrc.cross-rust.mk |
Rust cross-compilation |
spksrc.cross/env-rust.mk |
Rust environment setup |
spksrc.cross-dotnet.mk |
.NET cross-compilation |
spksrc.cross/env-dotnet.mk |
.NET environment setup |
Native Builds¶
| File | Purpose |
|---|---|
spksrc.native-cc.mk |
Native compilation entry point (also defines nativeclean, the native counterpart of spkclean) |
spksrc.native/env-default.mk |
Native build environment |
spksrc.native-cmake.mk |
Native CMake builds |
spksrc.native-meson.mk |
Native Meson builds |
spksrc.native-install.mk |
Install-only native build (skip configure/compile) |
Python/Wheel System¶
| File | Purpose |
|---|---|
spksrc.python-wheel.mk |
Main include for an exception wheel under python/ (pip/crossenv) |
spksrc.python-wheel-meson.mk |
Same, for meson-built wheels |
spksrc.wheel.mk |
Wheel package orchestration (via spksrc.spk.mk) |
spksrc.wheel/download.mk |
Wheel downloading |
spksrc.wheel/compile.mk |
Wheel compilation |
spksrc.wheel/install.mk |
Wheel installation |
spksrc.wheel/env.mk |
Wheel environment setup |
spksrc.python-crossenv.mk |
Cross-compilation virtual environment |
spksrc.python-module.mk |
A python extension module, compiled under crossenv |
SPK Package Creation¶
| File | Purpose |
|---|---|
spksrc.spk.mk |
Main SPK package assembly |
spksrc.spk-meta.mk |
Meta-consumer entry point: sets up the ffmpeg/python/videodriver meta(s), then includes spksrc.spk.mk |
spksrc.spk-meta/base.mk |
SPK_BASE_TEMPLATE — wires a meta's staging into the consumer |
spksrc.spk-meta/meta.mk |
Generates tc_vars.meta.mk, an inspectable diagnostic of the meta env (never -included) |
spksrc.spk-meta/videodriver-depends.mk |
The videodriver library DEPENDS, shared by spk/synocli-videodriver and the videodriver meta |
spksrc.spk/copy.mk |
Dependency copying to staging |
spksrc.spk/strip.mk |
Binary stripping |
spksrc.spk/icon.mk |
Icon processing |
spksrc.service.mk |
Service configuration generation |
Service Scripts (Templates)¶
| File | Purpose |
|---|---|
spksrc.service/installer.dsm6 |
DSM 6 installer template |
spksrc.service/installer.dsm7 |
DSM 7 installer template |
spksrc.service/installer.functions |
Common installer functions |
spksrc.service/start-stop-status |
Service control template |
spksrc.service/create_links |
Symlink creation helper |
Include Hierarchy¶
The framework is organized as entry-point .mk files at the mk/ root plus, for each subsystem, a spksrc.<name>/ directory of helper files. spksrc.common.mk is auto-loaded by every entry point (see Macros):
# Foundation — auto-loaded by every entry point (see Macros); entry points
# also pull in the shared Core files and the build pipeline below.
spksrc.common.mk
spksrc.common/
├── archs.mk # architecture classification / groups
├── directories.mk # work/staging/distrib directory layout
├── dotnet.mk # the archs a dotnet package refuses, and why
├── help.mk # context-aware `make help`; help-<arch>-<tcvers> adds overlay and check
├── logs.mk # logging helpers
├── macros.mk # GNU Make helper macros, one file per theme:
├── macros/
│ ├── archs.mk # which toolchain an overlay or its producer stands for, at which revision
│ ├── bool.mk # TRUE, FALSE, is_true, is_false, assert_bool, bool
│ ├── depend.mk # depend, dep_seen
│ ├── list.mk # uniq, dedup, dedup_files, merge, comma_append
│ ├── runlog.mk # _runlog, RUNLOG
│ ├── string.mk # upper, lower
│ ├── tools.mk # tc, native, read_makefile_var
│ └── version.mk # version_le/ge/lt/gt
├── overlay.mk # overlay decisions: available, requested, active
├── overlay/
│ ├── binutils.mk # per component, read by overlay.mk in this order:
│ ├── gcc.mk # binutils, gcc, rustc
│ ├── rustc.mk
│ └── warnings.mk # banner text for the degraded states
├── stage0.mk # parse-time toolchain pre-bootstrap (tc_vars.mk, tc_vars.overlay.mk)
└── tc-capability.mk # capability floors: MIN_GCC_VERSION, MIN_KERNEL_VERSION, ...
# Build pipeline — the per-package steps
spksrc.build.mk # standard pipeline aggregator (download -> install),
# included by spksrc.cross-cc.mk and spksrc.native-cc.mk
spksrc.build/
├── download.mk # source download
├── checksum.mk # archive verification
├── extract.mk # archive extraction
├── patch.mk # patch application
├── configure.mk # configure
├── compile.mk # compile
├── install.mk # install to staging
├── plist.mk # package list generation (cross/kernel/cross-virtual; not in build.mk)
├── ninja.mk # ninja helper (cmake/meson)
└── archive.mk # optional post-install archive (ARCHIVE_NAME)
# Rules — shared targets / orchestration, included by the entry points
spksrc.rules.mk # rules entry point: clean/changelog targets,
# aggregates dependency-tree.mk + generate-digests.mk
spksrc.rules/
├── check.mk # make check / check-<arch>-<tcvers>: the capability gates an arch fails
├── depend.mk # dependency resolution/build
├── dependency.mk # builds the DEPENDS, in order
├── dependency-tree.mk # dependency graph
├── generate-digests.mk # digests generation
├── overlay.mk # make overlay / overlay-<arch>-<tcvers>: the overlay report
├── pre-check.mk # pre-build validation
├── status.mk # build status tracking
├── supported.mk # arch/version support (build-arch-* targets); includes check.mk, overlay.mk
└── tests.mk # test harness rules
# Cross-compilation entry points (a cross/ package includes one)
spksrc.cross-cc.mk # autotools / plain C/C++
spksrc.cross-cmake.mk # CMake
spksrc.cross-dotnet.mk # .NET
spksrc.cross-go.mk # Go
spksrc.cross-meson.mk # Meson
spksrc.cross-rust.mk # Rust
spksrc.cross-install.mk # install-only: no configure/compile
spksrc.cross-virtual.mk # source-less: only aggregates DEPENDS
spksrc.cross/ # environment setup loaded by the entry points above
├── cmake-toolchainfile.mk # generated CMake toolchain file
├── env-cmake.mk
├── env-default.mk # base cross env
├── env-dotnet.mk
├── env-go.mk
├── env-meson.mk
├── env-rust.mk
└── meson-crossfile.mk # generated Meson cross file
# Native build entry points
spksrc.native-cc.mk
spksrc.native-cmake.mk
spksrc.native-install.mk
spksrc.native-meson.mk
spksrc.native-toolchain.mk # toolchain overlay producer front-end
spksrc.native/
├── env-cmake.mk
├── env-default.mk # base native env
└── env-meson.mk
spksrc.native-toolchain/ # one file per producer component, picked by PKG_NAME
├── binutils.mk # PKG_NAME = binutils
├── gcc.mk # PKG_NAME = gcc
├── pgo-sources.sh # generates the PGO training sources
└── rustc.mk # PKG_NAME = rustc
# SPK assembly entry point
spksrc.spk.mk
spksrc.spk/
├── copy.mk # dependency copying to staging
├── icon.mk # icon processing
├── publish.mk # publish to package server
└── strip.mk # binary stripping
# Meta-consumer entry point (sets up the meta(s), then includes spksrc.spk.mk)
spksrc.spk-meta.mk
spksrc.spk-meta/
├── base.mk # SPK_BASE_TEMPLATE
├── ffmpeg.mk # when FFMPEG_PACKAGE is set
├── meta.mk # generates tc_vars.meta.mk
├── python.mk # when PYTHON_PACKAGE is set
├── videodriver-depends.mk # the videodriver DEPENDS, shared with spk/synocli-videodriver
└── videodriver.mk # when VIDEODRV_PACKAGE is set
# Service configuration entry point
spksrc.service.mk
spksrc.service/
├── create_links
├── installer.dsm5
├── installer.dsm6
├── installer.dsm7
├── installer.functions
├── non-startable
├── privilege-installasroot
├── start-stop-status
├── testcase
├── use_alternate_tmpdir
└── use_alternate_tmpdir.dsm7
# Python entry points
spksrc.python-wheel.mk # an exception wheel under python/ (pip/crossenv)
spksrc.python-wheel-meson.mk # same, meson-built
spksrc.python-crossenv.mk # the cross-compilation virtual environment
spksrc.python-module.mk # a python extension module, under crossenv
spksrc.wheel.mk # wheel orchestration (via spksrc.spk.mk)
spksrc.wheel/
├── compile.mk
├── download.mk
├── env.mk
├── install.mk
└── requirement.mk
# Toolchain entry point
spksrc.toolchain.mk
spksrc.toolchain/
├── overlay/
│ ├── binutils.mk # uses the binutils overlay (shim, -B), cleans every overlay
│ └── rustc.mk # uses the rust overlay (synology triple, rustup toolchain)
├── tc-base.mk
├── tc-flags.mk
├── tc-normalize.mk
├── tc-rust.mk # rustup base install (rustup-rustc target)
├── tc-url.mk
├── tc-versions.mk
└── tc_vars.mk # generates the tc_vars* files
# Overlay consumer entry point (an overlay/ directory includes it)
spksrc.overlay.mk # reads arch, DSM and component off the directory name
spksrc.overlay/
├── binutils.mk # download, extract, as/ld shim
├── gcc.mk # download, extract, link sysroot and as/ld
└── rust.mk # download, extract, rustup toolchain link
# Toolkit entry point (only via REQUIRE_TOOLKIT)
spksrc.toolkit.mk
spksrc.toolkit/
├── tk-base.mk
├── tk-flags.mk
├── tk-normalize.mk
├── tk-url.mk
├── tk-versions.mk
└── tk_vars.mk # generates the tk_vars* files
# Kernel entry points (a kernel/ or driver/ package includes one)
spksrc.kernel.mk # a kernel's modules, built in the Synology kernel source
spksrc.driver.mk # an out-of-tree driver, built once per kernel against its source
spksrc.kernel/
├── base.mk # default kernel environment
├── configure.mk # kernel configuration
├── dependency.mk # kernel module dependencies
├── headers.mk # kernel headers for external modules
├── module.mk # module compilation
├── required.mk # kernel requirement checks
├── url.mk # kernel download locations
└── versions.mk # DSM version -> kernel metadata
Key Implementation Details¶
spksrc.common.mk¶
The foundation of all builds. Key responsibilities:
- BASEDIR detection - Determines repository root
- Local config loading - Includes
local.mkif present - Parallel build setup - Configures
PARALLEL_MAKEandNCPUS - Common utilities -
MSG,RUN, language definitions
# Key variables defined
BASEDIR # Repository root
MSG # Message output helper
RUN # Command execution in package environment
LANGUAGES # Supported localization languages
PARALLEL_MAKE # Parallel build mode
NCPUS # CPU count for parallel builds
spksrc.cross-cc.mk¶
The main entry point for cross-compiled packages. Implements the two-stage build:
# Stage 1: Toolchain
cross-stage1: $(TCVARS_DONE)
@$(MAKE) -C toolchain/$(TC) toolchain
@$(MAKE) -C toolchain/$(TC) tcvars
# Stage 2: Package build
cross-stage2:
# Standard pipeline: depend → configure → compile → install → plist
spksrc.cross/env-default.mk¶
Sets up the cross-compilation environment by loading tc_vars files:
# Loads toolchain configuration: tc_vars.mk always, then one fragment per
# word in TC_VARS_ENV (autotools, flags, rust -- the words that name a file)
include $(WORK_DIR)/tc_vars.mk
TC_VARS_FILES := $(wildcard $(foreach b,$(sort $(TC_VARS_ENV)),$(WORK_DIR)/tc_vars.$(b).mk))
# Exports to ENV for command execution
ENV += CC=$(TC_CC) CXX=$(TC_CXX) ...
spksrc.spk.mk¶
Orchestrates final SPK package creation:
- INFO generation - Package metadata
- Script generation - Install/upgrade scripts from templates
- Wizard processing - Mustache template rendering
- Package assembly - Creates package.tgz and SPK archive
spksrc.service.mk¶
Generates service-related files and configuration:
- Processes
FWPORTSinto resource files - Generates
SPK_COMMANDSfor usr-local-linker - Creates service control scripts
- Handles DSM version-specific differences
Adding New Build System Support¶
To add support for a new build system:
- Create environment file:
spksrc.cross-<system>-env.mk - Define environment variables needed
-
Handle toolchain file generation if needed
-
Create main include:
spksrc.cross-<system>.mk - Include the environment file
-
Define configure/compile targets
-
Update spksrc.build/configure.mk:
- Add detection for the new build system
- Include the new makefile when detected
Example: Meson Support¶
# spksrc.cross/env-meson.mk - Environment setup
MESON_CROSS_FILE = $(WORK_DIR)/tc_vars.meson-cross
ENV += MESON_CROSS_FILE=$(MESON_CROSS_FILE)
# spksrc.cross-meson.mk - Build logic
include ../../mk/spksrc.cross/env-meson.mk
include ../../mk/spksrc.cross/meson-crossfile.mk
configure_target:
meson setup --cross-file $(MESON_CROSS_FILE) ...
Cookie System Details¶
Cookies track build progress and enable incremental builds:
# Cookie file naming
COOKIE_PREFIX = $(PKG_NAME)-
COOKIE_FILE = $(WORK_DIR)/.$(COOKIE_PREFIX)<stage>_done
# Stage completion
download_target:
# ... download logic ...
@touch $(WORK_DIR)/.$(COOKIE_PREFIX)download_done
To force a rebuild from a specific stage, remove the corresponding cookie:
Debugging Framework Issues¶
Print Variable Values¶
# Add to package Makefile temporarily
debug:
@echo "CC=$(CC)"
@echo "STAGING_INSTALL_PREFIX=$(STAGING_INSTALL_PREFIX)"
@echo "ENV=$(ENV)"
Verbose Make¶
# Show all commands
make -C spk/mypackage ARCH=x64 TCVERSION=7.2 V=1
# Show makefile parsing
make -C spk/mypackage ARCH=x64 TCVERSION=7.2 --debug=v
Check Include Order¶
Related Documentation¶
- Architecture - Build pipeline overview
- Toolchains - Toolchain management
- Developer Guide: Build Rules - Using build system includes