Make
lastmod 2024-12-17created 2014-10-1740 edits
(For the automation platform, see Make (Automation Platform).)
make is a program build tool used in software development, mainly on Unix-like operating systems. By defining the dependencies between files and the commands each file needs, it can compile programs, and it has a standard syntax for describing the process of producing the final program. Make interprets a file written in this structure (usually named Makefile) and performs the program build.
Category
- Make:AutomaticVariables
- Make:Function
- Make:ConditionSetting
- Make:ExtensionRule
- Make:MacroRule
- Make:Dependency
- Make:SpecialBuiltInTargetNames
- Make:Example
Options
-
-d - Prints Debugging Messages. Same as
--debug=a.
-
-C [dir] - Changes the Directory to run in.
-
-f [file] - Specifies the path of the
Makefileto use.
-
-j N - Runs N jobs in parallel. Similar to parallel.
-
-t - Use the -t option when you want to update the creation date without recompiling files. The option stands for Touch: instead of compiling, it only updates the files' creation date to the current time.
-
--debug[=options] - Prints debugging information. The options are as follows.
- a (all) All types of debugging output are enabled. This is equivalent to using ‘-d’.
- b (basic) Basic debugging prints each target that was found to be out-of-date, and whether the build was successful or not.
- v (verbose) A level above ‘basic’; includes messages about which makefiles were parsed, prerequisites that did not need to be rebuilt, etc. This option also enables ‘basic’ messages.
- i (implicit) Prints messages describing the implicit rule searches for each target. This option also enables ‘basic’ messages.
- j (jobs) Prints messages giving details on the invocation of specific subcommands.
- m (makefile) By default, the above messages are not enabled while trying to remake the makefiles. This option enables messages while rebuilding makefiles, too. Note that the ‘all’ option does enable this option. This option also enables ‘basic’ messages.
-
--print-data-baseor-p - Print make's internal database.
-
--trace - Flag not available on macOS (Darwin version, i386-apple-darwin11.3.0).
Error code
make's exit codes are as follows.
- 0: Exit status is 'Successful'
- 2: Make Encountered Errors
- 1: Return response to -q (question) flag, indicating that targets require updating
Basic
The basic structure of Make is a continuous list of basic rules, each made up of three parts: target, dependency, and command. The encoding must be ANSI, and the command part must start with a TAB character. The basic form is as follows.
Print all targets
$ make -qp | awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}' | sort -u | uniq
Operators
-
:= - Keeps storing a command once it has been given.
-
+= - Appends to the assignment.
-
?= - Does not change the macro if it is already set.
File include
To include another Makefile, use include as follows.
DirectorySearch
If a file listed as a target or prerequisite does not exist in the current directory, make searches the directories in VPATH. The syntax is as follows. A colon (:) is used as the separator.
Multiline
If a command runs longer than one line, you can split it across several lines with the \ character. Think of the preprocessor in the C language.
See also
- gccmakedep
- Autoconf
- Automake
- remake
- Make (Automation Platform)
Favorite site
- GNU Make homepage
- Wikipedia (en) page on MAKE
- KLDP GNU Make usage
- GNU Software Make manual 1
- GNU Make Korean manual 2
- Using GNU make smartly
- KLDP thread on how to use Makefile eval
- Using a Make library
- Generating Dependencies Automatically 3