GNU Make
vi GNU make11 Using make to Update Archive Files . . . . . . . 12911.1 Archive Members as Targets . . . . . . . . . . . . . . . . . . . . . . . . . .
90 GNU make$(and condition1[,condition2[,condition3...]])The and function provides a “short-circuiting” AND operation. Each argumentis expanded, in or
Chapter 8: Functions for Transforming Text 91undefined before the foreach function call, it is undefined after the call. See Section 6.2[The Two Flavors
92 GNU make8.7 The call FunctionThe call function is unique in that it can be used to create new parameterized functions.You can write a complex expre
Chapter 8: Functions for Transforming Text 938.8 The value FunctionThe value function provides a way for you to use the value of a variable without ha
94 GNU makePROGRAMS = server clientserver_OBJS = server.o server_priv.o server_access.oserver_LIBS = priv protocolclient_OBJS = client.o client_api.o
Chapter 8: Functions for Transforming Text 95‘environment’if variable was inherited from the environment provided to make.‘environment override’if var
96 GNU makeThe syntax of the flavor function is:$(flavor variable)Note that variable is the name of a variable to inquire about, not a reference to th
Chapter 8: Functions for Transforming Text 978.13 The shell FunctionThe shell function is unlike any other function other than the wildcard function (
Chapter 9: How to Run make 999 How to Run makeA makefile that says how to recompile a program can be used in more than one way. Thesimplest use is to r
Chapter 1: Overview of make 11 Overview of makeThe make utility automatically determines which pieces of a large program need to berecompiled, and iss
100 GNU maketargets not in the makefile may be specified, if make can find implicit rules that say how tomake them.Make will set the special variable MAK
Chapter 9: How to Run make 101install Copy the executable file into a directory that users typically search for com-mands; copy any auxiliary files that
102 GNU makemodification times remain the same. You can use the ‘-W’ flag in conjunctionwith the ‘-n’ flag to see what would happen if you were to modify
Chapter 9: How to Run make 1033. Use the command ‘make -t ’ to mark all the object files as up to date. The next timeyou run make, the changes in the h
104 GNU make9.6 Testing the Compilation of a ProgramNormally, when an error happens in executing a shell command, make gives up immediately,returning
Chapter 9: How to Run make 105are being compared and with what results, which files actually need to beremade, which implicit rules are considered and
106 GNU make‘-h’‘--help’Remind you of the options that make understands and then exit.‘-i’‘--ignore-errors’Ignore all errors in recipes executed to re
Chapter 9: How to Run make 107Print the recipe that would be executed, but do not execute it (except in certaincircumstances). See Section 9.3 [Instea
108 GNU make(see Section 10.3 [Variables Used by Implicit Rules], page 115); see the ‘-R’option below.‘-R’‘--no-builtin-variables’Eliminate use of the
Chapter 9: How to Run make 109‘--no-print-directory’Disable printing of the working directory under -w. This option is useful when-w is turned on auto
2 GNU makeBefore reporting a bug or trying to fix it yourself, try to isolate it to the smallest possiblemakefile that reproduces the problem. Then send
Chapter 10: Using Implicit Rules 11110 Using Implicit RulesCertain standard ways of remaking target files are used very often. For example, onecustomar
112 GNU makefiles are supposed to exist. See Section 10.2 [Catalogue of Built-In Rules], page 112, for acatalogue of all the predefined implicit rules.A
Chapter 10: Using Implicit Rules 113Compiling C++ programsn.o is made automatically from n.cc, n.cpp, or n.C with a recipe of the form‘$(CXX) $(CPPFLA
114 GNU makecc -c x.c -o x.occ -c y.c -o y.occ -c z.c -o z.occ x.o y.o z.o -o xrm -f x.orm -f y.orm -f z.oIn more complicated cases, such as when ther
Chapter 10: Using Implicit Rules 115Texinfo and Infon.dvi is made from n.texinfo, n.texi, or n.txinfo, with the recipe‘$(TEXI2DVI) $(TEXI2DVI_FLAGS)’.
116 GNU makeFor example, the recipe used to compile a C source file actually says ‘$(CC) -c $(CFLAGS)$(CPPFLAGS)’. The default values of the variables
Chapter 10: Using Implicit Rules 117TANGLE Program to translate Web into Pascal; default ‘tangle’.CTANGLE Program to translate C Web into C; default ‘
118 GNU makeOnce make has decided to use the intermediate file, it is entered in the data base as if it hadbeen mentioned in the makefile, along with th
Chapter 10: Using Implicit Rules 119Thus, a pattern rule ‘%.o : %.c’ says how to make any file stem.o from another filestem.c.Note that expansion using
Chapter 2: An Introduction to Makefiles 32 An Introduction to MakefilesYou need a file called a makefile to tell make what to do. Most often, the makefile
120 GNU makedefines a rule that can make any file x.o from x.c. The recipe uses the automatic variables‘$@’ and ‘$<’ to substitute the names of the t
Chapter 10: Using Implicit Rules 121$% The target member name, when the target is an archive member. SeeChapter 11 [Archives], page 129. For example,
122 GNU makeOf the variables listed above, four have values that are single file names, and three havevalues that are lists of file names. These seven h
Chapter 10: Using Implicit Rules 123‘test’. The pattern rule prerequisites are turned into actual file names by substituting thestem for the character
124 GNU makeSuppose the makefile mentions foo.c. For this target, make would have to considermaking it by linking an object file foo.c.o, or by C compil
Chapter 10: Using Implicit Rules 125new rule is defined, the built-in one is replaced. The new rule’s position in the sequence ofimplicit rules is dete
126 GNU makeA single-suffix rule is defined by a single suffix, which is the source suffix. It matchesany file name, and the corresponding implicit prerequisi
Chapter 10: Using Implicit Rules 12710.8 Implicit Rule Search AlgorithmHere is the procedure make uses for searching for an implicit rule for a target
128 GNU makeis executed, each of these stored file names are entered into the data base and marked ashaving been updated and having the same update sta
Chapter 11: Using make to Update Archive Files 12911 Using make to Update Archive FilesArchive files are files containing named sub-files called members;
4 GNU make2.2 A Simple MakefileHere is a straightforward makefile that describes the way an executable file called editdepends on eight object files which
130 GNU makecc -c bar.c -o bar.oar r foo.a bar.orm -f bar.oHere make has envisioned the file bar.o as an intermediate file. See Section 10.4 [Chains ofI
Chapter 11: Using make to Update Archive Files 131(see Section 11.2 [Archive Update], page 129). But they are retained for compatibility withother mak
Chapter 12: Extending GNU make 13312 Extending GNU makeGNU make provides many advanced capabilities, including many useful functions. However,it does
134 GNU makecharacterA printable character is converted to the same character.string A string containing only printable characters is converted to the
Chapter 12: Extending GNU make 135define GUILEIO;; A simple Guile IO library for GNU make(define MKPORT #f)(define (mkopen name mode)(set! MKPORT (ope
136 GNU make Warning: The load directive and extension capability is considered a “technologypreview” in this release of GNU make. We encourage you
Chapter 12: Extending GNU make 137Regardless of how many times an object file appears in a load directive, it will only beloaded (and its setup functio
138 GNU makeData Structuresgmk_floc This structure represents a filename/location pair. It is provided when definingitems, so GNU make can inform the us
Chapter 12: Extending GNU make 139gmk_expandThis function takes a string and expands it using make expansion rules. Theresult of the expansion is retu
Chapter 2: An Introduction to Makefiles 5A recipe may follow each line that contains a target and prerequisites. These recipes sayhow to update the tar
140 GNU make#include <stdlib.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <unistd.h>#include <e
Chapter 12: Extending GNU make 141all:@echo Temporary file: $(mk-temp tmpfile.)load mk_temp.somk_temp.so: mk_temp.c$(CC) -shared -fPIC -o $ $<On MS
Chapter 13: Features of GNU make 14313 Features of GNU makeHere is a summary of the features of GNU make, for comparison with and credit to otherversi
144 GNU make• The automatic variable $^ containing a list of all prerequisites of the current target.We did not invent this, but we have no idea who d
Chapter 13: Features of GNU make 145• Declare phony targets with the special target .PHONY.Andrew Hume of AT&T Bell Labs implemented a similar fea
Chapter 14: Incompatibilities and Missing Features 14714 Incompatibilities and Missing FeaturesThe make programs in various other systems support a fe
148 GNU makeWe feel that it is cleaner for a rule without a recipe to always simply add to theprerequisite list for the target. The above example can
Chapter 15: Makefile Conventions 14915 Makefile ConventionsThis chapter describes conventions for writing the Makefiles for GNU programs. Using Au-tomake
6 GNU makeThus, if we change the file insert.c and run make, make will compile that file to updateinsert.o, and then link edit. If we change the file com
150 GNU makeappear in the source directory, they should always appear in the source directory, not inthe build directory. So Makefile rules to update t
Chapter 15: Makefile Conventions 15115.3 Variables for Specifying CommandsMakefiles should provide variables for overriding certain commands, options, a
152 GNU make15.4 DESTDIR: Support for Staged InstallsDESTDIR is a variable prepended to each installed target file, like this:$(INSTALL_PROGRAM) foo $(
Chapter 15: Makefile Conventions 153prefix A prefix used in constructing the default values of the variables listed below.The default value of prefix sh
154 GNU makeHere are the variables Makefiles should use to specify directories to put these variouskinds of files in:‘datarootdir’The root of the direct
Chapter 15: Makefile Conventions 155the next reboot. PID files for system daemons are a typical use. In addition,this directory should not be cleaned ex
156 GNU make‘htmldir’‘dvidir’‘pdfdir’‘psdir’ Directories for installing documentation files in the particular format. Theyshould all be set to $(docdir
Chapter 15: Makefile Conventions 157‘srcdir’ The directory for the sources being compiled. The value of this variable isnormally inserted by the config
158 GNU makeIf possible, write the install target rule so that it does not modify anything inthe directory where the program was built, provided ‘make
Chapter 15: Makefile Conventions 159When you have many documentation files to install, we recommend that youavoid collisions and clutter by arranging fo
Chapter 2: An Introduction to Makefiles 7objects = main.o kbd.o command.o display.o \insert.o search.o files.o utils.oedit : $(objects)cc -o edit $(obj
160 GNU make‘mostlyclean’Like ‘clean’, but may refrain from deleting a few files that people normallydon’t want to recompile. For example, the ‘mostlyc
Chapter 15: Makefile Conventions 161generated. These targets should not be dependencies of the all target; theuser must manually invoke them.Here’s an
162 GNU makeinstalldirsIt’s useful to add a target named ‘installdirs’ to create the directorieswhere files are installed, and their parent directories
Chapter 15: Makefile Conventions 163$(PRE_INSTALL) # Pre-install commands follow.$(POST_INSTALL) # Post-install commands follow.$(NORMAL_INSTALL) # Nor
Appendix A: Quick Reference 165Appendix A Quick ReferenceThis appendix summarizes the directives, text manipulation functions, and special variableswh
166 GNU makeexport variableexport variable-assignmentunexport variableTell make whether or not to export a particular variable to child processes.See
Appendix A: Quick Reference 167$(wordlist s,e,text)Returns the list of words in text from s to e.See Section 8.2 [Functions for String Substitution an
168 GNU make$(error text...)When this function is evaluated, make generates a fatal error with the messagetext.See Section 8.12 [Functions That Contro
Appendix A: Quick Reference 169$(file op filename,text)Expand the arguments, then open the file filename using mode op and writetext to that file.See Sec
8 GNU makeobjects = main.o kbd.o command.o display.o \insert.o search.o files.o utils.oedit : $(objects)cc -o edit $(objects)main.o : defs.hkbd.o : de
170 GNU makeMAKEFILESMakefiles to be read on every invocation of make.See Section 3.4 [The Variable MAKEFILES], page 14.VPATHDirectory search path for
Appendix A: Quick Reference 171MAKECMDGOALSThe targets given to make on the command line. Setting this variable has noeffect on the operation of make.S
Appendix B: Errors Generated by Make 173Appendix B Errors Generated by MakeHere is a list of the more common errors you might see generated by make, a
174 GNU make‘No rule to make target ‘xxx’.’‘No rule to make target ‘xxx’, needed by ‘yyy’.’This means that make decided it needed to build a target, b
Appendix B: Errors Generated by Make 175‘missing target pattern. Stop.’‘multiple target patterns. Stop.’‘target pattern contains no ‘%’. Stop.’‘mixed
Appendix C: Complex Makefile Example 177Appendix C Complex Makefile ExampleHere is the makefile for the GNU tar program. This is a moderately complex mak
178 GNU make# Things you might add to DEFS:# -DSTDC_HEADERS If you have ANSI C headers and# libraries.# -DPOSIX If you have POSIX.1 headers and# libra
Appendix C: Complex Makefile Example 179# and want to disable the tar -k# option instead of emulating open.# -DXENIX If you have sys/inode.h# and need
Chapter 2: An Introduction to Makefiles 92.7 Rules for Cleaning the DirectoryCompiling a program is not the only thing you might want to write rules fo
180 GNU makeAUX = README COPYING ChangeLog Makefile.in \makefile.pc configure configure.in \tar.texinfo tar.info* texinfo.tex \tar.h port.h open3.h ge
Appendix C: Complex Makefile Example 181.PHONY: realcleanrealclean: distcleanrm -f tar.info*.PHONY: sharshar: $(SRCS) $(AUX)shar $(SRCS) $(AUX) | compr
182 GNU maketo copy and redistribute it, with or without modifying it, either commercially or non-commercially. Secondarily, this License preserves fo
Appendix C: Complex Makefile Example 183editor, and that is suitable for input to text formatters or for automatic translation toa variety of formats s
184 GNU makeIf you publish printed copies (or copies in media that commonly have printed covers) ofthe Document, numbering more than 100, and the Docu
Appendix C: Complex Makefile Example 185F. Include, immediately after the copyright notices, a license notice giving the publicpermission to use the Mo
186 GNU makeyou may replace the old one, on explicit permission from the previous publisher thatadded the old one.The author(s) and publisher(s) of th
Appendix C: Complex Makefile Example 1878. TRANSLATIONTranslation is considered a kind of modification, so you may distribute translationsof the Documen
188 GNU makeversions of this License can be used, that proxy’s public statement of acceptance of aversion permanently authorizes you to choose that ve
Appendix C: Complex Makefile Example 189ADDENDUM: How to use this License for your documentsTo use this License in a document you have written, include
Index of Concepts 191Index of Concepts!!= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65!=, expansion. .
192 GNU make-I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13, 106-j . . . . . . . . . . . . . . . . . . . . . . .
Index of Concepts 193archive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129archive member targets . . . . . . . . .
194 GNU makeexecution, of recipes . . . . . . . . . . . . . . . . . . . . . . . . . . . 44exit status (errors). . . . . . . . . . . . . . . . . . . .
Index of Concepts 195Llast-resort default rules . . . . . . . . . . . . . . . . . . . . . . . 125ld. . . . . . . . . . . . . . . . . . . . . . . . . .
196 GNU makeportability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143POSIX. . . . . . . . . . . . . . . . . . . . . . . .
Index of Concepts 197rule, implicit, definition of . . . . . . . . . . . . . . . . . . . . . 11rule, implicit, how to use . . . . . . . . . . . . . . .
198 GNU maketargets, phony . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29terminal rule . . . . . . . . . . . . . . . . . . . . .
Index of Functions, Variables, & Directives 199Index of Functions, Variables, & Directives$$%. . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 3: Writing Makefiles 113 Writing MakefilesThe information that tells make how to recompile a system comes from reading a data basecalled the mak
200 GNU make|| (automatic variable) . . . . . . . . . . . . . . . . . . . . . . . . 121Aabspath . . . . . . . . . . . . . . . . . . . . . . . . . . .
Index of Functions, Variables, & Directives 201MAKECMDGOALS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100makefile . . . . .
12 GNU make3.1.1 Splitting Long LinesMakefiles use a “line-based” syntax in which the newline character is special and marks theend of a statement. GNU
Chapter 3: Writing Makefiles 133.3 Including Other MakefilesThe include directive tells make to suspend reading the current makefile and read one ormore
14 GNU makeOnly after it has tried to find a way to remake a makefile and failed, will make diagnose themissing makefile as a fatal error.If you want mak
Chapter 3: Writing Makefiles 15you can write an explicit rule with the makefile as the target, and an empty recipe (seeSection 5.9 [Using Empty Recipes]
16 GNU makethe information in the containing makefile, make should look in another makefile. SeeSection 10.5 [Pattern Rules], page 118, for more informa
Chapter 3: Writing Makefiles 17immediate != immediatedefine immediatedeferredendefdefine immediate =deferredendefdefine immediate ?=deferredendefdefine
18 GNU makeThat is, the target and prerequisite sections are expanded immediately, and the recipeused to construct the target is always deferred. This
Chapter 3: Writing Makefiles 19$*, etc. during the second expansion and they will have their expected values, just as inthe recipe. All you have to do
GNU MakeA Program for Directing RecompilationGNU make Version 4.1September 2014Richard M. Stallman, Roland McGrath, Paul D. Smith
20 GNU maketively. In the third they will have values foo.1, foo.1 bar.1 foo.2 bar.2, and foo.1bar.1 foo.2 bar.2 foo.1 foo.1 bar.1 foo.1 bar.1 respect
Chapter 4: Writing Rules 214 Writing RulesA rule appears in the makefile and says when and how to remake certain files, called therule’s targets (most o
22 GNU makeThe criterion for being out of date is specified in terms of the prerequisites, whichconsist of file names separated by spaces. (Wildcards an
Chapter 4: Writing Rules 23$(OBJS): | $(OBJDIR)$(OBJDIR):mkdir $(OBJDIR)Now the rule to create the objdir directory will be run, if needed, before any
24 GNU makeyou use the value of objects in a recipe, the shell may perform wildcard expansion whenthe recipe runs. To set objects to the expansion, in
Chapter 4: Writing Rules 25$(wildcard *.c)We can change the list of C source files into a list of object files by replacing the ‘.c’suffix with ‘.o’ in th
26 GNU makefoo.o : src/foo.cassuming the file foo.c does not exist in the current directory but is found in the directorysrc.4.4.2 The vpath DirectiveS
Chapter 4: Writing Rules 27vpath %.c foovpath % blishvpath %.c barwill look for a file ending in ‘.c’ in foo, then blish, then bar, whilevpath %.c foo:
28 GNU makeThis is done with the automatic variables such as ‘$^’ (see Section 10.5.3 [AutomaticVariables], page 120). For instance, the value of ‘$^’
Chapter 4: Writing Rules 29a pattern string. When a prerequisite like ‘-lname’ is seen, make will replace the percentin each pattern in the list with
This file documents the GNU make utility, which determines automatically which pieces ofa large program need to be recompiled, and issues the commands
30 GNU makeBy declaring the sub-directories as .PHONY targets (you must do this as the sub-directoryobviously always exists; otherwise it won’t be bui
Chapter 4: Writing Rules 31cleanall : cleanobj cleandiffrm programcleanobj :rm *.ocleandiff :rm *.diff4.6 Rules without Recipes or PrerequisitesIf a r
32 GNU make4.8 Special Built-in Target NamesCertain names have special meanings if they appear as targets..PHONYThe prerequisites of the special targe
Chapter 4: Writing Rules 33.DELETE_ON_ERRORIf .DELETE_ON_ERROR is mentioned as a target anywhere in the makefile, thenmake will delete the target of a
34 GNU make.EXPORT_ALL_VARIABLESSimply by being mentioned as a target, this tells make to export all variablesto child processes by default. See Secti
Chapter 4: Writing Rules 35bigoutput littleoutput : text.ggenerate text.g -$(subst output,,$@) > $@is equivalent tobigoutput : text.ggenerate text.
36 GNU makeIf none of the explicit rules for a target has a recipe, then make searches for an applicableimplicit rule to find one see Chapter 10 [Using
Chapter 4: Writing Rules 37objects = foo.o bar.oall: $(objects)$(objects): %.o: %.c$(CC) -c $(CFLAGS) $< -o $@Here ‘$<’ is the automatic variabl
38 GNU make• If you cannot be sure of the precise contents of the directories you are using, you maynot be sure which other irrelevant files might lead
Chapter 4: Writing Rules 39main.o : main.c defs.hThus you no longer have to write all those rules yourself. The compiler will do it for you.Note that
iShort Contents1 Overview of make . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 An Introduction to Makefiles . . . . . .
40 GNU makemakefiles like any others, make will remake them as necessary with no further work fromyou. See Section 3.5 [Remaking Makefiles], page 14.Not
Chapter 5: Writing Recipes in Rules 415 Writing Recipes in RulesThe recipe of a rule consists of one or more shell command lines to be executed, one a
42 GNU makecharacter of the next line after the backslash/newline is the recipe prefix character (a tabby default; see Section 6.14 [Special Variables]
Chapter 5: Writing Recipes in Rules 43we will get output like this:hello worldIf you like, you can also use target-specific variables (see Section 6.11
44 GNU makeThe ‘-s’ or ‘--silent’ flag to make prevents all echoing, as if all recipes started with‘@’. A rule in the makefile for the special target .S
Chapter 5: Writing Recipes in Rules 45.ONESHELL:SHELL = /usr/bin/perl.SHELLFLAGS = -eshow :@f = qw(a b c);print "@f\n";However, either of th
46 GNU makeUnlike most variables, the variable SHELL is never set from the environment. This isbecause the SHELL environment variable is used to speci
Chapter 5: Writing Recipes in Rules 47The effect of the above DOS-specific processing is that a Makefile that contains ‘SHELL= /bin/sh’ (as many Unix mak
48 GNU makecompleted. Additionally, if there are multiple recursive make invocations running in parallel,they will communicate so that only one of the
Chapter 5: Writing Recipes in Rules 49modes). For example, many programs that can display colorized output will not do soif they determine they are no
50 GNU makeeither directly or indirectly. No further recipes will be executed for these targets, since theirpreconditions have not been achieved.Norma
Chapter 5: Writing Recipes in Rules 51system. For example, suppose you have a sub-directory subdir which has its own makefile,and you would like the co
52 GNU makelines containing MAKE are executed normally despite the presence of a flag that causes mostrecipes not to be run. The usual MAKEFLAGS mechan
Chapter 5: Writing Recipes in Rules 53variable := valueexport variableLikewise,export variable += valueis just like:variable += valueexport variableSe
54 GNU make5.7.3 Communicating Options to a Sub-makeFlags such as ‘-s’ and ‘-k’ are passed automatically to the sub-make through the variableMAKEFLAGS
Chapter 5: Writing Recipes in Rules 55‘--warn-undefined-variables’). MFLAGS was traditionally used explicitly in the recursivemake command, like this:
56 GNU makeNormally, you do not need to specify this option because ‘make’ does it for you: ‘-w’is turned on automatically when you use the ‘-C’ optio
Chapter 5: Writing Recipes in Rules 57make will not echo the first line, the echo command. But it will echo the following tworecipe lines.On the other
Chapter 6: How to Use Variables 596 How to Use VariablesA variable is a name defined in a makefile to represent a string of text, called the variable’sv
iiiTable of Contents1 Overview of make . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.1 How to Read This Manual . . . . . . . . .
60 GNU makecould be used to compile a C program prog.c. Since spaces before the variable value areignored in variable assignments, the value of foo is
Chapter 6: How to Use Variables 61Simply expanded variables are defined by lines using ‘:=’ or ‘::=’ (see Section 6.5 [SettingVariables], page 65). Bot
62 GNU makeeffect (but be rather hard to read). If you put whitespace at the end of a variable value,it is a good idea to put a comment like that at th
Chapter 6: How to Use Variables 63For example:foo := a.o b.o c.obar := $(foo:%.o=%.c)sets ‘bar’ to ‘a.c b.c c.c’.6.3.2 Computed Variable NamesComputed
64 GNU makex = variable1variable2 := Helloy = $(subst 1,2,$(x))z = ya := $($($(z)))eventually defines a as ‘Hello’. It is doubtful that anyone would ev
Chapter 6: How to Use Variables 65ifdef do_sortfunc := sortelsefunc := stripendifbar := a d b g q cfoo := $($(func) $(bar))attempts to give ‘foo’ the
66 GNU makedefines a variable named objects. Whitespace around the variable name and immediatelyafter the ‘=’ is ignored.Variables defined with ‘=’ are
Chapter 6: How to Use Variables 67This takes the value of the variable objects, and adds the text ‘another.o’ to it (precededby a single space). Thus:
68 GNU makeThe first line defines the CFLAGS variable with a reference to another variable, includes.(CFLAGS is used by the rules for C compilation; see
Chapter 6: How to Use Variables 696.8 Defining Multi-Line VariablesAnother way to set the value of a variable is to use the define directive. This dire
iv GNU make4.9 Multiple Targets in a Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344.10 Multiple Rules for One Target
70 GNU makenot. However, if you are using the flavor (see Section 8.11 [Flavor Function], page 95) andorigin (see Section 8.10 [Origin Function], page
Chapter 6: How to Use Variables 716.11 Target-specific Variable ValuesVariable values in make are usually global; that is, they are the same regardless
72 GNU makepattern ... : variable-assignmentwhere pattern is a %-pattern. As with target-specific variable values, multiple patternvalues create a patt
Chapter 6: How to Use Variables 736.14 Other Special VariablesGNU make supports some variables that have special properties.MAKEFILE_LISTContains the
74 GNU make# Query the default goal.ifeq ($(.DEFAULT_GOAL),)$(warning no default goal is set)endif.PHONY: foofoo: ; @echo $@$(warning default goal is
Chapter 6: How to Use Variables 75.RECIPEPREFIXThe first character of the value of this variable is used as the character makeassumes is introducing a
76 GNU make‘target-specific’Supports target-specific and pattern-specific variable assignments.See Section 6.11 [Target-specific Variable Values], page 7
Chapter 7: Conditional Parts of Makefiles 777 Conditional Parts of MakefilesA conditional directive causes part of a makefile to be obeyed or ignored dep
78 GNU makelibs_for_gcc = -lgnunormal_libs =ifeq ($(CC),gcc)libs=$(libs_for_gcc)elselibs=$(normal_libs)endiffoo: $(objects)$(CC) -o foo $(objects) $(l
Chapter 7: Conditional Parts of Makefiles 79ifeq (arg1, arg2)ifeq ’arg1’ ’arg2’ifeq "arg1" "arg2"ifeq "arg1" ’arg2’ifeq ’
v7 Conditional Parts of Makefiles . . . . . . . . . . . . . . . 777.1 Example of a Conditional . . . . . . . . . . . . . . . . . . . . . . . . . . . .
80 GNU makereturn true for all definitions except those like foo =. To test for an emptyvalue, use ifeq ($(foo),). For example,bar =foo = $(bar)ifdef f
Chapter 7: Conditional Parts of Makefiles 81Substitution and Analysis], page 84). This is useful when touch is not enough to make afile appear up to dat
Chapter 8: Functions for Transforming Text 838 Functions for Transforming TextFunctions allow you to do text processing in the makefile to compute the
84 GNU make8.2 Functions for String Substitution and AnalysisHere are some functions that operate on strings:$(subst from,to,text)Performs a textual r
Chapter 8: Functions for Transforming Text 85$(objects:.o=.c)instead of using the general form:$(patsubst %.o,%.c,$(objects))$(strip string)Removes le
86 GNU makeFor example, given:objects=main1.o foo.o main2.o bar.omains=main1.o main2.othe following generates a list which contains all the object file
Chapter 8: Functions for Transforming Text 87produces the result ‘bar’. Although $(lastword text) is the same as $(word$(words text),text), the lastwo
88 GNU make$(suffix names...)Extracts the suffix of each file name in names. If the file name contains a period,the suffix is everything starting with the l
Chapter 8: Functions for Transforming Text 89$(wildcard pattern)The argument pattern is a file name pattern, typically containing wildcardcharacters (a
Comments to this Manuals