Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Make (software)
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!
{{short description|Software build automation tool}} {{Infobox programming language | name = <!-- otherwise defaults to {{PAGENAME}} --> | logo = <!-- (filename) --> | logo caption = | screenshot = <!-- (filename) --> | screenshot caption = | paradigm = [[macro (computer science)|macro]], [[declarative programming|declarative]] | family = | designer = [[Stuart Feldman]] | developer = <!-- or: | developers = --> | released = {{Start date and age|1976|04}} | latest release version = | latest release date = <!-- {{Start date and age|YYYY|MM|DD|df=yes/no}} --> | latest preview version = | latest preview date = <!-- {{Start date and age|YYYY|MM|DD|df=yes/no}} --> | typing = | scope = | programming language = [[C (programming language)|C]] | discontinued = | platform = | operating system = [[Unix-like]], [[Inferno (operating system)|Inferno]] | license = | file ext = | file format = [[#Makefile|Makefile]] | implementations = BSD, GNU, nmake | dialects = BSD make, GNU make, Microsoft nmake | influenced by = | influenced = [[Apache Ant|Ant]], [[Rake (software)|Rake]], [[MSBuild]], and ''[[List of build automation software#Non-Make-based tools|others]]'' }} In [[software development]], '''Make''' is a [[command-line interface]] [[software tool]] that performs actions ordered by configured [[Dependence analysis|dependencies]] as defined in a [[configuration file]] called a ''makefile''. It is commonly used for [[build automation]] to [[Software build|build]] [[executable|executable code]] (such as a [[computer program|program]] or [[library (software)|library]]) from [[source code]]. But, not limited to building, Make can perform any operation available via the [[Shell (computing)|operating system shell]]. Make is widely used, especially in [[Unix]] and [[Unix-like]] [[operating system]]s, even though many competing technologies and tools are available, including similar tools that perform actions based on dependencies, some [[compiler (computing)|compiler]]s and interactively via an [[integrated development environment]]. In addition to referring to the original [[Unix]] tool, Make is also a technology since multiple tools have been [[implementation|implemented]] with roughly the same functionality {{endash}} including similar makefile [[Syntax (programming languages)|syntax]] and [[Semantics (computer science)|semantics]]. ==Origin== [[Stuart Feldman]] created Make while at [[Bell Labs]]. An early version was completed in April 1976.<ref name="v7-version">{{cite web|url=http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7%2Fusr%2Fsrc%2Fcmd%2Fmake%2Fident.c|archive-url=https://archive.today/20130901165315/http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7%2Fusr%2Fsrc%2Fcmd%2Fmake%2Fident.c|url-status=dead|title=V7/usr/src/cmd/make/ident.c|date=1 September 2013|archive-date=1 September 2013|website=tuhs.org|access-date=18 March 2018}}</ref><ref>{{cite journal|last1=Feldman|first1=S. I.|title=Make --- A Program for Maintaining Computer Programs|journal=Software: Practice and Experience|date=April 1979|volume=9|issue=4|pages=255–265|doi=10.1002/spe.4380090402|citeseerx=10.1.1.39.7058|s2cid=33059412}}</ref><ref name=razzveer/> Feldman received the 2003 [[ACM Software System Award]] for authoring Make.<ref>{{Cite book|pages=94|title=Practical Development Environments|author=Matthew Doar|isbn=978-0-596-00796-6|year=2005|publisher=[[O'Reilly Media]]}}</ref> Feldman describes the inspiration to write Make as arising from a coworker's frustration with the available tooling of the time: {{blockquote|Make originated with a visit from [[Stephen C. Johnson|Steve Johnson]] (author of yacc, etc.), storming into my office, cursing the Fates that had caused him to waste a morning debugging a correct program (bug had been fixed, file hadn't been compiled, {{code|cc *.o}} was therefore unaffected). As I had spent a part of the previous evening coping with the same disaster on a project I was working on, the idea of a tool to solve it came up. It began with an elaborate idea of a dependency analyzer, boiled down to something much simpler, and turned into Make that weekend. Use of tools that were still wet was part of the culture. Makefiles were text files, not magically encoded binaries, because that was the [[Unix philosophy|Unix ethos]]: printable, debuggable, understandable stuff.|Stuart Feldman|''[[The Art of Unix Programming]]'', [[Eric S. Raymond]] 2003}} Before Make, building on Unix mostly consisted of [[shell script]]s written for each program's codebase. Make's dependency ordering and out-of-date checking makes the build process more robust and more efficient. The makefile allowed for better organization of build logic and often fewer build files. Make is widely used in part due to its early inclusion in [[Unix]], starting with [[PWB/UNIX]] 1.0, which featured a variety of software development tools.<ref name=razzveer>{{cite journal |last1=Thompson |first1=T. J. |title=Designer's Workbench: Providing a Production Environment |journal=Bell System Technical Journal |date=November 1980 |volume=59 |issue=9 |pages=1811–1825 |doi=10.1002/j.1538-7305.1980.tb03063.x|s2cid=27213583 |quote=In the general maintenance of DWB, we have used the Source Code Control System and make utility provided by the PWB/UNIX* interactive operating system.}}</ref> ==Variants== {{anchor|Derivatives}} Make has been [[Rewrite (programming)|implemented]] numerous times, generally using the same makefile format and providing the same features, but some providing enhancements from the original. Examples: * Sun DevPro Make appeared in 1986 with SunOS-3.2. With SunOS-3.2. It was delivered as an optional program; with SunOS-4.0, SunPro Make was made the default Make program.<ref>{{cite web|url=https://groups.google.com/forum/|title=Google Groups|website=arquivo.pt|access-date=18 March 2018|url-status=bot: unknown|archive-url=http://arquivo.pt/wayback/20110122130054/https://groups.google.com/forum/|archive-date=22 January 2011}}</ref>{{better source needed|date=May 2017}} In December 2006, Sun DevPro Make was made open source as part of the efforts to open-source [[Solaris (operating system)|Solaris]].<ref>{{cite web|url=https://blogs.oracle.com/jimgris/entry/opensolaris_at_two|title=OpenSolaris at Two (Jim Grisanzio)|date=12 December 2013|access-date=18 March 2018|url-status=dead|archive-url=https://web.archive.org/web/20131212131557/https://blogs.oracle.com/jimgris/entry/opensolaris_at_two|archive-date=12 December 2013}}</ref><ref>Grisanzio, Jim. [http://www.guug.de/veranstaltungen/osdevcon2007/slides/grisanzio-opensolaris-story-guug.pdf The OpenSolaris Story]{{Dead link|date=December 2024 |bot=InternetArchiveBot |fix-attempted=yes }}.</ref> * dmake or Distributed Make that came with Sun Solaris Studio as its default Make, but not the default one on the Solaris Operating System (SunOS). It was originally required to build OpenOffice, but in 2009<ref name="lo"/> the build system was rewritten to use GNU Make. While [[Apache OpenOffice]] still contains a mixture of both build systems,<ref name="oo">{{cite web|url=https://wiki.openoffice.org/wiki/Documentation/Building_Guide_AOO#Make_Systems_Used_by_Apache_OpenOffice|title=Apache OpenOffice Building Guide - Apache OpenOffice Wiki|website=wiki.openoffice.org|access-date=18 March 2018|archive-date=17 March 2018|archive-url=https://web.archive.org/web/20180317161912/https://wiki.openoffice.org/wiki/Documentation/Building_Guide_AOO#Make_Systems_Used_by_Apache_OpenOffice|url-status=live}}</ref> the much more actively developed [[LibreOffice]] only uses the modernized "gbuild" now.<ref name="lo">{{cite web|url=https://wiki.documentfoundation.org/Development/Gbuild|title=Development/Gbuild - The Document Foundation Wiki|website=wiki.documentfoundation.org|access-date=18 March 2018}}</ref> * [[BSD]] Make (''pmake'',<ref>{{citation|url=https://svnweb.freebsd.org/base/stable/2.0.5/usr.bin/make/make.h?revision=8869&view=markup|title=FreeBSD 2.0.5 Make Source Code|date=1993|access-date=2016-05-06|archive-date=2023-03-06|archive-url=https://web.archive.org/web/20230306011019/https://svnweb.freebsd.org/base/stable/2.0.5/usr.bin/make/make.h?revision=8869&view=markup|url-status=live}}</ref> ''bmake''<ref name="fbsdbmake">{{Cite web|url=https://www.freebsd.org/cgi/man.cgi?query=bmake&sektion=1|title=Bmake(1)}}</ref> or ''fmake''<ref>{{Cite web |title=fmake(1) General Commands Manual |url=https://manpages.debian.org/jessie/freebsd-buildutils/fmake.1 |access-date=2020-11-30 |archive-date=2021-04-20 |archive-url=https://web.archive.org/web/20210420110426/https://manpages.debian.org/jessie/freebsd-buildutils/fmake.1 |url-status=live }}</ref>), which is derived from Adam de Boor's work on a version of Make capable of building targets in [[Parallel computing|parallel]], and survives with varying degrees of modification in [[FreeBSD]],<ref name="fbsdbmake"/> [[NetBSD]]<ref>{{cite web|url=https://netbsd.gw.com/cgi-bin/man-cgi?make++NetBSD-current|title=make|website=NetBSD Manual Pages|access-date=9 July 2020|archive-date=9 July 2020|archive-url=https://web.archive.org/web/20200709221421/https://netbsd.gw.com/cgi-bin/man-cgi?make++NetBSD-current|url-status=dead}}</ref> and [[OpenBSD]].<ref>{{cite web|url=https://man.openbsd.org/make.1#HISTORY|title=make(1) - OpenBSD manual pages|website=man.openbsd.org|access-date=18 March 2018|archive-date=5 February 2018|archive-url=https://web.archive.org/web/20180205000820/https://man.openbsd.org/make.1#HISTORY|url-status=live}}</ref> Distinctively, it has conditionals and iterative loops which are applied at the parsing stage and may be used to conditionally and programmatically construct the makefile,<ref>{{cite web|url=https://www.freebsd.org/cgi/man.cgi?query=make&manpath=FreeBSD+12.1-RELEASE+and+Ports#INCLUDE%09STATEMENTS,_CONDITIONALS_AND_FOR_LOOPS|title=make|website=FreeBSD|access-date=9 July 2020|quote=Makefile inclusion, conditional structures and for loops reminiscent of the C programming language are provided in make.|archive-date=11 July 2020|archive-url=https://web.archive.org/web/20200711144451/https://www.freebsd.org/cgi/man.cgi?query=make&manpath=FreeBSD%2012.1-RELEASE%20and%20Ports#INCLUDE%09STATEMENTS,_CONDITIONALS_AND_FOR_LOOPS|url-status=live}}</ref> including generation of targets at runtime.{{citation needed|date=September 2014}} * [[GNU]] Make (short ''gmake'') is the standard implementation of Make for Linux and macOS.<ref>{{citation |url=http://www.linuxdevcenter.com/pub/a/linux/excerpts/9780596100292/gnu-make-utility.html |title=Unix in a Nutshell, Fourth Edition |author=Arnold Robbins |date=2005 |publisher=O'Reilly |access-date=2014-05-28 |archive-date=2014-11-21 |archive-url=https://web.archive.org/web/20141121143147/http://www.linuxdevcenter.com/pub/a/linux/excerpts/9780596100292/gnu-make-utility.html |url-status=live }}</ref> It provides several extensions over the original Make, such as conditionals. It also provides many built-in functions which can be used to eliminate the need for shell-scripting in the makefile rules as well as to manipulate the variables set and used in the makefile.<ref>{{citation |url=https://www.gnu.org/software/make/manual/html_node/Functions.html |title=8. Functions for Transforming Text |work=GNU make |publisher=Free Software Foundation |date=2013 |access-date=2014-05-28 |archive-date=2014-05-23 |archive-url=https://web.archive.org/web/20140523114951/http://www.gnu.org/software/make/manual/html_node/Functions.html |url-status=live }}</ref> For example, the ''foreach'' function can be used to iterate over a list of values, such as the names of files in a given directory.<ref>{{citation |url=https://www.gnu.org/software/make/manual/html_node/Foreach-Function.html#Foreach-Function |title=8.5 The foreach Function |work=GNU make |publisher=Free Software Foundation |date=2013 |access-date=2014-05-28 |archive-date=2014-05-22 |archive-url=https://web.archive.org/web/20140522071851/http://www.gnu.org/software/make/manual/html_node/Foreach-Function.html#Foreach-Function |url-status=live }}</ref> GNU Make is required for building many software systems, including [[GNU Compiler Collection]] (GCC) (since version 3.4<ref>{{cite web |url=https://www.gnu.org/software/gcc/gcc-3.4/changes.html |title=GCC 3.4 Release Series Changes, New Features, and Fixes |publisher=Free Software Foundation |date=2006 |access-date=2016-07-22 |archive-date=2016-10-24 |archive-url=https://web.archive.org/web/20161024053749/https://www.gnu.org/software/gcc/gcc-3.4/changes.html |url-status=live }}</ref>), the Linux kernel,<ref>{{cite magazine |url=http://www.linuxjournal.com/content/kbuild-linux-kernel-build-system |title=Kbuild: the Linux Kernel Build System |author=Javier Martinez Canillas |magazine=Linux Journal |date=December 26, 2012 |access-date=May 28, 2014 |archive-date=November 21, 2014 |archive-url=https://web.archive.org/web/20141121005050/http://www.linuxjournal.com/content/kbuild-linux-kernel-build-system |url-status=live }}</ref><ref>{{citation |url=http://www.linuxtopia.org/online_books/linux_kernel/kernel_configuration/ch03.html |title=Linux Kernel in a Nutshell |author=Greg Kroah-Hartman |publisher=O'Reilly |date=2006 |access-date=2014-05-28 |archive-date=2014-08-11 |archive-url=https://web.archive.org/web/20140811131446/http://linuxtopia.org/online_books/linux_kernel/kernel_configuration/ch03.html |url-status=live }}</ref> Apache OpenOffice,<ref name="oo"/> LibreOffice,<ref name="lo"/> and [[Mozilla Firefox]].<ref>{{Cite web | url=https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Build_Instructions | title=Build Instructions | access-date=2017-05-12 | archive-date=2017-04-25 | archive-url=https://web.archive.org/web/20170425211219/https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Build_Instructions | url-status=dead }}</ref> * Rocky Bernstein's Remake<ref>{{cite web|url=http://bashdb.sourceforge.net/remake/|title=Remake – GNU Make with comprehensible tracing and a debugger|author=Rocky Bernstein|access-date=2018-01-20|archive-date=2018-01-21|archive-url=https://web.archive.org/web/20180121071405/http://bashdb.sourceforge.net/remake/|url-status=live}}</ref> is a fork of GNU Make and provides several extensions over GNU Make, such as better location and error-location reporting, execution tracing, execution profiling, and it contains a debugger. * Glenn Fowler's ''nmake''<ref>{{cite web |url=http://www2.research.att.com/~astopen/nmake/nmake.html |title=nmake Overview |author=Glenn Fowler |publisher=Information and Software Systems Research, AT&T Labs Research |date=January 4, 2012 |access-date=May 26, 2014 |archive-url=https://web.archive.org/web/20150902010526/http://www2.research.att.com/~astopen/nmake/nmake.html |archive-date=September 2, 2015 |url-status=dead }}</ref> (unrelated to the same-named Microsoft variant) is incompatible with the UNIX variant, but provides features which, according to some, reduce the size of makefiles by a factor of 10. * [[Microsoft]] ''nmake'' is normally installed with [[Visual Studio]].<ref>{{cite web |url=http://msdn.microsoft.com/en-us/library/dd9y37ha.aspx |title=NMAKE Reference Visual Studio 2015 |publisher=Microsoft |date=2015 |access-date=2009-11-27 |archive-date=2009-12-08 |archive-url=https://web.archive.org/web/20091208064323/http://msdn.microsoft.com/en-us/library/dd9y37ha.aspx |url-status=live }}</ref> It supports preprocessor directives such as includes and conditional expressions which use variables set on the command-line or within the makefiles.<ref>{{cite web |url=http://msdn.microsoft.com/en-us/library/7y32zxwh.aspx |title=Makefile Preprocessing Directives |date=2014 |access-date=2014-05-27 |archive-date=2014-08-26 |archive-url=https://web.archive.org/web/20140826122139/http://msdn.microsoft.com/en-us/library/7y32zxwh.aspx |url-status=live }}</ref><ref>{{cite web |url=http://msdn.microsoft.com/en-us/library/8t2e8d78.aspx |title=Makefile Preprocessing Operators |publisher=Microsoft |date=2014 |access-date=2014-05-27 |archive-date=2014-08-26 |archive-url=https://web.archive.org/web/20140826122134/http://msdn.microsoft.com/en-us/library/8t2e8d78.aspx |url-status=live }}</ref> Inference rules differ from Make; for example they can include search paths.<ref>{{cite web |url=http://msdn.microsoft.com/en-us/library/hk9ztb8x.aspx |title=Search Paths in Rules |publisher=Microsoft |date=2014 |access-date=2014-05-27 |archive-date=2014-08-26 |archive-url=https://web.archive.org/web/20140826122150/http://msdn.microsoft.com/en-us/library/hk9ztb8x.aspx |url-status=live }}</ref> *[[Embarcadero Technologies|Embarcadero]] make has a command-line option that "Causes MAKE to mimic Microsoft's NMAKE.".<ref>{{cite web |url=http://docs.embarcadero.com/products/rad_studio/radstudio2007/RS2007_helpupdates/HUpdate4/EN/html/devwin32/make_xml.html |title=MAKE |publisher=CodeGear(TM) |date=2008 |access-date=2014-08-24 |archive-date=2017-03-02 |archive-url=https://web.archive.org/web/20170302093429/http://docs.embarcadero.com/products/rad_studio/radstudio2007/RS2007_helpupdates/HUpdate4/EN/html/devwin32/make_xml.html |url-status=live }}</ref> *[[Qt Project]]'s ''Jom'' tool is a clone of nmake.<ref>{{cite web |url=https://wiki.qt.io/Jom |title=Jom - Qt Wiki |publisher=Qt Project |date=2021 |access-date=2021-01-26 |archive-date=2021-02-02 |archive-url=https://web.archive.org/web/20210202130552/https://wiki.qt.io/Jom |url-status=live }}</ref> * ''Mk'' replaced Make in [[Research Unix]], starting from version 9.<ref name="reader">{{cite tech report |first=M. D. |last=McIlroy |author-link=Doug McIlroy |title=A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986 |number=CSTR 139 |institution=Bell Labs |year=1987 |url=http://www.9grid.fr/www.9grid.fr/misc/unix-reader.pdf}}</ref> A redesign of the original tool by Bell Labs programmer Andrew G. Hume, it features a different syntax. Mk became the standard build tool in [[Plan 9 from Bell Labs|Plan 9]], Bell Labs' intended successor to Unix.<ref>{{cite encyclopedia |last1=Hume |first1=Andrew G. |first2=Bob |last2=Flandrena |title=Maintaining files on Plan 9 with Mk |encyclopedia=Plan 9 Programmer’s Manual |publisher=AT&T Bell Laboratories |year=2002 |url=http://9p.io/sys/doc/mk.html |archive-url=https://web.archive.org/web/20150711105955/http://9p.io/sys/doc/mk.html |archive-date=July 11, 2015 |url-status=live}}</ref> * ''Kati'' is Google's replacement of GNU Make, as of 2020 used in [[Android OS]] builds. It translates the makefile into [[Ninja (build system)|ninja]] for faster incremental builds (similar to the cmake metatool).<ref>{{cite web |title=google/kati: An experimental GNU make clone |url=https://github.com/google/kati |website=GitHub |date=30 November 2020}}</ref> * Snakemake is a Python-driven implementation for compiling and running [[bioinformatics]] workflows.<ref>{{Cite journal |last1=Mölder |first1=Felix |last2=Jablonski |first2=Kim Philipp |last3=Letcher |first3=Brice |last4=Hall |first4=Michael B. |last5=Tomkins-Tinch |first5=Christopher H. |last6=Sochat |first6=Vanessa |last7=Forster |first7=Jan |last8=Lee |first8=Soohyun |last9=Twardziok |first9=Sven O. |last10=Kanitz |first10=Alexander |last11=Wilm |first11=Andreas |date=2021-04-19 |title=Sustainable data analysis with Snakemake |journal=F1000Research |language=en |volume=10 |pages=33 |doi=10.12688/f1000research.29032.2 |issn=2046-1402 |pmc=8114187 |pmid=34035898 |doi-access=free }}</ref> [[POSIX]] includes standardization of the basic features and operation of the Make utility, and is implemented with varying degrees of compatibility with Unix-based versions of Make. In general, simple makefiles may be used between various versions of Make with reasonable success. GNU Make, Makepp and some versions of BSD Make default to looking first for files named "GNUmakefile",<ref>{{cite web |url=https://www.gnu.org/software/make/manual/make.html#Makefile-Names |title=GNU 'make' |publisher=Free Software Foundation |access-date=2014-04-16 |archive-date=2018-06-05 |archive-url=https://web.archive.org/web/20180605023853/https://www.gnu.org/software/make/manual/make.html#Makefile-Names |url-status=live }}</ref> "Makeppfile"<ref>{{cite web |url=http://makepp.sourceforge.net/2.0/makepp_command.html#f_makefile |title=Makepp }}</ref> and "BSDmakefile"<ref>{{cite web |url=https://www.freebsd.org/cgi/man.cgi?query=make&apropos=0&sektion=0&manpath=FreeBSD+6.2-RELEASE&format=html#DESCRIPTION |title=Free BSD make |access-date=2018-05-07 |archive-date=2018-05-08 |archive-url=https://web.archive.org/web/20180508121646/https://www.freebsd.org/cgi/man.cgi?query=make&apropos=0&sektion=0&manpath=FreeBSD+6.2-RELEASE&format=html#DESCRIPTION |url-status=live }}</ref> respectively, which allows one to put makefiles which use implementation-defined behavior in separate locations. ==Use== In general, based on a makefile, Make updates target files from source files if any source file has a newer [[timestamp]] than the target file or the target file does not exist. For example, this could include compiling [[C (programming language)|C]] files ({{Code|*.c}}) into [[object file]]s, then linking the object files into an executable program. Or this could include compiling [[TypeScript]] files ({{Code|*.ts}}) to [[JavaScript]] for use in a browser. Other examples include: convert a source image file to another format, copy a file to a content management system, and send e-mail about build status. A makefile defines targets where each is either a file to generate or is a user-defined concept, called a ''phony'' target. Make updates the targets passed as arguments: <syntaxhighlight lang="bash"> make [-f makefile] [options] [targets] </syntaxhighlight> If no target is specified, Make updates the first target in the makefile which is often a phony target to perform the most commonly used action. Make skips build actions if the target file timestamp is after that of the source files.<ref>[http://alvinalexander.com/linux/unix-linux-ls-command-file-sort-sorting How to sort Linux ls command file output] {{webarchive |url=https://web.archive.org/web/20160913020855/http://alvinalexander.com/linux/unix-linux-ls-command-file-sort-sorting |date=September 13, 2016 }}</ref> Doing so optimizes the build process by skipping actions when the target file is up-to-date, but sometimes updates are skipped erroneously due to file timestamp issues including restoring an older version of a source file, or when a [[Network File System|network filesystem]] is a source of files and its clock or time zone is not synchronized with the machine running Make. Also, if a source file's timestamp is in the future, make repeatedly triggers unnecessary actions, causing longer build time. When Make starts, it uses the makefile specified on the command-line or if not specified, then uses the one found by via specific search rules. Generally, Make defaults to using the file in the [[working directory]] named {{mono|Makefile}}. GNU Make searches for the first file matching: {{mono|GNUmakefile}}, {{mono|makefile}}, or {{mono|Makefile}}. Make processes the options of the command-line based on the loaded makefile. ==Makefile== {{Anchor|makefile}} {{Infobox file format |name=Makefile |uniform type=public.make-source<ref>{{cite web |url=https://developer.apple.com/documentation/uniformtypeidentifiers/uttype/3750150-makefile |title=makefile |work=Apple Developer Documentation: Uniform Type Identifiers |publisher=[[Apple Inc]] |access-date=2023-05-22 |archive-date=2023-05-22 |archive-url=https://web.archive.org/web/20230522155039/https://developer.apple.com/documentation/uniformtypeidentifiers/uttype/3750150-makefile |url-status=live }}</ref> }} The '''makefile''' language is partially [[declarative programming]] where end conditions are described but the order in which actions are to be taken is not.<ref>Adams, P. and Solomon, M., 1993, An overview of the CAPITL software development environment. In International Workshop on Software Configuration Management (pp. 1-34). Berlin, Heidelberg: Springer Berlin Heidelberg.</ref><ref>[http://phoenix.labri.fr/wiki/doku.php?id=an_overview_on_dsls an overview on dsls] {{webarchive |url=https://web.archive.org/web/20071023021126/http://phoenix.labri.fr/wiki/doku.php?id=an_overview_on_dsls |date=October 23, 2007 }}, 2007/02/27, phoenix wiki</ref><ref>[http://lists.w3.org/Archives/Public/www-ws-arch/2002Aug/0105.html Re: Choreography and REST] {{webarchive |url=https://web.archive.org/web/20160912144047/http://lists.w3.org/Archives/Public/www-ws-arch/2002Aug/0105.html |date=September 12, 2016 }}, from Christopher B Ferris on 2002-08-09</ref><ref>[http://www.robots.ox.ac.uk/~tgtjr/makefiles.html Target Junior Makefiles] {{webarchive |url=https://web.archive.org/web/20100107082837/http://www.robots.ox.ac.uk/~tgtjr/makefiles.html |date=January 7, 2010 }}, Andrew W. Fitzgibbon and William A. Hoffman</ref> This type of programming can be confusing to programmers used to [[imperative programming]]. Makefiles can contain the following constructs:<ref>[https://www.gnu.org/software/make/manual/html_node/Makefile-Contents.html 3.1 What Makefiles Contain] {{Webarchive|url=https://web.archive.org/web/20210505100531/https://www.gnu.org/software/make/manual/html_node/Makefile-Contents.html |date=2021-05-05 }}, ''GNU make'', [[Free Software Foundation]]</ref> * ''Explicit rule'': defines when and how to update a target, listing ''prerequisites'' (dependent targets) and commands that define the update action, called the ''recipe'' * ''Implicit rule'': defines when and how to remake a class of files based on their names, including how a target depends on a file with a name similar to the target and an update recipe * ''Variable definition'': associates a text value with a name that can be substituted into later text * ''Directive'': instruction to do something special such as include another makefile * ''[[Comment (computer programming)|Comment]]'': line starting with {{code|#}} ===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}}. ===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> ===Suffix rules=== Suffix rules have "targets" with names in the form {{code|.FROM.TO}} and are used to launch actions based on file extension. In the command lines of suffix rules, POSIX specifies<ref name=posix-macros /> that the internal macro {{code|$<}} refers to the first prerequisite and {{code|$@}} refers to the target. In this example, which converts any HTML file into text, the shell redirection token {{code|>}} is part of the command line, whereas {{code|$<}} is a macro referring to the HTML file: <syntaxhighlight lang="make"> .SUFFIXES: .txt .html # From .html to .txt .html.txt: lynx -dump $< > $@ </syntaxhighlight> When called from the command line, the example above expands: <syntaxhighlight lang="console"> $ make -n file.txt lynx -dump file.html > file.txt </syntaxhighlight> ===Pattern rules === Suffix rules cannot have any prerequisites of their own.<ref>{{cite web|url=https://www.gnu.org/software/make/manual/html_node/Suffix-Rules.html#Suffix-Rules|title=GNU make manual: suffix rules|publisher=Free Software Foundation|access-date=2014-05-24|archive-date=2014-05-22|archive-url=https://web.archive.org/web/20140522130224/http://www.gnu.org/software/make/manual/html_node/Suffix-Rules.html#Suffix-Rules|url-status=live}}</ref> If they have any, they are treated as normal files with unusual names, not as suffix rules. GNU Make supports suffix rules for compatibility with old makefiles but otherwise encourages usage of ''pattern rules''.<ref>{{cite web|url=https://www.gnu.org/software/make/manual/html_node/Pattern-Rules.html#Pattern-Rules|title=GNU make manual: pattern rules|publisher=Free Software Foundation|access-date=2014-05-24|archive-date=2014-05-28|archive-url=https://web.archive.org/web/20140528170600/http://www.gnu.org/software/make/manual/html_node/Pattern-Rules.html#Pattern-Rules|url-status=live}}</ref> A pattern rule looks like an ordinary rule, except that its target contains exactly one {{code|%}} character within the string. The target is considered a pattern for matching file names: the {{code|%}} can match any substring of zero or more characters,<ref>[http://www.lehman.cuny.edu/cgi-bin/man-cgi?make+1 See section ''Pattern Matching Rules'' in the SunPro man page] {{webarchive|url=https://web.archive.org/web/20140529103302/http://www.lehman.cuny.edu/cgi-bin/man-cgi?make%201 |date=May 29, 2014 }}</ref> while other characters match only themselves. The prerequisites likewise use {{code|%}} to show how their names relate to the target name. The example above of a suffix rule would look like the following pattern rule: <syntaxhighlight lang="make"> # From %.html to %.txt %.txt : %.html lynx -dump $< > $@ </syntaxhighlight> ===Comment=== Single-line [[comment (programming)|comment]]s are started with the [[hash symbol]] (#). ===Directive=== A directive specifies special behavior such as [[include directive|including]] another makefile. ===Line continuation=== [[Line continuation]] is indicated with a backslash {{code|\}} character at the end of a line. target: component \ component {{keypress|TAB}}command ; \ {{keypress|TAB}}command | \ {{keypress|TAB}}piped-command ==Examples== The following commands are in the context of the makefile that follows. <syntaxhighlight lang="bash"> make # updates first target, 'all' make help # updates target 'help' to list targets make dist # updates target 'dist' to build for distribution </syntaxhighlight> <syntaxhighlight lang="make"> PACKAGE = package VERSION = ` date "+%Y.%m%d%" ` RELEASE_DIR = .. RELEASE_FILE = $(PACKAGE)-$(VERSION) # Default target # note: variable LOGNAME comes from the environment all: echo "Hello $(LOGNAME), nothing to do by default" echo "Try 'make help'" # Display targets by searching this file help: egrep "^# target:" [Mm]akefile # Make a release dist: tar -cf $(RELEASE_DIR)/$(RELEASE_FILE) && \ gzip -9 $(RELEASE_DIR)/$(RELEASE_FILE).tar </syntaxhighlight> Below is a simple makefile that by default (the "all" rule is listed first) compiles a source file called "helloworld.c" using the system's C compiler and also provides a "clean" target to remove the generated files if the user desires to start over. The {{code|$@}} and {{code|$<}} are two of the so-called internal macros (also known as automatic variables) and stand for the target name and "implicit" source, respectively. In the example below, {{code|$^}} expands to a space delimited list of the prerequisites. There are a number of other internal macros.<ref name=posix-macros /><ref>[https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html#Automatic-Variables Automatic Variables] {{webarchive |url=https://web.archive.org/web/20160425225736/https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html#Automatic-Variables |date=April 25, 2016 }} GNU `make'</ref> <syntaxhighlight lang="make"> CFLAGS ?= -g all: helloworld helloworld: helloworld.o $(CC) $(LDFLAGS) -o $@ $^ helloworld.o: helloworld.c $(CC) $(CFLAGS) -c -o $@ $< clean: $(RM) helloworld helloworld.o </syntaxhighlight> Many systems<!-- at least open group base specification compliant systems, see above ref --> come with predefined Make rules and macros to specify common tasks such as compilation based on file suffix. This lets users omit the actual (often unportable) instructions of how to generate the target from the source(s). On such a system the makefile above could be modified as follows: <syntaxhighlight lang="make"> all: helloworld helloworld: helloworld.o $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ clean: $(RM) helloworld helloworld.o # suffix rule .c.o: $(CC) $(CFLAGS) -c $< .SUFFIXES: .c </syntaxhighlight> <!-- it appears that the open group base specification says .SUFFIXES and simple suffix rules must work, so there, gnu make. --> That "helloworld.o" depends on "helloworld.c" is now automatically handled by Make. In such a simple example as the one illustrated here this hardly matters, but the real power of suffix rules becomes evident when the number of source files in a software project starts to grow. One only has to write a rule for the linking step and declare the object files as prerequisites. Make will then implicitly determine how to make all the object files and look for changes in all the source files. Simple suffix rules work well as long as the source files do not depend on each other and on other files such as header files. Another route to simplify the build process is to use so-called pattern matching rules that can be combined with compiler-assisted dependency generation. As a final example requiring the gcc compiler and GNU Make, here is a generic makefile that compiles all C files in a folder to the corresponding object files and then links them to the final executable. Before compilation takes place, dependencies are gathered in makefile-friendly format into a hidden file ".depend" that is then included to the makefile. Portable programs ought to avoid constructs used below. <syntaxhighlight lang="make"> # Generic GNUMakefile # snippet to fail if not GNU ifneq (,) This makefile requires GNU Make. endif PROGRAM = foo C_FILES := $(wildcard *.c) OBJS := $(patsubst %.c, %.o, $(C_FILES)) CC = cc CFLAGS = -Wall -pedantic LDFLAGS = LDLIBS = -lm all: $(PROGRAM) $(PROGRAM): .depend $(OBJS) $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(PROGRAM) $(LDLIBS) depend: .depend .depend: cmd = gcc -MM -MF depend $(var); cat depend >> .depend; .depend: @echo "Generating dependencies..." @$(foreach var, $(C_FILES), $(cmd)) @rm -f depend -include .depend # These are the pattern matching rules. In addition to the automatic # variables used here, the variable $* that matches whatever % stands for # can be useful in special cases. %.o: %.c $(CC) $(CFLAGS) -c $< -o $@ %: %.o $(CC) $(CFLAGS) -o $@ $< clean: rm -f .depend $(OBJS) .PHONY: clean depend </syntaxhighlight> == Dependency tracking == Makefile consist of dependencies and a forgotten or an extra one may not be immediately obvious to the user and may result in subtle bugs in the generated software that are hard to catch. Various approaches may be used to avoid this problem and keep dependencies in source and makefiles in sync. One approach is using the compiler to keep track of dependencies changes. GCC can statically analyze the source code and produce rules for the given file automatically by using the {{Code|-MM}} switch. The other approach would be makefiles or third-party tools that would generate makefiles with dependencies (e.g. [[Automake]] toolchain by the [[GNU Project]], can do so automatically). Another approach is to use meta-build tools like [[CMake]], [[Meson (software)|Meson]] etc. == See also == {{Portal|Free and open-source software}} * {{Annotated link|Dependency graph}} * {{Annotated link|List of build automation software}} == References == {{Reflist|30em|refs= <ref name=posix-macros>{{cite web|url=http://www.opengroup.org/onlinepubs/009695399/utilities/make.html#tag_04_84_13_07|title=make|website=www.opengroup.org|access-date=18 March 2018|archive-date=31 October 2010|archive-url=https://web.archive.org/web/20101031131616/http://www.opengroup.org/onlinepubs/009695399/utilities/make.html#tag_04_84_13_07|url-status=live}}</ref> }} == External links == {{wikibooks|make}} * [https://www.gnu.org/software/make/ GNU Make homepage] {{Unix commands}} {{Authority control}} [[Category:Articles with example code]] [[Category:Build automation]] [[Category:Compiling tools]] [[Category:GNU Project software]] [[Category:Unix programming tools]] [[Category:Unix SUS2008 utilities]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Anchor
(
edit
)
Template:Annotated link
(
edit
)
Template:Authority control
(
edit
)
Template:Better source needed
(
edit
)
Template:Blockquote
(
edit
)
Template:Citation
(
edit
)
Template:Citation needed
(
edit
)
Template:Cite book
(
edit
)
Template:Cite encyclopedia
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite magazine
(
edit
)
Template:Cite tech report
(
edit
)
Template:Cite web
(
edit
)
Template:Code
(
edit
)
Template:Comma separated entries
(
edit
)
Template:Dead link
(
edit
)
Template:Endash
(
edit
)
Template:Infobox file format
(
edit
)
Template:Infobox programming language
(
edit
)
Template:Keypress
(
edit
)
Template:Main other
(
edit
)
Template:Man
(
edit
)
Template:Mono
(
edit
)
Template:Portal
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Sister project
(
edit
)
Template:Unix commands
(
edit
)
Template:Webarchive
(
edit
)
Template:Wikibooks
(
edit
)