Makefile - build a repository of archive using foreach function
$(foreach var,list,text)
var is the declared iterate variable. It should be used in text expression.
list is a word separated list. var takes every values of this list.
text is the expression that is evaluated with var.
This Makefile is an example of how to use foreach function. It is used conjunction with define directive, eval and call functions.
all:
@$(foreach i,one two three,echo $(i);)
one two three
To make a parallel with shell
for i in one two three; do
echo $i;
done
one two three
The Makefile contains its own example
pkg-m := a b c
a-vers := 0 1 2
a-deps := b c
a-preinst := true
b-vers := 3 4 5
b-deps := c
c-vers := 0
c-postinst := false
Here, it builds packages a-0, a-1, a-2, b-3, b-4, b-5 and c-0. Package a has a preinst script and c a postinst script.
pkg-m is the top level variable. It lists every packages to build (i.e. a, b and c).
Every packages can specify its versions, its dependencies and if it has package scripts. <pkgname>-vers lists every versions. If unspecified, 1 is assumed. <pkgname>-deps lists all dependencies by _<pkgname>_. Both variables are space separated list. <pkgname>-preinst, <pkgname>-postinst, <pkgname>-prerm and <pkgname>-postrm are boolean (true of false) to tells if <pkgname> has one of this package script.
The Makefile defines do_pkg($pkg) at top level for each _tgz-m packages. Then, this define-directive calls do_pkg_control($pkg, $vers) for each versions of -vers to generates the debian style control file. Finally, this define calls do_pkg_script($pkg, $vers, $script) for every boolean - which is set to true.
The following shell script is a good candidate to understand what the Makefile is doing
for pkg in ...; do
do_pkg $pkg
done
do_pkg() {
for vers in ...; do
do_pkg_control $1 $vers
done
}
do_pkg_control() {
...
for script in preinst postinst prerm postrm; do
do_pkg_script $1 $2 $script
done
}
do_pkg_script() {
...
}
Written by Gaël PORTAY gael.portay@gmail.com
Copyright (c) 2016-2017 Gaël PORTAY
This program is free software: you can redistribute it and/or modify it under the terms of the MIT License.