Makefile Flashcards
Multiple explicit rules with the same target names is bad practice; you get a warning. How do you tell combine the commands from all rules?
target :: dependencies The double-colon is the trick
What is the function and syntax for selecting one word from a list?
$(word n,text) Extract the nth word (one-origin) of text.
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.
Which directive identifies targets which do not represent a file of the same name (the default behavior)?
.PHONY: targets…
Which command line option invokes make to print commands that would be executed without actually executing them?
–just-print or -n
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 function and syntax for removing a pattern or pattern from a string?
$(filter-out pattern…,text) Select words in text that do not match any of the pattern words.
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 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.
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 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)
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 option can be used to find mistyped or misnamed variables?
–warn-undefined-variables Combine with –just-print to debug without building.