Macros¶
spksrc ships a small set of GNU Make helper macros in mk/spksrc.common/macros.mk, which includes one file per theme from mk/spksrc.common/macros/ (string.mk, version.mk, bool.mk, list.mk, depend.mk, tools.mk, archs.mk, runlog.mk). They are loaded automatically: spksrc.common.mk includes spksrc.common/macros.mk first, so the macros are available in any package Makefile that includes a spksrc entry point (spksrc.cross-cc.mk, spksrc.spk.mk, ...).
Architecture awareness is loaded early too
The same spksrc.common.mk also pulls in the parse-time toolchain pre-bootstrap (spksrc.common/stage0.mk) and the architecture classification (spksrc.common/archs.mk). That is what makes TC_GCC and the architecture groups available while a package's DEPENDS are parsed, so version- and arch-gated dependencies resolve correctly on a cold tree.
Summary¶
Every macro, by the file under mk/spksrc.common/macros/ that defines it. The helpers internal to a file (_odepend, _tc_gcc_tools, ...) are not listed; _runlog is, as the build rules call it directly.
| File | Macro | What it does |
|---|---|---|
string.mk |
$(call upper,TEXT) |
Upper-cases the ASCII letters of TEXT, without a fork |
string.mk |
$(call lower,TEXT) |
Lower-cases the ASCII letters of TEXT, without a fork |
version.mk |
$(call version_le,A,B) |
1 when version A <= B (GNU sort -V) |
version.mk |
$(call version_ge,A,B) |
1 when version A >= B |
version.mk |
$(call version_lt,A,B) |
1 when version A < B |
version.mk |
$(call version_gt,A,B) |
1 when version A > B |
bool.mk |
$(TRUE), $(FALSE) |
Every spelling of a switch on / off, in lower and upper case |
bool.mk |
$(call is_true,VALUE) |
Non-empty when VALUE is on (1, y, yes, true, on, any case) |
bool.mk |
$(call is_false,VALUE) |
Non-empty when VALUE is off (0, n, no, false, off, any case, or empty) |
bool.mk |
$(call assert_bool,VALUE,NAME) |
Stops the build when VALUE is neither, naming NAME |
bool.mk |
$(call bool,VALUE,NAME) |
TRUE or FALSE, for ifeq; stops the build on any other value |
list.mk |
$(call comma_append,LIST,ITEM) |
Appends ITEM to a comma-separated list, or returns it unchanged when ITEM is empty |
list.mk |
$(call uniq,WORDS) |
Removes duplicate words, keeping the first occurrence of each |
list.mk |
$(call dedup,STRING,DELIMITER) |
De-duplicates a delimiter-separated string, dropping empty entries |
list.mk |
$(call dedup_files,FILES) |
Removes files whose content (md5sum) was already seen, in order |
list.mk |
$(call merge,ENV,VAR,DELIMITER) |
Every VAR= value in ENV, last one first, joined with DELIMITER |
depend.mk |
$(call depend,PKGS[,ON[,OFF]]) |
Declares a dependency: required, alternatives with \|, or optional with its switches |
depend.mk |
$(call dep_seen,STAMPS,DEP) |
Shell test: true when DEP was already visited in a dependency walk |
tools.mk |
$(call read_makefile_var,FILE,VAR) |
The value FILE assigns to VAR, unexpanded, without including the file |
tools.mk |
$(call tc,TOOL) |
Absolute path of a cross tool, honouring the active overlays |
tools.mk |
$(call native,TOOL) |
Absolute path of a build-host tool, or its bare name when absent |
archs.mk |
$(call overlay_dist_arch,ARCH,DSM) |
The arch an overlay archive is named after: a generic arch's real arch |
archs.mk |
$(call toolchain_real,ARCH-DSM) |
The toolchain a producer builds an <arch>-<dsm> as |
archs.mk |
$(call toolchain_archs,DSM) |
The archs a producer builds for a DSM version |
archs.mk |
$(call toolchain_published_rev,ARCH,DSM,SUFFIX) |
The PKG_REV of the overlay that installs an archive, or empty |
runlog.mk |
$(call _runlog,COMMAND,LOG) |
Shell fragment: runs COMMAND teed into LOG, leaving the status to the caller |
runlog.mk |
$(call RUNLOG,GOAL) |
Recipe line: runs a goal of this Makefile, logged, and reports a failure |
The sections below show them in use.
Version comparison¶
These compare two version strings (natural/sort -V order) and return 1 when the test is true, empty otherwise — ideal for ifeq:
| Macro | True when |
|---|---|
$(call version_le,A,B) |
A ≤ B |
$(call version_ge,A,B) |
A ≥ B |
$(call version_lt,A,B) |
A < B |
$(call version_gt,A,B) |
A > B |
# Pull a dependency only on a recent enough toolchain
ifeq ($(call version_ge,$(TC_GCC),8.5),1)
DEPENDS += python/numpy-latest
endif
# Apply a workaround on older compilers
ifeq ($(call version_lt,$(TC_GCC),5.0),1)
ADDITIONAL_CFLAGS += -std=gnu99
endif
Boolean values¶
A switch may be written 1/0, y/n, yes/no, true/false or on/off, in any
case. Empty is false: an unset switch is off.
| Macro | Returns |
|---|---|
$(call is_true,VALUE) |
a non-empty word when VALUE is true, empty otherwise -- for $(if ...) |
$(call is_false,VALUE) |
a non-empty word when VALUE is false or empty |
$(call bool,VALUE[,NAME]) |
TRUE or FALSE -- for ifeq; stops the build on any other value, naming NAME |
# Validates as it reads: OVERLAY_GCC=maybe stops with "OVERLAY_GCC: invalid boolean value 'maybe'"
ifeq ($(call bool,$(OVERLAY_GCC),OVERLAY_GCC),TRUE)
...
endif
# Inside an expression
ACTIVE = $(if $(call is_true,$(PSTAT)),1)
bool is the one to use where a typo must not silently read as "off". $(call assert_bool,VALUE,NAME) only validates, for a switch read with is_true / is_false elsewhere. $(TRUE) and $(FALSE) hold every spelling, in lower and upper case.
Case conversion¶
$(call upper,TEXT) and $(call lower,TEXT) change the case of ASCII letters in pure make, without a fork. The switches above are read through lower, and the Rust triple becomes an environment suffix through both: CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER, CC_x86_64_unknown_linux_gnu.
Dependencies¶
$(call depend,...) declares a dependency the build takes where it can, with the
configure switches that come with it. It does not replace DEPENDS and
OPTIONAL_DEPENDS: it removes the conditions a package like ffmpeg had to copy, word for
word, from each of its dependencies.
The first argument is a list of packages, read two ways:
- AND -- packages separated by spaces,
cross/a cross/b ... cross/z: the call holds when every one of them supports the build. - OR -- alternatives separated by
|,cross/a|cross/b|...|cross/z: the call holds with the first one that supports the build.
The two combine: cross/a|cross/b cross/c is "a or b, and c".
| Call | Effect |
|---|---|
$(call depend,cross/x) |
DEPENDS += cross/x -- required, as before |
$(call depend,cross/a cross/b ... cross/z) |
required, all of them -- a plain DEPENDS too |
$(call depend,cross/a\|cross/b\|...\|cross/z) |
required alternatives: the first whose tree supports the build, else the last, which then refuses it -- a virtual package |
$(call depend,<list>,<if-switches>) |
optional: where the list holds, its packages go to DEPENDS and <if-switches> to CONFIGURE_ARGS; elsewhere nothing |
$(call depend,<list>,<if-switches>,<else-switches>) |
the same, and <else-switches> where the list does not hold |
$(call depend,<list>,nop) |
optional, with no switch |
<list> is any of the AND/OR forms above: one package, cross/a cross/b ... cross/z
(all must pass, else <else-switches>), cross/a|cross/b|...|cross/z (the first that
passes, else <else-switches>).
include ../../mk/spksrc.common.mk
# required: a plain DEPENDS
$(call depend,cross/cairo)
# one package, if-switches: taken where vvenc's own floors (gcc 7.5, its archs) are met
$(call depend,cross/vvenc,--enable-libvvenc)
# one package, if- and else-switches: enabled by default upstream, so turned off by name
# where x265 cannot be built
$(call depend,cross/x265,--enable-libx265,--disable-libx265)
# no switch: the build finds it on its own
$(call depend,cross/intel-mediasdk,nop)
# AND: flac and libtheora together, or neither
$(call depend,cross/flac cross/libtheora,--enable-libtheora)
# AND with an else: dvbcsa needs both libraries
$(call depend,cross/libdvbcsa cross/dvb-apps,--enable-dvbcsa,--disable-dvbcsa)
# OR: the first supported version
$(call depend,cross/libvmaf-2.3|cross/libvmaf-1.5,--enable-libvmaf)
# OR with an else
$(call depend,cross/libvmaf-2.3|cross/libvmaf-1.5,--enable-libvmaf,--disable-libvmaf)
include ../../mk/spksrc.cross-cc.mk
Include spksrc.common.mk before the first call
The macro is defined there; called earlier it expands to nothing, silently.
A virtual package¶
The required OR form, with no switch, is a whole virtual package: one of the versions is required, the first one the architecture supports.
PKG_NAME = libaom-virtual
include ../../mk/spksrc.common.mk
$(call depend,cross/libaom-latest|cross/libaom-3.8)
include ../../mk/spksrc.cross-virtual.mk
make ARCH=x64 TCVERSION=6.2.4 check -- the first version needs gcc 7.5, the second is
picked:
===> libaom-virtual: x64-6.2.4 check: 0 failed, 1 more behind an optional dependency
optional
cross/libaom-latest gcc 4.9.3 < 7.5
optional in use : cross/libaom-3.8
optional unused : cross/libaom-latest
make check-x64-7.1 -- the first version is supported:
===> libaom-virtual: x64-7.1 check: OK
optional in use : cross/libaom-latest
optional unused : cross/libaom-3.8
make check-x86-5.2 -- neither is: the last one is kept, and refuses the build by name:
===> libaom-virtual: x86-5.2 check: 1 failed, 1 more behind an optional dependency
required
cross/libaom-3.8 gcc 4.7.3 < 4.8
optional
cross/libaom-latest gcc 4.7.3 < 7.5
optional in use : cross/libaom-3.8
optional unused : cross/libaom-latest
How the framework processes both lists, in a build, a walk and without an ARCH:
How DEPENDS and OPTIONAL_DEPENDS are processed.
The outcome keeps the place of the call
DEPENDS and CONFIGURE_ARGS come out in the order the Makefile lists them, as with
an ifeq at that line. Until resolution, though, they hold a placeholder: do not test
their content while parsing.
Instead of
OPTIONAL_DEPENDS += cross/vvenc
...
ifeq ($(call version_ge,$(TC_GCC),7.5),1)
DEPENDS += cross/vvenc
CONFIGURE_ARGS += --enable-libvvenc
endif
where the ifeq repeats MIN_GCC_VERSION = 7.5 from cross/vvenc/Makefile, and must be
kept in step with it by hand.
How it decides¶
The verdict is the one make check
gives: the dependency and its required tree pass every gate (MIN_GCC_VERSION,
MIN_GLIBC_VERSION, MIN_KERNEL_VERSION, REQUIRE_64BIT, UNSUPPORTED_ARCHS, …) of
the build's ARCH-TCVERSION. So the condition belongs to the dependency: a floor
missing there is a floor to add there, not a condition to put back in the caller.
- Computed once per
WORK_DIR, the candidates in parallel, and kept inwork-<arch>-<vers>/depend-<package>.mk. After changing a dependency's floors,make clean(orspkclean) to recompute. - The optional dependency is always declared in
OPTIONAL_DEPENDS, somake dependency-list-spk(noARCH) still fetches its sources. - A dependency walk (the pre-check,
make check) computes verdicts only for required alternatives: it walks the required tree, and an unsupported optional dependency never refuses the build. make checkreports the outcome:optional in use/optional unused.
A call inside an ifeq is not seen without an ARCH
A $(call depend,...) inside a block that a parse without ARCH does not enter (the
videodriver block of ffmpeg, say) cannot declare its package: name it in
OPTIONAL_DEPENDS yourself.
The switches go to CONFIGURE_ARGS, the one variable autotools, CMake and Meson builds all
read.
Toolchain tools¶
$(call tc,<tool>) is the absolute path of a cross tool. Use it instead of assembling
$(TC_PATH)$(TC_PREFIX)<tool> by hand: an overlay toolchain lives somewhere else entirely
(<consumer>/work/install/usr/local/bin, against the base toolchain's
<work>/<target>/bin) and its gcc family carries a version suffix there, so a
hand-built path silently resolves to the vendor tool the moment an overlay is active.
| Tool family | Resolved through | Tools |
|---|---|---|
| gcc | TC_OVERLAY_GCC_PATH when TC_OVERLAY_GCC_ON, else TC_PATH (plus TC_GCC_SUFFIX) |
gcc g++ c++ cpp gfortran |
| binutils | TC_OVERLAY_BINUTILS_PATH when TC_OVERLAY_BINUTILS_ON, else TC_PATH |
ld as ar nm ranlib strip objdump objcopy readelf |
| anything else | TC_PATH |
— |
TC_OVERLAY_<c>_PATH is empty unless that overlay is active for the build (see
Overlay switches), so the call is already
correct with no overlay and stays correct when one is grafted on — nothing to revisit in
the package.
# ffmpeg takes its tools from the command line, not from CC/AR in the environment
CONFIGURE_ARGS += --cc=$(call tc,gcc)
CONFIGURE_ARGS += --ar=$(call tc,ar)
# a plain make line that would otherwise ignore the environment
COMPILE_ARGS = CC=$(call tc,gcc) AR=$(call tc,ar)
Most packages need nothing
Autotools, CMake and Meson builds already receive CC, CXX, AR… through the
environment, overlay-aware. Reach for $(call tc,...) only where a build system
ignores that and takes a tool path of its own.
Host tools¶
$(call native,<tool>) is the same idea for the build host — the other half of the
cross/ against native/ split — and is what native/ packages get in their environment:
It falls back to the bare name when the tool is absent, so a missing one fails by its own
name rather than as an empty command, and it uses command -v rather than which: the
former is a POSIX shell builtin, the latter an external binary a minimal image may not ship.
List helpers¶
| Macro | Purpose |
|---|---|
$(call uniq,<list>) |
Remove duplicate words, preserving order |
$(call dedup,<string>,<delimiter>) |
De-duplicate a delimiter-separated string, preserving order |
$(call dedup_files,<files>) |
Remove duplicate files (compared by md5sum), preserving order |
$(call merge,<env>,<var>,<delimiter>) |
Every value of <var>= in <env>, last one first, joined with <delimiter> |
$(call comma_append,<list>,<item>) |
Append to a comma-separated list, or return it unchanged when <item> is empty |
BUILD_DEPENDS := $(call uniq,spk/$(FFMPEG_PACKAGE) $(BUILD_DEPENDS))
SPK_DEPENDS := $(call dedup,$(PYTHON_PACKAGE):$(SPK_DEPENDS),:)
Reading a Makefile¶
$(call read_makefile_var,<file>,<VAR>) returns the value <file> assigns to <VAR> (=, := or ?=), as raw text, without including the file: a reference inside the value is not expanded. It is empty when the file or the line is absent. The toolchain producers and overlays read a base toolchain's TC_TARGET or TC_GCC this way.
$(call toolchain_published_rev,<arch>,<dsm>,<suffix>) reads an overlay's PKG_REV that way: the revision at which the archive of <arch>-<dsm> is published, for the overlay directory suffix <suffix>. It takes the arch's own overlay, overlay/syno-<arch>-<dsm>_<suffix>, or else that of a generic arch built as it (overlay_dist_arch): x64-7.1 installs apollolake-7.1's archive, which has no overlay of its own. It is empty where neither exists. A producer builds one past it (mk/spksrc.native-toolchain.mk).
$(call toolchain_published_rev,apollolake,7.1,gcc-8.5) # v6, through x64-7.1
$(call toolchain_published_rev,qoriq,6.2.4,rust-1.82_gcc-4.9.3) # v5
$(call toolchain_published_rev,armv7,7.1,rust-1.98_gcc-8.5) # empty: no such overlay
See also¶
- Developer Guide: Makefile Variables — where these macros are commonly used
- Reference: Architectures — the architecture groups available for
ifeqconditions