Makefile Flashcards
What is the function and syntax to evaluate each word in a list and expand each one individually in some expression?
$(foreach var,words,text) Evaluate text with var bound to each word in words, and concatenate the results.
What is $? ?
The names of all prerequisites that are newer than the target.
What is the function and syntax for selecting one word from a list?
$(word n,text) Extract the nth word (one-origin) of text.
Which directive identifies targets which do not represent a file of the same name (the default behavior)?
.PHONY: targets…
What is the function and syntax for selecting the non-directory part of a file name?
$(notdir names…) Extract the non-directory part of each file name.
What are the three elements of a rule?
Targets, Prerequisites (or Dependencies), and Commands
target [more targets] :[:] [prerequisites] [; commands] [commands] [commands]
What is the function and syntax for adding a suffix to a name?
$(addsuffix suffix,names…) Append suffix to each word in names.
What is $% ?
The name of an archive member (used with ar).
Give an example of an explicit rule with a multi-line command
$(targets) : @echo $@; \ @touch $@ The key is the backslash.
What is the function and syntax for general pattern substitution?
$(patsubst pattern,replacement,text) Replace words matching pattern with replacement in text.
What is the function and syntax for counting the words in a list?
$(words text) Count the number of words in text.
What is the function and syntax to generate a warning?
$(warning text…) When this function is evaluated, make generates a warning with the message text.
Which option or options show how make analyzes the dependency graph?
–debug More powerful: –debug=option,option basic - targets and update actions verbose - additional info implicit - basic plus implicit rule searches jobs - subprocesses makefile - info about includes all - all (default with -d)
Invoking with –print-data-base (-p) results in what?
Make prints Variables, Directories, Implicit Rules, Pattern-Specific Variable Values, Files (Explicit Rules), and VPath Search Values. In that order.
What is the difference between include and -include?
-include ignores missing files.
What is the function and syntax for selecting the directory part of a file name?
$(dir names…) Extract the directory part of each file name.
What does a list look like?
A list looks like a string with words separated by spaces. Ex: MYLIST = fub.c bar.h goo.cpp
What option can be used to find mistyped or misnamed variables?
–warn-undefined-variables Combine with –just-print to debug without building.
What is $* ?
The stem with which an implicit rule matches. The stem is the pattern match in an implicit rule.
What is the function and syntax to call a user-defined function?
$(call var,param,…) Evaluate the variable var replacing any references to $(1),$(2) with the first, second, etc. param values.
What is the function and syntax for selecting the base part (no suffix or file extension) of a file name?
$(basename names…) Extract the base name (name without suffix) of each file name.