Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Make (software)
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Rules=== Each rule begins with a ''dependency line'' which consists of the rule's [[Orientation (graph theory)|target]] name followed by a colon (:), and optionally a list of targets (also known as prerequisites) on which the rule's target depends.<ref>{{cite web|url=https://www.gnu.org/software/make/manual/html_node/Prerequisite-Types.html|title=Prerequisite Types (GNU make)|website=GNU.org|publisher=[[GNU Project]]|access-date=15 December 2020|archive-date=2 December 2020|archive-url=https://web.archive.org/web/20201202083734/https://www.gnu.org/software/make/manual/html_node/Prerequisite-Types.html|url-status=live}}</ref> target [target ...]: [component ...] {{keypress|TAB}}[command 1] . . . {{keypress|TAB}}[command n] Usually a rule has a single target, rather than multiple. A dependency line may be followed by a recipe: a series of [[Tab character|TAB]] indented command lines that define how to generate the target from the components (i.e. source files). If any prerequisite has a more recent timestamp than the target file or the target does not exist as a file, the recipe is performed. The first command may appear on the same line after the prerequisites, separated by a semicolon, <syntaxhighlight lang="make"> targets: prerequisites ; command </syntaxhighlight> for example, <syntaxhighlight lang="make"> hello: ; @echo "hello" </syntaxhighlight> Each command line must begin with a tab character. Even though a [[space character|space]] is also [[Whitespace (computer science)|whitespace]], Make requires tab. Since this often leads to confusion and mistakes, this aspect of makefile syntax is subject to criticism. [[Eric S. Raymond]] describes it as "one of the worst design botches in the history of Unix"<ref name="esr">"Chapter 15. Tools: make: Automating Your Recipes", ''The Art of Unix Programming'', [[Eric S. Raymond]] 2003</ref> and ''[[The Unix-Haters Handbook]]'' said "using tabs as part of the syntax is like one of those pungee [sic] stick traps in [[The Green Berets (film)|''The Green Berets'']]". Feldman explains the choice as caused by a [[Technical debt|workaround]] for an early implementation difficulty, and preserved by a desire for [[backward compatibility]] with the very first users: {{blockquote|Why the tab in column 1? [[Yacc]] was new, [[Lex (software)|Lex]] was brand new. I hadn't tried either, so I figured this would be a good excuse to learn. After getting myself snarled up with my first stab at Lex, I just did something simple with the pattern newline-tab. It worked, it stayed. And then a few weeks later I had a user population of about a dozen, most of them friends, and I didn't want to screw up my embedded base. The rest, sadly, is history.|Stuart Feldman<ref name="esr"/>}} GNU Make since version 3.82 allows the choice of any symbol (one character) as the recipe prefix using the .RECIPEPREFIX special variable: <syntaxhighlight lang="make"> .RECIPEPREFIX := : all: :@echo "recipe prefix symbol is set to '$(.RECIPEPREFIX)'" </syntaxhighlight> Each command is executed in a separate [[Unix shell|shell]]. Since operating systems use different shells, this can lead to unportable makefiles. For example, GNU Make (all POSIX Makes) executes commands with [[/bin/sh]] by default, where [[Unix]] commands like [[cp (Unix)|cp]] are normally used. In contrast, Microsoft's ''nmake'' executes commands with cmd.exe where [[Batch file|batch]] commands like [[copy (command)|copy]] are available but not necessarily cp. Since a recipe is optional, the dependency line can consist solely of components that refer to other targets: <syntaxhighlight lang="make"> realclean: clean distclean </syntaxhighlight> The following example rule is evaluated when Make updates target file.txt via {{code|make file.txt}}. If file.html is newer than file.txt or file.txt does not exist, then the command is run to generate file.txt from file.html. <syntaxhighlight lang="make"> file.txt: file.html lynx -dump file.html > file.txt </syntaxhighlight> A command can have one or more of the following prefixes (after the tab): * [[hyphen-minus|minus]] (-) specifies to ignore an error from the command * [[at sign|at]] (@) specifies to ''not'' output the command before it is executed * [[plus sign|plus]] (+) specifies to execute the command even if Make is invoked in "do not execute" mode Ignoring errors and silencing echo can alternatively be obtained via the special targets {{code|.IGNORE}} and {{code|.SILENT}}.<ref name=SUS>{{man|1|make|SUS}}</ref> Microsoft's NMAKE has predefined rules that can be omitted from these makefiles, e.g. {{code|c.obj $(CC)$(CFLAGS)|lang=make}}.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Make (software)
(section)
Add topic