+# Concatenate variables together. The first argument is a list of variables
+# names to concatenate. The second argument is an optional prefix for the
+# variables and the third is the string to use as separator (" ~" if omitted).
+# For example:
+# X_A := a
+# X_B := b
+# $(call varcat,A B,X_, --)
+# Will produce something like "a -- b --"
+varcat = $(foreach v,$1,$($2$v)$(if $3,$3, ~))
+
+# Replace variables with specified values in a template file. The first
+# argument is a list of make variables names which will be replaced in the
+# target file. The strings @VARNAME@ in the template file will be replaced
+# with the value of the make $(VARNAME) variable and the result will be stored
+# in the target file. The second (optional) argument is a prefix to add to the
+# make variables names, so if the prefix is PREFIX_ and @VARNAME@ is found in
+# the template file, it will be replaced by the value of the make variable
+# $(PREFIX_VARNAME). The third and fourth arguments are the source file and
+# the destination file (both optional, $< and $@ are used if omitted). The
+# fifth (optional) argument are options to pass to the substitute sed command
+# (for example, use "g" if you want to do multiple substitutions per line).
+replace = $(call exec,sed '$(foreach v,$1,s|@$v@|$($2$v)|$5;)' $(if $3,$3,$<) \
+ > $(if $4,$4,$@))
+