Chapter10: UsingImplicitRules
111
10 UsingImplicitRules
Certain standard ways of f remaking target files are used d very y often. . For r example, , one
customarywaytomakeanobjectfileisfromaCsourcefileusingtheCcompiler,cc.
Implicit rules s tellmake e how to usecustomary techniques sothat youdo not have to
specifythemindetailwhenyouwanttousethem. Forexample,thereisanimplicitrule
for C compilation. . File e names determine which implicit rules are run. . For r example, , C
compilationtypicallytakesa.cfileandmakesa.ofile. Somakeappliestheimplicitrule
forCcompilationwhenitseesthiscombinationoffilenameendings.
Achainofimplicitrulescanapplyinsequence;forexample,makewillremakea.ofile
froma.yfilebywayofa.cfile. SeeSection10.4[ChainsofImplicitRules],page117.
The built-in n implicit t rules s use e several variables in their recipes so that, by changing
thevaluesofthevariables,youcanchangethewaytheimplicitruleworks. Forexample,
thevariable CFLAGS controlstheflags giventotheC compiler bytheimplicit rule for C
compilation. SeeSection10.3[VariablesUsedbyImplicitRules],page115.
Youcandefineyourownimplicitrulesbywritingpatternrules.SeeSection10.5[Defining
andRedefiningPatternRules],page118.
Suffixrulesareamorelimitedwaytodefineimplicitrules.Patternrulesaremoregeneral
andclearer,butsuffixrulesareretainedforcompatibility.SeeSection10.7[Old-Fashioned
SuffixRules],page125.
10.1 UsingImplicitRules
Toallowmaketofindacustomarymethodforupdatingatargetfile,allyouhavetodois
refrainfromspecifyingrecipes yourself. . Eitherwritearulewithnorecipe,ordon’twrite
aruleatall. Thenmakewillfigureoutwhichimplicitruletousebasedonwhichkindof
sourcefileexistsorcanbemade.
Forexample,supposethemakefilelookslikethis:
foo : foo.o bar.o
cc -o foo foo.o o bar.o o $(CFLAGS) $(LDFLAGS)
Becauseyoumentionfoo.obutdonotgivearuleforit,makewillautomaticallylookfor
animplicitrulethat tells howtoupdateit. . This s happens whetherornot thefile foo.o
currentlyexists.
Ifanimplicitruleis found,itcansupplybotharecipeandoneor moreprerequisites
(thesourcefiles). Youwouldwanttowritearuleforfoo.owithnorecipeifyouneedto
specifyadditionalprerequisites,suchasheaderfiles,thattheimplicitrulecannotsupply.
Eachimplicitrulehasatargetpatternandprerequisitepatterns. Theremaybemany
implicitruleswiththesametarget pattern. . For r example,numerousrules make‘.o’files:
one,froma‘.c’filewiththeCcompiler;another,froma‘.p’filewiththePascalcompiler;
andso on. . Therulethat t actually appliesis theonewhoseprerequisites exist or can n be
made. So,ifyouhaveafilefoo.c,makewillruntheCcompiler;otherwise,ifyouhavea
filefoo.p,makewillrunthePascalcompiler;andsoon.
Of course,whenyouwritethemakefile,youknow whichimplicit rule youwant make
touse,andyouknowitwillchoosethatonebecauseyouknowwhichpossibleprerequisite
Change font size pdf form reader - 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 fillable pdf; pdf optimized format
Change font size pdf form reader - 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
best way to compress pdf; pdf change font size in textbox
112
GNUmake
filesaresupposedtoexist. SeeSection10.2[CatalogueofBuilt-InRules],page112,fora
catalogueofallthepredefinedimplicitrules.
Above, we saidanimplicit t rule applies if the requiredprerequisites “exist or canbe
made”. Afile“canbemade”ifitismentionedexplicitlyinthemakefileas s atargetora
prerequisite,orifanimplicitrulecanberecursivelyfoundforhowtomakeit. Whenan
implicitprerequisiteistheresultofanotherimplicitrule,wesaythatchainingisoccurring.
SeeSection10.4[ChainsofImplicitRules],page117.
Ingeneral,makesearchesforanimplicitruleforeachtarget,andforeachdouble-colon
rule, that t has no recipe. . Afile e that is mentioned only as s aprerequisiteis considereda
targetwhoserulespecifiesnothing,soimplicitrulesearchhappensforit. SeeSection10.8
[ImplicitRuleSearchAlgorithm],page127,forthedetailsofhowthesearchisdone.
Notethatexplicitprerequisitesdonotinfluenceimplicitrulesearch. Forexample,con-
siderthisexplicitrule:
foo.o: foo.p
Theprerequisiteonfoo.pdoesnotnecessarilymeanthatmakewillremakefoo.oaccording
totheimplicitruletomakeanobjectfile,a.ofile,fromaPascalsourcefile,a.pfile. For
example,iffoo.calsoexists,theimplicitruletomakeanobjectfilefromaCsourcefile
isusedinstead,becauseitappearsbeforethePascalruleinthelistofpredefinedimplicit
rules(seeSection10.2[CatalogueofBuilt-InRules],page112).
Ifyoudonotwantanimplicitruletobeusedforatargetthathasnorecipe,youcan
givethattargetanemptyrecipebywritingasemicolon(seeSection5.9[DefiningEmpty
Recipes],page57).
10.2 CatalogueofBuilt-InRules
Here is s a a catalogue of f predefined d implicit t rules s which are e always s available e unless the
makefile explicitly overrides or r cancels them. . See Section 10.5.6 [Canceling Implicit
Rules],page124,for informationoncancelingor overridinganimplicit rule. . The e ‘-r’or
‘--no-builtin-rules’optioncancelsallpredefinedrules.
ThismanualonlydocumentsthedefaultrulesavailableonPOSIX-basedoperatingsys-
tems.Otheroperatingsystems,suchasVMS,Windows,OS/2,etc.mayhavedifferentsets
ofdefaultrules. Toseethefulllistofdefaultrulesandvariablesavailableinyourversion
ofGNUmake,run‘make-p’inadirectorywithnomakefile.
Not all l of theserules s willalways be defined,evenwhenthe ‘-r’ ’ optionis s not given.
Many ofthe predefined d implicit t rules are implemented d inmake e as suffix rules, , so which
oneswillbedefineddependsonthesuffixlist(thelistofprerequisitesofthespecialtarget
.SUFFIXES). Thedefaultsuffixlistis:.out,.a,.ln,.o,.c,.cc,.C,.cpp,.p,.f,.F,.m,
.r,.y,.l,.ym,.lm,.s,.S,.mod,.sym,.def,.h,.info,.dvi,.tex,.texinfo,.texi,
.txinfo, .w,.ch.web,.sh, .elc,.el. . Alloftheimplicit t rules describedbelow whose
prerequisiteshaveoneofthesesuffixesareactuallysuffixrules.Ifyoumodifythesuffixlist,
theonlypredefinedsuffixrulesineffectwillbethosenamedbyoneortwoofthesuffixes
thatareonthelistyouspecify;ruleswhosesuffixesfailtobeonthelistaredisabled. See
Section10.7[Old-FashionedSuffixRules],page125,forfulldetailsonsuffixrules.
CompilingCprograms
n.o is s made e automatically from n.c with a recipe of f the e form ‘$(CC)
$(CPPFLAGS)$(CFLAGS)-c’.
C# PDF insert text Library: insert text into PDF content in C#.net
without adobe reader installed in ASP.NET. Powerful .NET PDF edit control allows modify existing scanned PDF text. Ability to change text font, color, size and
optimize scanned pdf; pdf text box font size
C# PDF Annotate Library: Draw, edit PDF annotation, markups in C#.
reader installed. Support to add text, text box, text field and crop marks to PDF document. Able to edit and change PDF annotation properties such as font size
pdf form change font size; best way to compress pdf files
Chapter10: UsingImplicitRules
113
CompilingC++programs
n.oismadeautomaticallyfromn.cc,n.cpp,orn.Cwitharecipeoftheform
‘$(CXX)$(CPPFLAGS)$(CXXFLAGS)-c’. We e encourage youto use the suffix
‘.cc’forC++sourcefilesinsteadof‘.C’.
CompilingPascalprograms
n.oismadeautomaticallyfromn.pwiththerecipe‘$(PC)$(PFLAGS)-c’.
CompilingFortranandRatforprograms
n.oismadeautomaticallyfromn.r,n.Forn.fbyrunningtheFortrancom-
piler. Thepreciserecipeusedisasfollows:
‘.f’
‘$(FC)$(FFLAGS)-c’.
‘.F’
‘$(FC)$(FFLAGS)$(CPPFLAGS)-c’.
‘.r’
‘$(FC)$(FFLAGS)$(RFLAGS)-c’.
PreprocessingFortranandRatforprograms
n.fismadeautomaticallyfromn.rorn.F.Thisrulerunsjustthepreprocessor
to convert a Ratfor r or r preprocessable Fortran n program into a strict Fortran
program. Thepreciserecipeusedisasfollows:
‘.F’
‘$(FC)$(CPPFLAGS)$(FFLAGS)-F’.
‘.r’
‘$(FC)$(FFLAGS)$(RFLAGS)-F’.
CompilingModula-2programs
n.sym is made from
n.def with h a recipe e of f the form
‘$(M2C)
$(M2FLAGS)$(DEFFLAGS)’.
n.o is s made e from n.mod; ; the e form is:
‘$(M2C)$(M2FLAGS)$(MODFLAGS)’.
Assemblingandpreprocessingassemblerprograms
n.oismadeautomaticallyfromn.sbyrunningtheassembler,as.Theprecise
recipeis‘$(AS)$(ASFLAGS)’.
n.sismadeautomaticallyfromn.SbyrunningtheCpreprocessor,cpp. The
preciserecipeis‘$(CPP)$(CPPFLAGS)’.
Linkingasingleobjectfile
n is made automatically from
n.o by running the linker (usu-
ally called ld) ) via a the C compiler.
The precise recipe used is
‘$(CC)$(LDFLAGS)n.o$(LOADLIBES)$(LDLIBS)’.
Thisruledoestherightthingforasimpleprogramwithonlyonesourcefile. It
willalsodotherightthingiftherearemultipleobjectfiles(presumablycoming
fromvariousothersourcefiles),oneofwhichhasanamematchingthatofthe
executablefile.Thus,
x: y.o o z.o
whenx.c,y.candz.callexistwillexecute:
C# PDF Sticky Note Library: add, delete, update PDF note in C#.net
enable users to annotate PDF without adobe PDF reader control installed. Able to add notes to PDF using C# source Able to change font size in PDF comment box.
pdf page size; change font size pdf document
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.
pdf edit text size; adjust size of pdf
114
GNUmake
cc -c x.c c -o o x.o
cc -c y.c c -o o y.o
cc -c z.c c -o o z.o
cc x.o o y.o o z.o o -o x
rm -f x.o
rm -f y.o
rm -f z.o
Inmore complicatedcases,such as whenthere is noobject filewhose name
derives from m the executable file name, youmust t write an n explicit t recipe for
linking.
Eachkindoffileautomaticallymadeinto‘.o’objectfileswillbeautomatically
linkedbyusingthecompiler(‘$(CC)’,‘$(FC)’or‘$(PC)’;theCcompiler‘$(CC)’
isusedtoassemble‘.s’files)withoutthe‘-c’option. Thiscouldbedoneby
usingthe‘.o’objectfilesasintermediates,butitisfastertodothecompiling
andlinkinginonestep,sothat’showit’sdone.
YaccforCprograms
n.cismadeautomaticallyfromn.ybyrunningYaccwiththerecipe‘$(YACC)
$(YFLAGS)’.
LexforCprograms
n.c is s made automatically from m n.l by running Lex. . The e actual l recipe is
‘$(LEX)$(LFLAGS)’.
LexforRatforprograms
n.r is s made automatically from m n.l by running Lex. . The e actual l recipe is
‘$(LEX)$(LFLAGS)’.
Theconventionofusingthesamesuffix‘.l’forallLexfilesregardlessofwhether
theyproduceCcodeorRatforcodemakesitimpossibleformaketodetermine
automaticallywhichofthetwolanguagesyouareusinginanyparticularcase.If
makeiscalledupontoremakeanobjectfilefroma‘.l’file,itmustguesswhich
compiler touse. . ItwillguesstheC C compiler,becausethat ismorecommon.
IfyouareusingRatfor,makesuremakeknowsthisbymentioningn.rinthe
makefile. Or,ifyouareusingRatforexclusively,withnoCfiles,remove‘.c’
fromthelistofimplicitrulesuffixeswith:
.SUFFIXES:
.SUFFIXES: .o .r .f .l ...
MakingLintLibrariesfromC,Yacc,orLexprograms
n.ln is s made e from n.c by running g lint.
The precise recipe is
‘$(LINT)$(LINTFLAGS)$(CPPFLAGS)-i’. Thesamerecipe e isusedontheC
codeproducedfromn.yorn.l.
T
E
XandWeb
n.dviismadefromn.texwiththerecipe‘$(TEX)’.n.texismadefromn.web
with‘$(WEAVE)’,orfromn.w(andfromn.chifitexistsorcanbemade)with
‘$(CWEAVE)’.n.pismadefromn.webwith‘$(TANGLE)’andn.cismadefrom
n.w(andfromn.chifitexistsorcanbemade)with‘$(CTANGLE)’.
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
reduce pdf file size; reader compress pdf
Generate Barcodes in Web Image Viewer| Online Tutorials
Set barcode orientation and rotation angle; Change barcode image width & height; Colorize Set human-readable text font style, color, size; Resize barcode
pdf custom paper size; change font size in pdf fillable form
Chapter10: UsingImplicitRules
115
TexinfoandInfo
n.dvi is s made from m n.texinfo, , n.texi, or r n.txinfo, , with h the e recipe
‘$(TEXI2DVI)$(TEXI2DVI_FLAGS)’.n.infoismadefromn.texinfo,n.texi,
orn.txinfo,withtherecipe‘$(MAKEINFO)$(MAKEINFO_FLAGS)’.
RCS
Any file n is extracted if necessary from m an n RCS S file e named d either n,v v or
RCS/n,v. The e precise recipe usedis ‘$(CO)$(COFLAGS)’. . n n willnot t be e ex-
tracted from RCS S if it t already y exists, even if f the e RCS S file e is s newer. . The
rulesforRCSareterminal(seeSection10.5.5[Match-AnythingPatternRules],
page 123), so RCSfiles s cannotbegeneratedfromanothersource; ; theymust
actuallyexist.
SCCS
Any file e n n is s extracted d if necessary from an SCCS file named either r s.n or
SCCS/s.n.Thepreciserecipeusedis‘$(GET)$(GFLAGS)’. TherulesforSCCS
areterminal(seeSection10.5.5[Match-AnythingPatternRules],page123),so
SCCSfilescannotbegeneratedfromanothersource;theymustactuallyexist.
For the benefit t of SCCS, , a file n is s copied d from n.sh and made executable
(byeveryone). ThisisforshellscriptsthatarecheckedintoSCCS.SinceRCS
preservestheexecutionpermissionofafile,youdonotneedtousethisfeature
withRCS.
WerecommendthatyouavoidusingofSCCS.RCSiswidelyheldtobesuperior,
andisalsofree. Bychoosingfreesoftwareinplaceofcomparable(orinferior)
proprietarysoftware,yousupportthefreesoftwaremovement.
Usually, you want t to change only the variables s listed in the e table above, which are
documentedinthefollowingsection.
However,therecipesinbuilt-inimplicitrulesactuallyusevariablessuchasCOMPILE.c,
LINK.p,andPREPROCESS.S,whosevaluescontaintherecipeslistedabove.
makefollows the conventionthattheruletocompilea.xsourcefile usesthevariable
COMPILE.x. Similarly,theruletoproduceanexecutablefroma a .x fileuses LINK.x; and
theruletopreprocessa.xfileusesPREPROCESS.x.
EveryrulethatproducesanobjectfileusesthevariableOUTPUT_OPTION. makedefines
thisvariableeithertocontain‘-o$@’,ortobeempty,dependingonacompile-timeoption.
Youneedthe‘-o’optiontoensurethattheoutputgoesintotherightfilewhenthesource
file is s in a a different directory, as s when using g VPATH (see Section 4.4 [Directory y Search],
page25). However,compilersonsomesystemsdonotaccepta‘-o’switchforobjectfiles.
If youusesuchasystem,anduse VPATH,somecompilationswillputtheir output inthe
wrongplace. Apossibleworkaroundforthis s problemistogiveOUTPUT_OPTIONthevalue
‘;mv$*.o$@’.
10.3 VariablesUsedbyImplicitRules
Therecipesinbuilt-inimplicitrulesmakeliberaluseofcertainpredefinedvariables. You
canalterthevaluesofthesevariablesinthemakefile,withargumentstomake,orintheen-
vironmenttoalterhowtheimplicitrulesworkwithoutredefiningtherulesthemselves.You
cancancelallvariablesusedbyimplicitruleswiththe‘-R’or‘--no-builtin-variables’
option.
VB.NET Image: Visual Basic .NET Guide to Draw Text on Image in .
Please note that you can change some of the example, you can adjust the text font, font size, font type (regular LoadImage) Dim DrawFont As New Font("Arial", 16
pdf markup text size; pdf file size
Generate Image in .NET Winforms Imaging Viewer| Online Tutorials
Change Barcode Properties. barcode rotation angle; Click "Width" and "Height" to set barcode size; Click "Font" to choose human-readable text font style, color
can a pdf file be compressed; best pdf compression
116
GNUmake
Forexample,therecipeusedtocompileaCsourcefileactuallysays‘$(CC)-c$(CFLAGS)
$(CPPFLAGS)’. Thedefault t valuesofthevariablesusedare‘cc’andnothing,resultingin
the command‘cc-c’. . By y redefining ‘CC’to ‘ncc’,youcould d cause ‘ncc’to be used for
allCcompilationsperformedby theimplicitrule. . By y redefining‘CFLAGS’tobe‘-g’,you
couldpassthe‘-g’optiontoeachcompilation.All implicitrulesthatdoCcompilationuse
‘$(CC)’togettheprogramnameforthecompilerandall include‘$(CFLAGS)’amongthe
argumentsgiventothecompiler.
Thevariablesusedinimplicitrulesfallintotwoclasses:thosethatarenamesofprograms
(likeCC)andthosethatcontainargumentsfortheprograms(likeCFLAGS). (The“nameof
aprogram”mayalsocontainsomecommandarguments,butitmuststartwithanactual
executableprogramname.) Ifavariablevaluecontainsmorethanoneargument,separate
themwithspaces.
Thefollowingtablesdescribeofsomeofthemorecommonly-usedpredefinedvariables.
Thislistisnotexhaustive,andthedefaultvaluesshownheremaynotbewhatmakeselects
foryourenvironment. Toseethecompletelistofpredefinedvariablesforyourinstanceof
GNUmakeyoucanrun‘make-p’inadirectorywithnomakefiles.
Here isa table ofsomeof themore commonvariables usedas namesofprograms in
built-inrules:
AR
Archive-maintainingprogram;default‘ar’.
AS
Programforcompilingassemblyfiles;default‘as’.
CC
ProgramforcompilingCprograms;default‘cc’.
CXX
ProgramforcompilingC++programs;default‘g++’.
CPP
ProgramforrunningtheCpreprocessor,withresultstostandardoutput;de-
fault‘$(CC)-E’.
FC
ProgramforcompilingorpreprocessingFortranandRatforprograms;default
‘f77’.
M2C
ProgramtousetocompileModula-2sourcecode;default‘m2c’.
PC
ProgramforcompilingPascalprograms;default‘pc’.
CO
ProgramforextractingafilefromRCS;default‘co’.
GET
ProgramforextractingafilefromSCCS;default‘get’.
LEX
ProgramtousetoturnLexgrammarsintosourcecode;default‘lex’.
YACC
ProgramtousetoturnYaccgrammarsintosourcecode;default‘yacc’.
LINT
Programtousetorunlintonsourcecode;default‘lint’.
MAKEINFO ProgramtoconvertaTexinfosourcefileintoanInfofile;default‘makeinfo’.
TEX
ProgramtomakeT
E
XdvifilesfromT
E
Xsource;default‘tex’.
TEXI2DVI ProgramtomakeT
E
XdvifilesfromTexinfosource;default‘texi2dvi’.
WEAVE
ProgramtotranslateWebintoT
E
X;default‘weave’.
CWEAVE
ProgramtotranslateCWebintoT
E
X;default‘cweave’.
Chapter10: UsingImplicitRules
117
TANGLE
ProgramtotranslateWebintoPascal;default‘tangle’.
CTANGLE
ProgramtotranslateCWebintoC;default‘ctangle’.
RM
Commandtoremoveafile;default‘rm-f’.
Here is s a a table of f variables whose values are e additional arguments for the programs
above. Thedefaultvaluesforalloftheseistheemptystring,unlessotherwisenoted.
ARFLAGS
Flagstogivethearchive-maintainingprogram;default‘rv’.
ASFLAGS
Extraflagstogivetotheassembler(whenexplicitly invokedona‘.s’or‘.S’
file).
CFLAGS
ExtraflagstogivetotheCcompiler.
CXXFLAGS ExtraflagstogivetotheC++compiler.
COFLAGS
ExtraflagstogivetotheRCScoprogram.
CPPFLAGS ExtraflagstogivetotheCpreprocessorandprogramsthatuseit(theCand
Fortrancompilers).
FFLAGS
ExtraflagstogivetotheFortrancompiler.
GFLAGS
ExtraflagstogivetotheSCCSgetprogram.
LDFLAGS
Extraflagstogivetocompilers whenthey aresupposedtoinvokethelinker,
‘ld’, suchas s -L. . Libraries s (-lfoo) should d be added to the LDLIBS S variable
instead.
LDLIBS
Libraryflags or names giventocompilers whenthey are supposed d to invoke
thelinker,‘ld’. LOADLIBESisadeprecated(butstillsupported)alternativeto
LDLIBS.Non-librarylinkerflags,suchas-L,shouldgointheLDFLAGSvariable.
LFLAGS
ExtraflagstogivetoLex.
YFLAGS
ExtraflagstogivetoYacc.
PFLAGS
ExtraflagstogivetothePascalcompiler.
RFLAGS
ExtraflagstogivetotheFortrancompilerforRatforprograms.
LINTFLAGS
Extraflagstogivetolint.
10.4 ChainsofImplicitRules
Sometimesafilecanbemadebyasequenceofimplicitrules. Forexample,afilen.ocould
bemadefromn.ybyrunningfirstYaccandthencc.Suchasequenceiscalledachain.
Ifthefile n.cexists,orismentionedinthemakefile,nospecialsearchingisrequired:
make finds that theobject file canbe madeby C compilationfromn.c; ; later r on, , when
consideringhowtomaken.c,theruleforrunningYaccisused. Ultimatelybothn.cand
n.oareupdated.
However,evenifn.cdoesnotexistandisnotmentioned,makeknowshowtoenvision
itasthemissinglinkbetweenn.oandn.y! Inthiscase,n.ciscalledanintermediatefile.
118
GNUmake
Oncemakehasdecidedtousetheintermediatefile,itisenteredinthedatabaseasifithad
beenmentionedinthemakefile,alongwiththeimplicitrulethatsayshowtocreateit.
Intermediatefilesareremadeusingtheirrulesjustlikeallotherfiles. Butintermediate
filesaretreateddifferentlyintwoways.
Thefirstdifferenceiswhathappensiftheintermediatefiledoesnotexist.Ifanordinary
filebdoesnotexist,andmakeconsidersatargetthatdependsonb,itinvariablycreatesb
andthenupdatesthetargetfromb.Butifbisanintermediatefile,thenmakecanleavewell
enoughalone. Itwon’tbotherupdatingb,ortheultimatetarget,unlesssomeprerequisite
ofbisnewerthanthattargetorthereissomeotherreasontoupdatethattarget.
The seconddifferenceis thatifmakedoes s createbinordertoupdatesomethingelse,
itdeletesblateronafteritisnolongerneeded. Therefore,anintermediatefilewhichdid
not exist beforemakealsodoes notexistafter make. . makereportsthedeletiontoyouby
printinga‘rm-f’commandshowingwhichfileitisdeleting.
Ordinarily,afilecannot be intermediateifit ismentionedinthemakefile asatarget
or prerequisite. . However, , you can explicitly mark k a file as intermediate by listing it as
a prerequisite of the special target t .INTERMEDIATE. . This s takes s effect even if f the file is
mentionedexplicitlyinsomeotherway.
Youcanpreventautomaticdeletionofanintermediatefilebymarkingitasasecondary
file. To o do this, list it as a prerequisite of the special target t .SECONDARY. . When n afile
is secondary, , make e will l not t create the file merely becauseit does not already exist, , but
makedoes not automaticallydeletethefile. . Markingafileas s secondaryalsomarksit as
intermediate.
Youcanlistthetargetpatternofanimplicitrule(suchas‘%.o’)asaprerequisiteofthe
specialtarget.PRECIOUStopreserveintermediatefilesmadebyimplicitruleswhosetarget
patternsmatchthatfile’sname;seeSection5.6[Interrupts],page50.
Achaincaninvolvemorethantwoimplicitrules.Forexample,itispossibletomakea
filefoofromRCS/foo.y,vbyrunningRCS,Yaccandcc. Thenbothfoo.yandfoo.care
intermediatefilesthataredeletedattheend.
Nosingle implicit rulecanappearmore thanonce inachain. . This s meansthat make
willnotevenconsidersucharidiculousthingasmakingfoofromfoo.o.obyrunningthe
linkertwice. Thisconstraint t hastheaddedbenefitof preventinganyinfinite loopinthe
searchforanimplicitrulechain.
There are some specialimplicit rules to optimize certain cases that would otherwise
be handledby y rule chains. . For r example, , making g foo o from foo.c could be e handled by
compilingandlinkingwithseparatechainedrules,usingfoo.oasanintermediatefile. But
whatactuallyhappensisthataspecialruleforthiscasedoesthecompilationandlinking
witha singlecccommand. . The e optimizedruleis usedinpreference to the step-by-step
chainbecauseitcomesearlierintheorderingofrules.
10.5 DefiningandRedefiningPatternRules
Youdefineanimplicitrulebywritingapatternrule.Apatternrulelookslikeanordinary
rule,exceptthatitstargetcontainsthecharacter‘%’(exactlyoneofthem). Thetargetis
consideredapatternformatchingfilenames;the‘%’canmatchanynonemptysubstring,
whileother characters matchonly themselves. . Theprerequisites s likewiseuse‘%’toshow
howtheirnamesrelatetothetargetname.
Chapter10: UsingImplicitRules
119
Thus, apatternrule ‘%.o:%.c’ says s how to make any file stem.o from m another r file
stem.c.
Notethatexpansionusing‘%’inpatternrulesoccursafteranyvariableorfunctionex-
pansions,whichtakeplacewhenthemakefileisread. SeeChapter6[HowtoUseVariables],
page59,andChapter8[FunctionsforTransformingText],page83.
10.5.1 IntroductiontoPatternRules
Apatternrulecontainsthecharacter‘%’(exactlyoneofthem)inthetarget;otherwise,it
looksexactlylikeanordinaryrule. Thetargetisapatternformatchingfilenames;the‘%’
matchesanynonemptysubstring,whileothercharactersmatchonlythemselves.
For example,‘%.c’ as s a pattern n matches any y filename that ends in n ‘.c’. . ‘s.%.c’as
a pattern matches s any y file e name e that t starts s with‘s.’, , ends in‘.c’ and is s at least five
characterslong. (There e must beatleastone charactertomatchthe ‘%’.) ) The e substring
thatthe‘%’matchesiscalledthestem.
‘%’inaprerequisiteofapatternrulestandsforthesamestemthatwasmatchedbythe
‘%’inthetarget. Inorderforthepatternruletoapply,itstargetpatternmustmatchthe
filenameunderconsiderationandallofitsprerequisites(afterpatternsubstitution)must
namefilesthatexistorcanbemade.Thesefilesbecomeprerequisitesofthetarget.
Thus,aruleoftheform
%.o : %.c c ; ; recipe...
specifieshowtomakeafilen.o,withanotherfilen.casitsprerequisite,providedthatn.c
existsorcanbemade.
Theremayalsobeprerequisitesthatdonotuse‘%’;suchaprerequisiteattachestoevery
filemadebythispatternrule.Theseunvaryingprerequisitesareusefuloccasionally.
Apatternruleneednothaveanyprerequisitesthatcontain‘%’,orinfactanyprerequi-
sitesatall. Sucharuleiseffectivelyageneralwildcard.Itprovidesawaytomakeanyfile
thatmatchesthetargetpattern. SeeSection10.6[LastResort],page125.
Morethanonepatternrulemaymatchatarget. Inthiscasemakewillchoosethe“best
fit”rule. SeeSection10.5.4[HowPatternsMatch],page122.
Patternrulesmayhavemorethanonetarget. Unlikenormalrules,thisdoesnotactas
manydifferentruleswiththesameprerequisitesandrecipe. Ifapatternrulehasmultiple
targets,makeknowsthattherule’srecipeisresponsibleformakingallofthetargets.The
recipeisexecutedonlyoncetomakeallthetargets. Whensearchingforapatternruleto
matchatarget,thetargetpatternsofaruleotherthantheonethatmatchesthetargetin
needofaruleareincidental: makeworriesonlyaboutgivingarecipeandprerequisitesto
thefilepresentlyinquestion. However,whenthisfile’srecipeisrun,theothertargetsare
markedashavingbeenupdatedthemselves.
10.5.2 PatternRuleExamples
Herearesomeexamplesofpatternrulesactuallypredefinedinmake. First,therulethat
compiles‘.c’filesinto‘.o’files:
%.o : %.c
$(CC) -c $(CFLAGS) ) $(CPPFLAGS) ) $< -o $@
120
GNUmake
definesarulethatcanmakeanyfilex.ofromx.c.Therecipeusestheautomaticvariables
‘$@’and‘$<’tosubstitutethenamesofthetargetfileandthesourcefileineachcasewhere
theruleapplies(seeSection10.5.3[AutomaticVariables],page120).
Hereisasecondbuilt-inrule:
% :: RCS/%,v
$(CO) $(COFLAGS) $<
definesarulethatcanmakeanyfilexwhatsoeverfromacorrespondingfilex,vinthesub-
directoryRCS.Sincethetargetis‘%’,thisrulewillapplytoanyfilewhatever,providedthe
appropriateprerequisitefileexists.Thedoublecolonmakestheruleterminal,whichmeans
thatitsprerequisitemaynot beanintermediatefile (see Section10.5.5[Match-Anything
PatternRules],page123).
Thispatternrulehastwotargets:
%.tab.c %.tab.h: %.y
bison -d $<
Thistellsmake that therecipe ‘bison-dx.y’willmake both h x.tab.c c and d x.tab.h. . If
the file foo depends on the files parse.tab.o andscan.o and the file scan.o depends
onthefileparse.tab.h,whenparse.yischanged,therecipe‘bison-dparse.y’willbe
executedonlyonce,andtheprerequisitesofbothparse.tab.oandscan.owillbesatisfied.
(Presumablythefileparse.tab.owillberecompiledfromparse.tab.candthefilescan.o
fromscan.c,whilefoo islinkedfromparse.tab.o,scan.o,anditsotherprerequisites,
anditwillexecutehappilyeverafter.)
10.5.3 AutomaticVariables
Supposeyouarewritingapatternruletocompilea‘.c’file intoa‘.o’file: : howdoyou
writethe‘cc’commandsothatitoperatesontherightsourcefilename?Youcannotwrite
thenameintherecipe,becausethenameisdifferenteachtimetheimplicitruleisapplied.
Whatyoudoisuseaspecialfeatureofmake,theautomaticvariables. Thesevariables
havevaluescomputedafreshforeachrulethatisexecuted,basedonthetargetandprereq-
uisitesoftherule.Inthisexample,youwoulduse‘$@’fortheobjectfilenameand‘$<’for
thesourcefilename.
It’s very important that yourecognize the limited d scopein which automatic variable
valuesareavailable: theyonlyhavevalueswithintherecipe.Inparticular,youcannotuse
themanywherewithinthetargetlist ofarule;theyhavenovaluethereandwillexpand
tothe empty string. . Also, , they y cannot be accesseddirectly within n the prerequisite list
of a rule. . Acommon n mistakeis s attempting touse $@ withinthe prerequisites list; ; this
willnotwork. However,thereisaspecialfeatureofGNUmake,secondaryexpansion(see
Section3.8[SecondaryExpansion],page18),whichwillallowautomaticvariablevaluesto
beusedinprerequisitelists.
Hereisatableofautomaticvariables:
$@
Thefilenameofthetargetoftherule. Ifthetargetisanarchivemember,then
‘$@’isthenameofthearchivefile. Inapatternrulethathasmultipletargets
(seeSection10.5.1[IntroductiontoPatternRules],page119),‘$@’isthename
ofwhichevertargetcausedtherule’srecipetoberun.
Documents you may be interested
Documents you may be interested