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!
===Macros=== A makefile can define and use macros. Macros are usually referred to as ''variables'' when they hold simple string definitions, like {{code|1=CC=clang|lang=make}}. Macros in makefiles may be overridden in the [[command-line argument]]s passed to the Make utility. [[Environment variables]] are also available as macros. For example, the macro {{code|CC}} is frequently used in makefiles to refer to the location of a [[C (programming language)|C]] compiler. If used consistently throughout the makefile, then the compiler used can be changed by changing the value of the macro rather than changing each rule command that invokes the compiler. Macros are commonly named in [[all-caps]]: <syntaxhighlight lang="make"> MACRO = definition </syntaxhighlight> A macro value can consist of other macro values. The value of macro is expanded on each use [[lazy evaluation|lazily]]. A macro is used by expanding either via $''NAME'' or $(''NAME''). The latter is safer since omitting the parentheses leads to Make interpreting the next letter after the {{code|$}} as the entire variable name. An equivalent form uses curly braces rather than parentheses, i.e. {{code|${} }}, which is the style used in [[BSD]]. <syntaxhighlight lang="make"> NEW_MACRO = $(MACRO)-$(MACRO2) </syntaxhighlight> Macros can be composed of shell commands by using the [[command substitution]] operator <code>!=</code>.<ref>{{Cite web |url=https://pubs.opengroup.org/onlinepubs/9799919799/utilities/make.html |title=Make |access-date=2024-10-29 |archive-date=2024-10-05 |archive-url=https://web.archive.org/web/20241005234028/https://pubs.opengroup.org/onlinepubs/9799919799/utilities/make.html |url-status=live }}</ref> <syntaxhighlight lang="make"> YYYYMMDD != date </syntaxhighlight> The command-line syntax for overriding a macro is: <syntaxhighlight lang="bash"> make MACRO="value" [MACRO="value" ...] TARGET [TARGET ...] </syntaxhighlight> Makefiles can access predefined ''internal macros'', with {{code|?}} and {{code|@}} being common. <syntaxhighlight lang="make"> target: component1 component2 # echo components YOUNGER than TARGET echo $? # echo TARGET name echo $@ </syntaxhighlight> A common syntax when defining macros, which works on BSD and GNU Make, is to use {{mono|1=+=}}, {{mono|1=?=}}, and {{mono|1=!=}} instead of the equal sign ({{mono|1==}}).<ref>{{man|1|make|FreeBSD}}</ref>
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