Makefile Flashcards

1
Q

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?

A

target :: dependencies The double-colon is the trick

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

What is the function and syntax for selecting one word from a list?

A

$(word n,text) Extract the nth word (one-origin) of text.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

What is the function and syntax to evaluate each word in a list and expand each one individually in some expression?

A

$(foreach var,words,text) Evaluate text with var bound to each word in words, and concatenate the results.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is $? ?

A

The names of all prerequisites that are newer than the target.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which directive identifies targets which do not represent a file of the same name (the default behavior)?

A

.PHONY: targets…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which command line option invokes make to print commands that would be executed without actually executing them?

A

–just-print or -n

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the function and syntax for selecting the non-directory part of a file name?

A

$(notdir names…) Extract the non-directory part of each file name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the three elements of a rule?

A

Targets, Prerequisites (or Dependencies), and Commands

target [more targets] :[:] [prerequisites] [; commands] [commands] [commands]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the function and syntax for adding a suffix to a name?

A

$(addsuffix suffix,names…) Append suffix to each word in names.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the function and syntax for removing a pattern or pattern from a string?

A

$(filter-out pattern…,text) Select words in text that do not match any of the pattern words.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does a list look like?

A

A list looks like a string with words separated by spaces. Ex: MYLIST = fub.c bar.h goo.cpp

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is $% ?

A

The name of an archive member (used with ar).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Give an example of an explicit rule with a multi-line command

A

$(targets) : @echo $@; \ @touch $@ The key is the backslash.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Invoking with –print-data-base (-p) results in what?

A

Make prints Variables, Directories, Implicit Rules, Pattern-Specific Variable Values, Files (Explicit Rules), and VPath Search Values. In that order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the function and syntax for general pattern substitution?

A

$(patsubst pattern,replacement,text) Replace words matching pattern with replacement in text.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the function and syntax for counting the words in a list?

A

$(words text) Count the number of words in text.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the function and syntax to generate a warning?

A

$(warning text…) When this function is evaluated, make generates a warning with the message text.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which option or options show how make analyzes the dependency graph?

A

–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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the difference between include and -include?

A

-include ignores missing files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the function and syntax for selecting the directory part of a file name?

A

$(dir names…) Extract the directory part of each file name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What option can be used to find mistyped or misnamed variables?

A

–warn-undefined-variables Combine with –just-print to debug without building.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is $* ?

A

The stem with which an implicit rule matches. The stem is the pattern match in an implicit rule.

20
Q

Give an example of a one-line explicit rule.

A

$(targets) :; @echo $@; touch $@ The semicolon is the key

20
Q

What is the function and syntax to call a user-defined function?

A

$(call var,param,…) Evaluate the variable var replacing any references to $(1),$(2) with the first, second, etc. param values.

21
Q

What is the function and syntax for selecting the base part (no suffix or file extension) of a file name?

A

$(basename names…) Extract the base name (name without suffix) of each file name.

23
Q

What is the function and syntax for removing excess whitespace?

A

$(strip string) Remove excess whitespace characters from string.

23
Q

What are $(@D), $(@F), $(*D), $(*F), $(%D), $(%F), $(

A

The directory and file-within-directory parts of $@, $*, $%, $

24
Q

How do you expand a variable? Call a function?

A

$(var) $(call functionname)

26
Q

What is the function and syntax for sorting a list?

A

$(sort list) Sort the words in list lexicographically, removing duplicates.

28
Q

What is the difference between = and := ?

A

= is assignment := is expansion assignment Assignment expands the definition when the variable is used. Expansion assignment expands the definition when it appears in the Makefile, immediately (like procedural code).

29
Q

What is the function and syntax to run a shell command and return its output?

A

$(shell command) Execute a shell command and return its output.

31
Q

What is the function and syntax for finding a pattern or pattern within a string?

A

$(filter pattern…,text) Select words in text that match one of the pattern words.

32
Q

What does pattern notation do? Give an example.

A

Pattern notation enables rules to be written once instead of repeating the same rule for many files. %.pdf: %.ps; -ps2pdf $<

34
Q

What is the function and syntax for general text substitution?

A

$(subst from,to,text) Replace from with to in text.

34
Q

What is the function and syntax for selecting the suffix or file extension part of a file name?

A

$(suffix names…) Extract the suffix (the last dot and following characters) of each file name.

35
Q

What does $(a:b=c) do?

A

This is modified variable expansion, specifically a substitution reference. When $(a) is expanded, every occurrence of b at the END OF A WORD is replaced with c.

36
Q

What is the difference between an implicit rule and an explicit rule?

A

An implicit rule has targets and prerequisites, an explicit rule has commands. Rules can be split into explicit/implicit rules or merged together.

36
Q

Write a makefile that converts and Postscript(PS) file into a PDF using the command ps2pdf.

A

all: $(patsubst %.ps,%.pdf,$(wildcard *.ps)) %.pdf: %.ps; -ps2pdf $<

37
Q

What is a computed variable name?

A

$($(x)) The variable name is expanded, then the variable is expanded.

38
Q

What are the conditional directives?

A

ifdef variable ifndef variable ifeq (a,b) ifeq “a” “b” ifeq ‘a’ ‘b’ ifneq (a,b) ifneq “a” “b” ifneq ‘a’ ‘b’ else endif

40
Q

What is the function and syntax for selecting a slice of a list?

A

$(wordlist s,e,text) Returns the list of words in text from s to e.

41
Q

What are the command modifiers?

A

@command prevents display of the command -command suppresses error detection (make will not halt) !command executes command for EACH dependent file if $** or $? is used. $** expands into all dependencies, $? expands into those with later timestamps than targets.

42
Q

What is $@ ?

A

The name of the target

42
Q

What is $+ ?

A

The names of all prerequisites, including duplicates.

44
Q

What is the function and syntax for joining two parallel lists of words?

A

$(join list1,list2) Join two parallel lists of words.

45
Q

What is the function and syntax to generate a fatal error?

A

$(error text…) When this function is evaluated, make generates a fatal error with the message text.

46
Q

What is the function and syntax to print a string describing how a variable was defined?

A

$(origin variable) Return a string describing how the make variable variable was defined.

47
Q

What is the function and syntax to get a list of files given a wildcard pattern?

A

$(wildcard pattern…) Find file names matching a shell file name pattern (not a `%’ pattern).

48
Q

What is $^ ?

A

The names of all prerequisites with duplicates removed.

49
Q

What is the function and syntax for testing for a string within a string?

A

$(findstring find,text) Locate find in text. Returns the found or “”.

51
Q

What is the function and syntax for selecting the first word of a list?

A

$(firstword names…) Extract the first word of names.

52
Q

What is $< ?

A

The name of the first prerequisite.

53
Q

What is the function and syntax for adding a prefix to a name?

A

$(addprefix prefix,names…) Prepend prefix to each word in names.