# Standard phony targets
Target | Function
----------|--------------------------------------------------------------------
all | Perform all tasks to build the application
install | Create an installation of the application from the compiled binaries
clean | Delete the binary files generated from sources
distclean | Delete all the generated files that were not in the original source distribution
TAGS | Create a tags table for use by editors
info | Create GNU info files from their Texinfo sources
check | Run any tests associated with this application
# Automatic Variables
$@ | The filename representing the target.
$% | The filename element of an archive member specification.
$< | The filename of the first prerequisite.
$? | The names of all prerequisites that are newer than the target, separated by spaces.
$^ | The filenames of all the prerequisites, separated by spaces. This list has duplicate
| filenames removed since for most uses, such as compiling, copying, etc., duplicates are not wanted.
$+ | Similar to $^, this is the names of all the prerequisites separated by spaces, except
| that $+ includes duplicates. This variable was created for specific situations such
| as arguments to linkers where duplicate values have meaning.
$* | The stem of the target filename. A stem is typically a filename without its suffix.
| (We’ll discuss how stems are computed later in the section “Pattern Rules.”) Its use
| outside of pattern rules is discouraged.
VPATH = src
vpath pattern directory-list
vpath %.c src
# Special Targets
.INTERMEDIATE
Prerequisites of this special target are treated as intermediate files. If make creates
the file while updating another target, the file will be deleted automatically when
make exits. If the file already exists when make considers updating the file, the file
will not be deleted.
This can be very useful when building custom rule chains. For instance, most
Java tools accept Windows-like file lists. Creating rules to build the file lists and
marking their output files as intermediate allows make to clean up many temporary files.
.SECONDARY
Prerequisites of this special target are treated as intermediate files but are never
automatically deleted. The most common use of .SECONDARY is to mark object
files stored in libraries. Normally these object files will be deleted as soon as they
are added to an archive. Sometimes it is more convenient during development to
keep these object files, but still use the make support for updating archives.
.PRECIOUS
When make is interrupted during execution, it may delete the target file it is
updating if the file was modified since make started. This is so make doesn't leave
a partially constructed (possibly corrupt) file laying around in the build tree.
There are times when you don't want this behavior, particularly if the file is large
and computationally expensive to create. If you mark the file as precious, make
will never delete the file if interrupted.
Use of .PRECIOUS is relatively rare, but when it is needed it is often a life saver.
Note that make will not perform an automatic delete if the commands of a rule
generate an error. It does so only when interrupted by a signal.
.DELETE_ON_ERROR
This is sort of the opposite of .PRECIOUS. Marking a target as .DELETE_ON_ERROR
says that make should delete the target if any of the commands associated with
the rule generates an error. make normally only deletes the target if it is interrupted by a signal.
target...: variable = value
target...: variable := value
target...: variable += value
target...: variable ?= value
--include-dir (or -I)
-include i-may-not-exist.mk
@echo "$(MAKE_VERSION)"
--directory (-C)
@echo "$(CURDIR)"
@echo "$(MAKECMDGOALS)"
@echo "$(MAKEFILE_LIST)"
@echo "$(.VARIABLES)"
# String Functions
$(filter pattern... ,text)
$(filter-out pattern... ,text)
$(findstring string,text)
$(subst search-string,replace-string,text)
$(patsubst search-pattern,replace-pattern,text)
$(words text)
$(word n,text)
$(firstword text)
$(wordlist start,end,text)
# Important Miscellaneous Functions
$(sort list)
$(shell command)
# Filename Functions
$(wildcard pattern...)
$(dir list...)
$(notdir name...)
$(suffix name...)
$(basename name...)
$(addsuffix suffix,name...)
$(addprefix prefix,name...)
$(join prefix-list,suffix-list)
# Flow Control
$(if condition,then-part,else-part)
$(error text)
$(foreach variable,list,body)
# Less Important Miscellaneous Functions
$(strip text)
$(origin variable)
$(warning text)
@ | Do not echo the command. For historical compatibility, you can make your tar-
| get a prerequisite of the special target .SILENT if you want all of its commands to
| be hidden. Using @ is preferred, however, because it can be applied to individual
| commands within a command script. If you want to apply this modifier to all
| targets (although it is hard to imagine why), you can use the --silent (or -s)
| option.
|
- | The dash prefix indicates that errors in the command should be ignored by make.
| By default, when make executes a command, it examines the exit status of the
| program or pipeline, and if a nonzero (failure) exit status is returned, make termi-
| nates execution of the remainder of the command script and exits. This modi-
| fier directs make to ignore the exit status of the modified line and continue as if
| no error occurred.
|
+ | The plus modifier tells make to execute the command even if the --just-print (or
| -n) command-line option is given to make. It is used when writing recursive
| makefiles.
# Debugging
--just-print -p
--print-data-base -n
--warn-undefined-variables
No comments:
Post a Comment