2. call
The call can be used to create new
parameterized functions.
$(call variable,param,param,…)
reverse = $(2) $(1)
foo = $(call reverse,a,b)
This would be equal to
foo = b a
A function to manipulate, then return a
string.
2
3. define
define’ in makefile is like ‘=‘ operator.
It allows multiple lines and it is ended with
endef.
Eg.
define PROGRAM_template =
$(1): $$($(1)_OBJS) $$($(1)_LIBS:%=-l%)
ALL_OBJS += $$($(1)_OBJS)
endef
$(call PROGRAM_template,$(prog))
3
4. eval
dynamic makefile construction which are
the result of evaluating other variables and
functions.
the argument to the eval function is
expanded, then the results of that expansion
are parsed as makefile syntax.
A function, to use the input string as a part
of Makfile.
4
5. Example for call, define, and eval
PROGRAMS = server client
server_OBJS = server.o
client_OBJS = client.o
# Everything after this is generic
.PHONY: all
all: $(PROGRAMS)
define PROGRAM =
$(1): $$($(1)_OBJS)
ALL_OBJS += $$($(1)_OBJS)
endef
$(foreach prog,$(PROGRAMS),
$(eval $(call PROGRAM,$(prog))))
--expand 1.
prog = server client
server: $server_OBJS
ALL_OBJS += $(server_OBJS)
client: $client_OBJS
ALL_OBJS += $(client_OBJS)
--expand2.
server : server.o
ALL_OBJS += server.o
client: client.o
ALL_OBJS += client.o
5
6. Appendix: Variables
$? : updated dependencies, which is newer
than target itself.
$@ : the value of targets.
$< : the first value of dependencies.
$* : all files (w/o extension) in targets.
6