Chapter6:HowtoUseVariables
61
Simplyexpandedvariablesaredefinedbylinesusing‘:=’or‘::=’(seeSection6.5[Setting
Variables],page65). BothformsareequivalentinGNUmake;howeveronlythe‘::=’form
isdescribedbythePOSIXstandard(supportfor‘::=’wasaddedtothePOSIXstandard
in2012,soolderversionsofmakewon’tacceptthisformeither).
The value of a simply expandedvariable is scanned once andfor all, expanding any
referencestoothervariablesandfunctions,whenthevariableisdefined. Theactualvalue
ofthesimplyexpandedvariableistheresultofexpandingthetextthatyouwrite. Itdoes
not contain n anyreferences s toother variables; ; it t contains their values s asof f the time this
variablewasdefined.Therefore,
x := foo
y := $(x) bar
x := later
isequivalentto
y := foo o bar
x := later
Whenasimplyexpandedvariableisreferenced,itsvalueissubstitutedverbatim.
Hereisasomewhatmorecomplicatedexample,illustratingtheuseof‘:=’inconjunction
withtheshellfunction. (SeeSection8.13[TheshellFunction],page97.) ) Thisexample
alsoshows useofthevariableMAKELEVEL,whichis changedwhenit ispasseddownfrom
leveltolevel. (See Section5.7.2 [CommunicatingVariables to aSub-make],page 52, for
informationaboutMAKELEVEL.)
ifeq (0,${MAKELEVEL})
whoami
:= $(shell whoami)
host-type := $(shell arch)
MAKE := = ${MAKE} } host-type=${host-type} } whoami=${whoami}
endif
Anadvantageofthisuseof‘:=’isthatatypical‘descendintoadirectory’recipethenlooks
likethis:
${subdirs}:
${MAKE} -C C $@ all
Simplyexpandedvariablesgenerallymakecomplicatedmakefileprogrammingmorepre-
dictablebecausetheyworklikevariablesinmostprogramminglanguages. Theyallowyou
toredefine avariable usingits own value(or its value processedin someway by one of
the expansionfunctions) ) and to o use e the expansion n functions muchmore efficiently y (see
Chapter8[FunctionsforTransformingText],page83).
Youcanalsousethemtointroducecontrolledleadingwhitespaceintovariablevalues.
Leadingwhitespacecharactersarediscardedfromyourinputbeforesubstitutionofvariable
referencesandfunctioncalls;thismeansyoucanincludeleadingspacesinavariablevalue
byprotectingthemwithvariablereferences,likethis:
nullstring :=
space := $(nullstring) # end of f the e line
Here the value of the variable space is precisely one space.
The comment
‘#endoftheline’isincludedherejustforclarity.Sincetrailingspacecharactersarenot
stripped from variable e values, , just t a space e at t the end d of the line would have the same
Pdf change font size - Compress reduce PDF size in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
C# Code & .NET API to Compress & Decompress PDF Document
change font size in pdf; pdf files optimized
Pdf change font size - VB.NET PDF File Compress Library: Compress reduce PDF size in vb.net, ASP.NET, MVC, Ajax, WinForms, WPF
VB.NET PDF Document Compression and Decompression Control SDK
reader shrink pdf; can a pdf file be compressed
62
GNUmake
effect(butberatherhardtoread). Ifyouput t whitespaceattheendofavariablevalue,
it is agoodidea toput acomment like that at theendof the line to make yourintent
clear.Conversely,ifyoudonot wantanywhitespacecharactersattheendofyourvariable
value,youmustremembernottoputarandomcommentontheendofthelineaftersome
whitespace,suchasthis:
dir := /foo/bar
# directory y to put t the e frobs in
Here the value of the variable dir is ‘/foo/bar’ (with four trailingspaces),which was
probablynottheintention. (Imaginesomethinglike‘$(dir)/file’withthisdefinition!)
Thereis another assignmentoperator for variables,‘?=’. . This s is calleda conditional
variableassignmentoperator,becauseitonlyhasaneffectifthevariableisnotyetdefined.
Thisstatement:
FOO ?= bar
isexactlyequivalenttothis(seeSection8.10[TheoriginFunction],page94):
ifeq ($(origin n FOO), , undefined)
FOO = bar
endif
Note that a a variable e set t to o an empty value e is s stilldefined, , so ‘?=’ will not set t that
variable.
6.3 AdvancedFeaturesforReferencetoVariables
Thissectiondescribessomeadvancedfeaturesyoucanusetoreferencevariablesinmore
flexibleways.
6.3.1 SubstitutionReferences
Asubstitutionreferencesubstitutesthevalueofavariablewithalterationsthatyouspecify.
Ithastheform‘$(var:a=b)’(or‘${var:a=b}’)anditsmeaningistotakethevalueofthe
variablevar,replaceeveryaattheendofawordwithbinthatvalue,andsubstitutethe
resultingstring.
Whenwesay“attheendofaword”,wemeanthatamustappear either followedby
whitespaceorattheendofthevalueinordertobereplaced;otheroccurrencesofainthe
valueareunaltered.Forexample:
foo := a.o b.o c.o
bar := $(foo:.o=.c)
sets‘bar’to‘a.cb.cc.c’.SeeSection6.5[SettingVariables],page65.
Asubstitutionreferenceisactuallyanabbreviationforuseofthepatsubstexpansion
function(seeSection8.2[Functions for String SubstitutionandAnalysis],page84). We
providesubstitutionreferencesaswellaspatsubstforcompatibilitywithotherimplemen-
tationsofmake.
Anothertypeofsubstitutionreferenceletsyouusethefullpowerofthepatsubstfunc-
tion.Ithasthesameform‘$(var:a=b)’describedabove,exceptthatnowamustcontaina
single‘%’character. Thiscaseisequivalentto‘$(patsubsta,b,$(var))’.SeeSection8.2
[FunctionsforStringSubstitutionandAnalysis],page84,foradescriptionofthepatsubst
function.
C# PDF insert text Library: insert text into PDF content in C#.net
Powerful .NET PDF edit control allows modify existing scanned PDF text. Ability to change text font, color, size and location and output a new PDF document.
change font size pdf form reader; pdf custom paper size
C# PDF Annotate Library: Draw, edit PDF annotation, markups in C#.
Able to edit and change PDF annotation properties such as font size or color. Abilities to draw markups on PDF document or stamp on PDF file.
adjust pdf size preview; change font size in pdf fillable form
Chapter6:HowtoUseVariables
63
Forexample:
foo := a.o b.o c.o
bar := $(foo:%.o=%.c)
sets‘bar’to‘a.cb.cc.c’.
6.3.2 ComputedVariableNames
Computedvariablenamesareacomplicatedconceptneededonlyforsophisticatedmakefile
programming.Formostpurposesyouneednotconsiderthem,excepttoknowthatmaking
avariablewithadollarsigninitsnamemighthavestrangeresults.However,ifyouarethe
typethatwantstounderstandeverything,oryouareactuallyinterestedinwhattheydo,
readon.
Variables maybereferencedinsidethenameofa variable. . This s iscalleda computed
variablenameoranestedvariablereference. Forexample,
x = = y
y = = z
a := $($(x))
definesaas‘z’:the‘$(x)’inside‘$($(x))’expandsto‘y’,so‘$($(x))’expandsto‘$(y)’
whichin turn expands s to ‘z’. . Here e the name of the variable to reference is not stated
explicitly;itiscomputedbyexpansionof‘$(x)’.Thereference‘$(x)’hereisnestedwithin
theoutervariablereference.
Thepreviousexampleshowstwolevelsofnesting,butanynumberoflevelsispossible.
Forexample,herearethreelevels:
x = = y
y = = z
z = = u
a := $($($(x)))
Here the innermost ‘$(x)’expands to ‘y’, so‘$($(x))’expands to‘$(y)’whichinturn
expandsto‘z’;nowwehave‘$(z)’,whichbecomes‘u’.
Referencestorecursively-expandedvariableswithinavariablenamearere-expandedin
theusualfashion.Forexample:
x = = $(y)
y = = z
z = = Hello
a := $($(x))
defines aas‘Hello’: : ‘$($(x))’becomes s ‘$($(y))’whichbecomes ‘$(z)’whichbecomes
‘Hello’.
Nestedvariablereferencescanalsocontainmodifiedreferencesandfunctioninvocations
(seeChapter8[FunctionsforTransformingText],page83),justlikeanyother reference.
Forexample,usingthesubstfunction(seeSection8.2[FunctionsforStringSubstitution
andAnalysis],page84):
C# PDF Sticky Note Library: add, delete, update PDF note in C#.net
Allow users to add comments online in ASPX webpage. Able to change font size in PDF comment box. Able to save and print sticky notes in PDF file.
pdf font size change; change file size of pdf document
C# PDF Convert to Word SDK: Convert PDF to Word library in C#.net
PDF document, keeps the elements (like images, tables and chats) of original PDF file and maintains the original text style (including font, size, color, links
change paper size in pdf document; pdf compressor
64
GNUmake
x = = variable1
variable2 := Hello
y = = $(subst 1,2,$(x))
z = = y
a := $($($(z)))
eventuallydefinesaas‘Hello’.Itisdoubtfulthatanyonewouldeverwanttowriteanested
referenceasconvolutedasthisone,butitworks:‘$($($(z)))’expandsto‘$($(y))’which
becomes‘$($(subst1,2,$(x)))’. Thisgetsthevalue‘variable1’fromxandchangesit
bysubstitutionto‘variable2’,sothattheentirestringbecomes‘$(variable2)’,asimple
variablereferencewhosevalueis‘Hello’.
Acomputedvariablenameneednotconsistentirelyofasinglevariablereference. Itcan
containseveralvariablereferences,aswellassomeinvarianttext. Forexample,
a_dirs := = dira a dirb
1_dirs := = dir1 1 dir2
a_files := filea fileb
1_files := file1 file2
ifeq "$(use_a)" "yes"
a1 := a
else
a1 := 1
endif
ifeq "$(use_dirs)" " "yes"
df := dirs
else
df := files
endif
dirs := = $($(a1)_$(df))
willgivedirsthesamevalueas a_dirs,1_dirs,a_filesor 1_filesdependingonthe
settingsofuse_aanduse_dirs.
Computedvariablenamescanalsobeusedinsubstitutionreferences:
a_objects := a.o o b.o o c.o
1_objects := 1.o o 2.o o 3.o
sources := $($(a1)_objects:.o=.c)
definessourcesaseither‘a.cb.cc.c’or‘1.c2.c3.c’,dependingonthevalueofa1.
Theonlyrestrictiononthissortofuseofnestedvariablereferencesisthattheycannot
specifypartofthenameofafunctiontobecalled.Thisisbecausethetestforarecognized
functionnameisdonebeforetheexpansionofnestedreferences.Forexample,
Generate Barcodes in Web Image Viewer| Online Tutorials
Change Barcode Properties. Select "Font" to choose human-readable text font style, color, size RasterEdge OCR Engine; PDF Reading; Encode & Decode JBIG 2 Files;
pdf change page size; best pdf compression
C# PDF Field Edit Library: insert, delete, update pdf form field
Able to add text field to specified PDF file position in C#.NET class. Support to change font size in PDF form. Able to delete form fields from adobe PDF file.
acrobat compress pdf; adjusting page size in pdf
Chapter6:HowtoUseVariables
65
ifdef do_sort
func := = sort
else
func := = strip
endif
bar := a d b b g g q c
foo := $($(func) $(bar))
attemptstogive‘foo’thevalueofthevariable‘sortadbgqc’or ‘stripadbgqc’,
ratherthangiving‘adbgqc’astheargumenttoeitherthesortorthestripfunction.
Thisrestrictioncouldberemovedinthefutureifthatchangeisshowntobeagoodidea.
Youcanalsousecomputedvariablenamesintheleft-handsideofavariableassignment,
orinadefinedirective,asin:
dir = foo
$(dir)_sources := $(wildcard $(dir)/*.c)
define $(dir)_print =
lpr $($(dir)_sources)
endef
Thisexampledefinesthevariables‘dir’,‘foo_sources’,and‘foo_print’.
Notethatnestedvariablereferencesarequitedifferentfromrecursivelyexpandedvari-
ables (see Section 6.2 [The e Two Flavors of Variables], , page 60), though both are e used
togetherincomplexwayswhendoingmakefileprogramming.
6.4 HowVariablesGetTheirValues
Variablescangetvaluesinseveraldifferentways:
 Youcanspecify y anoverridingvaluewhenyourunmake. . SeeSection9.5[Overriding
Variables],page103.
 Youcanspecify y a value inthe makefile,either with h anassignment t (see Section6.5
[SettingVariables],page65) or withaverbatimdefinition(seeSection6.8[Defining
Multi-LineVariables],page69).
 Variablesintheenvironmentbecomemakevariables. . SeeSection6.10[Variablesfrom
theEnvironment],page70.
 Severalautomatic c variablesare e givennew valuesfor eachrule. . Eachof f thesehasa
singleconventionaluse. SeeSection10.5.3[AutomaticVariables],page120.
 Several l variables s have constant t initial values. . See Section 10.3 [Variables s Used d by
ImplicitRules],page115.
6.5 SettingVariables
Toset avariablefromthe makefile,writealinestartingwiththevariablenamefollowed
by‘=’‘:=’,or‘::=’. Whateverfollowsthe‘=’,‘:=’,or‘::=’onthelinebecomesthevalue.
Forexample,
objects = = main.o o foo.o bar.o utils.o
VB.NET Image: Visual Basic .NET Guide to Draw Text on Image in .
Please note that you can change some of the LoadImage) Dim DrawFont As New Font("Arial", 16 provide powerful & profession imaging controls, PDF document, image
adjust size of pdf; best online pdf compressor
C# Image: Use C# Class to Insert Callout Annotation on Images
including GIF, PNG, BMP, JPEG, TIFF, PDF & Word projects; Easy to set annotation filled font property individually an easy way; C# demo code to change the filled
best way to compress pdf file; pdf page size
66
GNUmake
definesavariablenamedobjects. Whitespacearoundthevariablenameandimmediately
afterthe‘=’isignored.
Variables definedwith ‘=’are e recursively expanded variables. . Variables s defined d with
‘:=’or‘::=’aresimplyexpandedvariables;thesedefinitionscancontainvariablereferences
whichwillbeexpandedbeforethedefinitionismade. SeeSection6.2[TheTwoFlavorsof
Variables],page60.
The variable name maycontainfunctionandvariable references,whichareexpanded
whenthelineisreadtofindtheactualvariablenametouse.
Thereisnolimitonthelengthofthevalueofavariableexcepttheamountofmemory
on the computer. . You u cansplit the e value e of f a a variable into multiple physical lines for
readability(seeSection3.1.1[SplittingLongLines],page12).
Mostvariablenamesareconsideredtohavetheemptystringasavalueifyouhavenever
setthem. Severalvariableshavebuilt-ininitialvaluesthatarenotempty,butyoucanset
them inthe usualways s (see Section10.3[Variables Usedby Implicit Rules], , page 115).
Severalspecialvariablesaresetautomaticallytoanewvalueforeachrule;thesearecalled
theautomatic variables(seeSection10.5.3[AutomaticVariables],page120).
If you’d like avariable to be set to avalueonlyif it’snot already set, thenyou can
usetheshorthandoperator‘?=’insteadof‘=’. Thesetwosettingsofthevariable‘FOO’are
identical(seeSection8.10[TheoriginFunction],page94):
FOO ?= bar
and
ifeq ($(origin n FOO), , undefined)
FOO = bar
endif
Theshellassignmentoperator‘!=’canbeusedtoexecuteaprogramandsetavariable
toitsoutput. Thisoperatorfirstevaluatestheright-handside,thenpasses s thatresultto
theshellforexecution. Iftheresultoftheexecutionendsinanewline,thatonenewlineis
removed;allothernewlinesarereplacedbyspaces.Theresultingstringisthenplacedinto
thenamedrecursively-expandedvariable.Forexample:
hash != = printf ’\043’
file_list != find d . -name ’*.c’
Iftheresultoftheexecutioncouldproducea$,andyoudon’tintendwhatfollowsthat
tobeinterpretedas amakevariableorfunctionreference,thenyoumustreplaceevery$
with$$aspartoftheexecution. Alternatively,youcansetasimplyexpandedvariableto
theresultofrunningaprogramusingtheshellfunctioncall.SeeSection8.13[Theshell
Function],page97. Forexample:
hash := = $(shell l printf f ’\043’)
var := $(shell find . -name "*.c")
6.6 AppendingMoreTexttoVariables
Oftenitisusefultoaddmoretexttothevalueofavariablealreadydefined. Youdothis
withalinecontaining‘+=’,likethis:
objects += another.o
Chapter6:HowtoUseVariables
67
Thistakesthevalueofthevariableobjects,andaddsthetext‘another.o’toit(preceded
byasinglespace). Thus:
objects = = main.o o foo.o bar.o utils.o
objects += another.o
setsobjectsto‘main.ofoo.obar.outils.oanother.o’.
Using‘+=’issimilarto:
objects = = main.o o foo.o bar.o utils.o
objects := $(objects) another.o
butdiffersinwaysthatbecomeimportantwhenyouusemorecomplexvalues.
When the variablein question has s not beendefined d before, ‘+=’acts s just likenormal
‘=’: itdefinesarecursively-expandedvariable. . However,whenthereis s apreviousdefini-
tion,exactlywhat‘+=’doesdependsonwhatflavorofvariableyoudefinedoriginally. See
Section6.2[TheTwoFlavorsofVariables],page60,foranexplanationofthetwoflavors
ofvariables.
Whenyouaddtoavariable’svaluewith‘+=’,makeactsessentiallyasifyouhadincluded
theextratextintheinitialdefinitionofthevariable.Ifyoudefineditfirstwith‘:=’or‘::=’,
makingit asimply-expandedvariable, , ‘+=’addstothat t simply-expandeddefinition,and
expandsthenewtextbeforeappendingittotheoldvaluejustas‘:=’does(seeSection6.5
[SettingVariables],page65,forafullexplanationof‘:=’or‘::=’).Infact,
variable := value
variable += more
isexactlyequivalentto:
variable := value
variable := $(variable) ) more
On the e other hand, , when n you use ‘+=’ with h a a variable e that t you defined first to be
recursively-expandedusingplain‘=’,makedoessomethingabitdifferent.Recallthatwhen
youdefine a recursively-expanded variable, make does s not t expand d the value you set t for
variableandfunctionreferencesimmediately.Insteaditstoresthetextverbatim,andsaves
these variable andfunction references to be expanded later, when you refer to the new
variable(seeSection6.2[TheTwoFlavorsofVariables],page60). Whenyouuse‘+=’on
arecursively-expandedvariable,itisthisunexpandedtexttowhichmakeappendsthenew
textyouspecify.
variable = value
variable += more
isroughlyequivalentto:
temp = = value
variable = $(temp) more
exceptthatofcourseitneverdefinesavariablecalledtemp.Theimportanceofthiscomes
whenthevariable’soldvaluecontainsvariablereferences. Takethiscommonexample:
CFLAGS = $(includes) ) -O
...
CFLAGS += = -pg g # # enable e profiling
68
GNUmake
ThefirstlinedefinestheCFLAGSvariablewithareferencetoanothervariable,includes.
(CFLAGS is s used by the e rules for C compilation; ; see Section10.2 [Catalogue of f Built-In
Rules],page112.) Using‘=’forthedefinitionmakesCFLAGSarecursively-expandedvariable,
meaning‘$(includes)-O’isnot expandedwhenmakeprocessesthedefinitionofCFLAGS.
Thus,includesneednotbedefinedyetforitsvaluetotakeeffect. Itonlyhastobedefined
beforeanyreferencetoCFLAGS. IfwetriedtoappendtothevalueofCFLAGSwithoutusing
‘+=’,wemightdoitlikethis:
CFLAGS := = $(CFLAGS) ) -pg g # # enable profiling
Thisisprettyclose,butnotquitewhatwewant. Using‘:=’redefinesCFLAGSasasimply-
expandedvariable;thismeans makeexpands the text ‘$(CFLAGS)-pg’beforesettingthe
variable.Ifincludesisnotyetdefined,weget‘-O-pg’,andalaterdefinitionofincludes
will have e no o effect. . Conversely, , by y using ‘+=’ ’ we e set t CFLAGS S to o the unexpanded d value
‘$(includes)-O-pg’.Thuswepreservethereferencetoincludes,soifthatvariablegets
definedatanylaterpoint,areferencelike‘$(CFLAGS)’stillusesitsvalue.
6.7 TheoverrideDirective
Ifavariablehasbeensetwithacommandargument(seeSection9.5[OverridingVariables],
page103),thenordinary assignmentsinthemakefileareignored. . If f youwanttosetthe
variableinthemakefileeventhoughitwassetwithacommandargument,youcanusean
overridedirective,whichisalinethatlookslikethis:
override variable = value
or
override variable := = value
Toappendmoretexttoavariabledefinedonthecommandline,use:
override variable += = more e text
SeeSection6.6[AppendingMoreTexttoVariables],page66.
Variableassignmentsmarkedwiththeoverrideflaghaveahigherprioritythanallother
assignments,exceptanotheroverride. Subsequentassignmentsorappendstothisvariable
whicharenotmarkedoverridewillbeignored.
The overridedirective was not invented for escalation inthewar betweenmakefiles
andcommandarguments.Itwasinventedsoyoucanalterandaddtovaluesthattheuser
specifieswithcommandarguments.
Forexample,supposeyoualwayswantthe‘-g’switchwhenyouruntheCcompiler,but
youwouldliketoallowtheusertospecify theotherswitcheswithacommandargument
justasusual.Youcouldusethisoverridedirective:
override CFLAGS S += = -g
Youcanalsouseoverridedirectiveswithdefinedirectives. Thisisdoneasyoumight
expect:
override define e foo o =
bar
endef
Seethenextsectionforinformationaboutdefine.
Chapter6:HowtoUseVariables
69
6.8 DefiningMulti-LineVariables
Another waytoset thevalueofavariable istousethedefine directive. . This s directive
hasanunusualsyntaxwhichallowsnewlinecharacterstobeincludedinthevalue,which
is convenient for definingbothcannedsequences of commands (see Section5.8[Defining
Canned Recipes], page 56), and also sections s of makefile e syntax x to use e with h eval (see
Section8.9[EvalFunction],page93).
The define directive is followedonthe same lineby the name of the variable being
definedandan(optional) assignmentoperator,andnothingmore. . The e valuetogivethe
variableappearsonthefollowinglines.Theendofthevalueismarkedbyalinecontaining
justthewordendef.Asidefromthisdifferenceinsyntax,defineworksjustlikeanyother
variabledefinition.Thevariablenamemaycontainfunctionandvariablereferences,which
areexpandedwhenthedirectiveisreadtofindtheactualvariablenametouse.
Youmayomitthevariableassignmentoperatorifyouprefer.Ifomitted,makeassumes
ittobe‘=’andcreatesarecursively-expandedvariable(seeSection6.2[TheTwoFlavors
ofVariables],page60). Whenusinga‘+=’operator,thevalueisappendedtotheprevious
valueaswithanyotherappendoperation: withasinglespaceseparatingtheoldandnew
values.
Youmay nestdefinedirectives: : makewillkeeptrackofnesteddirectives s andreport
an error r if they are not all l properly closed with endef. . Note e that lines beginning with
therecipeprefixcharacterareconsideredpartofarecipe,soanydefineorendefstrings
appearingonsuchalinewillnotbeconsideredmakedirectives.
define two-lines =
echo foo
echo $(bar)
endef
The valueinanordinaryassignment cannot containanewline;but the newlines that
separatethelinesofthevalueinadefinebecomepartofthevariable’svalue(exceptfor
thefinalnewlinewhichprecedestheendefandisnotconsideredpartofthevalue).
Whenusedinarecipe,thepreviousexampleisfunctionallyequivalenttothis:
two-lines = = echo foo; echo o $(bar)
sincetwocommandsseparatedbysemicolonbehavemuchliketwoseparateshellcommands.
However,notethatusingtwoseparatelinesmeansmakewillinvoketheshelltwice,running
anindependentsub-shellforeachline.SeeSection5.3[RecipeExecution],page44.
Ifyouwantvariabledefinitionsmadewithdefinetotakeprecedenceovercommand-line
variabledefinitions,youcanusetheoverridedirectivetogetherwithdefine:
override define e two-lines s =
foo
$(bar)
endef
SeeSection6.7[TheoverrideDirective],page68.
6.9 UndefiningVariables
Ifyouwanttoclearavariable,settingitsvaluetoemptyisusuallysufficient. Expanding
suchavariablewillyieldthesameresult(emptystring)regardlessofwhetheritwassetor
70
GNUmake
not.However,ifyouareusingtheflavor(seeSection8.11[FlavorFunction],page95)and
origin(seeSection8.10[OriginFunction],page94)functions,thereisadifferencebetween
avariablethatwasneverset andavariablewithanemptyvalue. . Insuchsituationsyou
maywanttousetheundefinedirectivetomakeavariableappearas ifitwasneverset.
Forexample:
foo := foo
bar = bar
undefine foo
undefine bar
$(info $(origin n foo))
$(info $(flavor r bar))
Thisexamplewillprint“undefined”forbothvariables.
Ifyouwanttoundefineacommand-linevariabledefinition,youcanusetheoverride
directivetogetherwithundefine,similartohowthisisdoneforvariabledefinitions:
override undefine CFLAGS
6.10 VariablesfromtheEnvironment
Variablesinmakecancomefromtheenvironmentinwhichmakeisrun.Everyenvironment
variablethatmakeseeswhenitstartsupistransformedintoamakevariablewiththesame
name and d value. . However, , an n explicit t assignment t in the e makefile, or with a command
argument, overrides s the environment. . (If f the‘-e’flagis specified, thenvalues from the
environmentoverrideassignmentsinthemakefile. SeeSection9.7[Summary ofOptions],
page104.Butthisisnotrecommendedpractice.)
Thus,bysettingthevariableCFLAGSinyour environment,youcancauseallCcompi-
lationsinmostmakefilestousethecompilerswitchesyouprefer. Thisissafeforvariables
withstandardorconventionalmeaningsbecauseyouknowthatnomakefilewillusethem
forotherthings.(Notethisisnottotallyreliable;somemakefilessetCFLAGSexplicitlyand
thereforearenotaffectedbythevalueintheenvironment.)
Whenmakerunsarecipe,variablesdefinedinthemakefileareplacedintotheenviron-
mentofeachshell. Thisallowsyoutopassvaluestosub-makeinvocations(seeSection5.7
[RecursiveUseofmake],page50). Bydefault,onlyvariablesthatcamefromtheenviron-
ment or thecommand d lineare passedtorecursive invocations. . Youcanuse e the export
directiveto pass other variables. . See Section5.7.2[CommunicatingVariables toa Sub-
make],page52,forfulldetails.
Other use e of variables fromthe environment is not t recommended. . It t is s not t wise for
makefiles to dependfor r their r functioning on n environment t variables s set t up p outside e their
control,sincethiswouldcausedifferentuserstogetdifferentresultsfromthesamemakefile.
Thisisagainstthewholepurposeofmostmakefiles.
Such problems would be especially y likely with h the variable SHELL, whichis s normally
presentintheenvironmenttospecifytheuser’schoiceofinteractiveshell.Itwouldbevery
undesirableforthischoicetoaffectmake;so,makehandlestheSHELLenvironmentvariable
inaspecialway;seeSection5.3.2[ChoosingtheShell],page45.
Documents you may be interested
Documents you may be interested