xref: /freebsd/share/man/man5/style.Makefile.5 (revision 2322159a2b7eb41bb34cafd1b24182735c183367)
1*2322159aSDavid E. O'Brien.\" Copyright (c) 2002-2003, 2023 David O'Brien <obrien@FreeBSD.org>
291c8d237SDavid E. O'Brien.\" All rights reserved.
391c8d237SDavid E. O'Brien.\"
491c8d237SDavid E. O'Brien.\" Redistribution and use in source and binary forms, with or without
591c8d237SDavid E. O'Brien.\" modification, are permitted provided that the following conditions
691c8d237SDavid E. O'Brien.\" are met:
791c8d237SDavid E. O'Brien.\" 1. Redistributions of source code must retain the above copyright
891c8d237SDavid E. O'Brien.\"    notice, this list of conditions and the following disclaimer.
991c8d237SDavid E. O'Brien.\" 2. Redistributions in binary form must reproduce the above copyright
1091c8d237SDavid E. O'Brien.\"    notice, this list of conditions and the following disclaimer in the
1191c8d237SDavid E. O'Brien.\"    documentation and/or other materials provided with the distribution.
1291c8d237SDavid E. O'Brien.\" 3. Neither the name of the author nor the names of any contributors
1391c8d237SDavid E. O'Brien.\"    may be used to endorse or promote products derived from this software
1491c8d237SDavid E. O'Brien.\"    without specific prior written permission.
1591c8d237SDavid E. O'Brien.\"
1691c8d237SDavid E. O'Brien.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1791c8d237SDavid E. O'Brien.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1891c8d237SDavid E. O'Brien.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1991c8d237SDavid E. O'Brien.\" ARE DISCLAIMED.  IN NO EVENT SHALL DAVID O'BRIEN OR CONTRIBUTORS BE LIABLE
2091c8d237SDavid E. O'Brien.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2191c8d237SDavid E. O'Brien.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2291c8d237SDavid E. O'Brien.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2391c8d237SDavid E. O'Brien.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2491c8d237SDavid E. O'Brien.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2591c8d237SDavid E. O'Brien.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2691c8d237SDavid E. O'Brien.\" SUCH DAMAGE.
2791c8d237SDavid E. O'Brien.\"
2873fb7a7aSMateusz Piotrowski.Dd July 17, 2023
2991c8d237SDavid E. O'Brien.Dt STYLE.MAKEFILE 5
3091c8d237SDavid E. O'Brien.Os
3191c8d237SDavid E. O'Brien.Sh NAME
3291c8d237SDavid E. O'Brien.Nm style.Makefile
33ef91670aSDavid E. O'Brien.Nd
34ef91670aSDavid E. O'Brien.Fx
35ef91670aSDavid E. O'Brien.Pa Makefile
36ef91670aSDavid E. O'Brienfile style guide
3791c8d237SDavid E. O'Brien.Sh DESCRIPTION
38ef91670aSDavid E. O'BrienThis file specifies the preferred style for makefiles in the
3991c8d237SDavid E. O'Brien.Fx
4091c8d237SDavid E. O'Briensource tree.
41ef91670aSDavid E. O'Brien.Bl -bullet
4291c8d237SDavid E. O'Brien.It
43ef91670aSDavid E. O'Brien.Cm .PATH :
449e850513SMateusz Piotrowskicomes first if needed, and is spelled
45ef91670aSDavid E. O'Brien.Dq Li ".PATH: " ,
46ef91670aSDavid E. O'Brienwith a single
47ef91670aSDavid E. O'Brien.Tn ASCII
48ef91670aSDavid E. O'Brienspace after a colon.
49a250a461SDavid E. O'BrienDo not use the
50a250a461SDavid E. O'Brien.Va VPATH
51a250a461SDavid E. O'Brienvariable.
5291c8d237SDavid E. O'Brien.It
53ef91670aSDavid E. O'BrienSpecial variables (i.e.,
54ef91670aSDavid E. O'Brien.Va LIB , SRCS , MLINKS ,
55ef91670aSDavid E. O'Brienetc.) are listed in order of
56ef91670aSDavid E. O'Brien.Dq product ,
5791c8d237SDavid E. O'Brienthen building and installing a binary.
587b5570bfSDavid E. O'BrienSpecial variables may also be listed in
59ed403545SDavid E. O'Brien.Dq build
60ed403545SDavid E. O'Brienorder: i.e., ones for the primary program (or library) first.
61ed403545SDavid E. O'BrienThe general
62ed403545SDavid E. O'Brien.Dq product
63ed403545SDavid E. O'Brienorder is:
64b37af785SBruce Evans.Va PROG Ns / Ns Oo Va SH Oc Ns Va LIB Ns / Ns Va SCRIPTS
6591c8d237SDavid E. O'Brien.Va FILES
6691c8d237SDavid E. O'Brien.Va LINKS
6773fb7a7aSMateusz Piotrowski.Va MAN
68ef91670aSDavid E. O'Brien.Va MLINKS
6991c8d237SDavid E. O'Brien.Va INCS
70ef91670aSDavid E. O'Brien.Va SRCS
7191c8d237SDavid E. O'Brien.Va WARNS
726b3a148cSAlex Richardson.Va CSTD
7391c8d237SDavid E. O'Brien.Va CFLAGS
7491c8d237SDavid E. O'Brien.Va DPADD
75ef91670aSDavid E. O'Brien.Va LDADD .
76ed403545SDavid E. O'BrienThe general
77ed403545SDavid E. O'Brien.Dq build
78ed403545SDavid E. O'Brienorder is:
79b37af785SBruce Evans.Va PROG Ns / Ns Oo Va SH Oc Ns Va LIB Ns / Ns Va SCRIPTS
80ed403545SDavid E. O'Brien.Va SRCS
81ed403545SDavid E. O'Brien.Va WARNS
826b3a148cSAlex Richardson.Va CSTD
83ed403545SDavid E. O'Brien.Va CFLAGS
84ed403545SDavid E. O'Brien.Va DPADD
85ed403545SDavid E. O'Brien.Va LDADD
86ed403545SDavid E. O'Brien.Va INCS
87ed403545SDavid E. O'Brien.Va FILES
88ed403545SDavid E. O'Brien.Va LINKS
8973fb7a7aSMateusz Piotrowski.Va MAN
90ed403545SDavid E. O'Brien.Va MLINKS .
9191c8d237SDavid E. O'Brien.It
9291c8d237SDavid E. O'BrienOmit
93ef91670aSDavid E. O'Brien.Va SRCS
9491c8d237SDavid E. O'Brienwhen using
95fe08efe6SRuslan Ermilov.In bsd.prog.mk
9691c8d237SDavid E. O'Brienand there is a single source file named the same as the
9791c8d237SDavid E. O'Brien.Va PROG .
9891c8d237SDavid E. O'Brien.It
9991c8d237SDavid E. O'BrienOmit
10091c8d237SDavid E. O'Brien.Va MAN
10191c8d237SDavid E. O'Brienwhen using
102fe08efe6SRuslan Ermilov.In bsd.prog.mk
103ef91670aSDavid E. O'Brienand the manual page is named the same as the
104ef91670aSDavid E. O'Brien.Va PROG ,
10591c8d237SDavid E. O'Brienand is in section 1.
10691c8d237SDavid E. O'Brien.It
107ef91670aSDavid E. O'BrienAll variable assignments are spelled
108ef91670aSDavid E. O'Brien.Dq Va VAR Ns Ic = ,
109ef91670aSDavid E. O'Brieni.e., no space between the variable name and the
110ef91670aSDavid E. O'Brien.Ic = .
11191c8d237SDavid E. O'BrienKeep values sorted alphabetically, if possible.
11291c8d237SDavid E. O'Brien.It
11337bfb9b3SBryan DreweryVariables are expanded with
11437bfb9b3SBryan Drewery.Sy {} ,
11537bfb9b3SBryan Drewerynot
11637bfb9b3SBryan Drewery.Sy () .
11737bfb9b3SBryan DrewerySuch as
11837bfb9b3SBryan Drewery.Va ${VARIABLE} .
11937bfb9b3SBryan Drewery.It
120ef91670aSDavid E. O'BrienDo not use
121ef91670aSDavid E. O'Brien.Ic +=
12291c8d237SDavid E. O'Briento set variables that are only set once
12391c8d237SDavid E. O'Brien(or to set variables for the first time).
12491c8d237SDavid E. O'Brien.It
125ef91670aSDavid E. O'BrienDo not use vertical whitespace in simple makefiles,
12691c8d237SDavid E. O'Brienbut do use it to group locally related things in more complex/longer ones.
12791c8d237SDavid E. O'Brien.It
12891c8d237SDavid E. O'Brien.Va WARNS
12991c8d237SDavid E. O'Briencomes before
13091c8d237SDavid E. O'Brien.Va CFLAGS ,
13191c8d237SDavid E. O'Brienas it is basically a
13291c8d237SDavid E. O'Brien.Va CFLAGS
13391c8d237SDavid E. O'Brienmodifier.
13491c8d237SDavid E. O'BrienIt comes before
13591c8d237SDavid E. O'Brien.Va CFLAGS
13691c8d237SDavid E. O'Brienrather than after
13791c8d237SDavid E. O'Brien.Va CFLAGS
13891c8d237SDavid E. O'Brienso it does not get lost in a sea of
13991c8d237SDavid E. O'Brien.Va CFLAGS
14091c8d237SDavid E. O'Brienstatements as
14191c8d237SDavid E. O'Brien.Va WARNS
14291c8d237SDavid E. O'Brienis an important thing.
143a250a461SDavid E. O'BrienThe usage of
144a250a461SDavid E. O'Brien.Va WARNS
145a250a461SDavid E. O'Brienis spelled
146e84d3134SRuslan Ermilov.Dq Li "WARNS?= " ,
1478979ef39SMike Pritchardso that it may be overridden on the command line or in
14808b91343SYaroslav Tykhiy.Xr make.conf 5 .
14991c8d237SDavid E. O'Brien.It
1507fa2f2a6SAlex Richardson.Dq Li "MK_WERROR=no"
151ef91670aSDavid E. O'Brienshould not be used,
152ef91670aSDavid E. O'Brienit defeats the purpose of
15391c8d237SDavid E. O'Brien.Va WARNS .
1547b5570bfSDavid E. O'BrienIt should only be used on the command line and in special circumstances.
15591c8d237SDavid E. O'Brien.It
15691c8d237SDavid E. O'Brien.Va CFLAGS
15791c8d237SDavid E. O'Brienis spelled
158ef91670aSDavid E. O'Brien.Dq Li "CFLAGS+= " .
15991c8d237SDavid E. O'Brien.It
160ef91670aSDavid E. O'BrienListing
161ef91670aSDavid E. O'Brien.Fl D Ns 's
162ef91670aSDavid E. O'Brienbefore
163ef91670aSDavid E. O'Brien.Fl I Ns 's
164ef91670aSDavid E. O'Brienin
16591c8d237SDavid E. O'Brien.Va CFLAGS
166ef91670aSDavid E. O'Brienis preferred for alphabetical ordering and to make
167ef91670aSDavid E. O'Brien.Fl D Ns 's
168ef91670aSDavid E. O'Brieneasier to see.
169ef91670aSDavid E. O'BrienThe
170ef91670aSDavid E. O'Brien.Fl D Ns 's
171ef91670aSDavid E. O'Brienoften affect conditional compilation,
172ef91670aSDavid E. O'Brienand
173ef91670aSDavid E. O'Brien.Fl I Ns 's
174ef91670aSDavid E. O'Brientend to be quite long.
175a250a461SDavid E. O'BrienSplit long
176a250a461SDavid E. O'Brien.Va CFLAGS
177a250a461SDavid E. O'Briensettings between the
178a250a461SDavid E. O'Brien.Fl D Ns 's
179a250a461SDavid E. O'Brienand
180a250a461SDavid E. O'Brien.Fl I Ns 's.
18191c8d237SDavid E. O'Brien.It
182ef91670aSDavid E. O'BrienDo not use GCCisms (such as
183ef91670aSDavid E. O'Brien.Fl g
184ef91670aSDavid E. O'Brienand
185ef91670aSDavid E. O'Brien.Fl Wall )
186ef91670aSDavid E. O'Brienin
18791c8d237SDavid E. O'Brien.Va CFLAGS .
18891c8d237SDavid E. O'Brien.It
189ef91670aSDavid E. O'BrienTypically, there is one
190ef91670aSDavid E. O'Brien.Tn ASCII
191ef91670aSDavid E. O'Brientab between
192ef91670aSDavid E. O'Brien.Va VAR Ns Ic =
19391c8d237SDavid E. O'Brienand the value in order to start the value in column 9.
194ef91670aSDavid E. O'BrienAn
195ef91670aSDavid E. O'Brien.Tn ASCII
196ef91670aSDavid E. O'Brienspace is allowed for variable names that extend beyond column 9.
197ef91670aSDavid E. O'BrienA lack of whitespace is also allowed for very long variable names.
19891c8d237SDavid E. O'Brien.It
199fe08efe6SRuslan Ermilov.Ic .include In bsd.*.mk
20091c8d237SDavid E. O'Briengoes last.
201a250a461SDavid E. O'Brien.It
202a250a461SDavid E. O'BrienDo not use anachronisms like
203a250a461SDavid E. O'Brien.Va $<
204a250a461SDavid E. O'Brienand
205a250a461SDavid E. O'Brien.Va $@ .
206a250a461SDavid E. O'BrienInstead use
2077b5570bfSDavid E. O'Brien.Va ${.IMPSRC}
208a250a461SDavid E. O'Brienor
2097b5570bfSDavid E. O'Brien.Va ${.ALLSRC}
210a250a461SDavid E. O'Brienand
2117b5570bfSDavid E. O'Brien.Va ${.TARGET} .
2129146ea4eSDavid E. O'Brien.It
2139146ea4eSDavid E. O'BrienTo not build the
214db9eea4dSDavid E. O'Brien.Dq foo
2159146ea4eSDavid E. O'Brienpart of the base system,
2169146ea4eSDavid E. O'Brienuse
2179146ea4eSDavid E. O'Brien.Va NO_FOO ,
2189146ea4eSDavid E. O'Briennot
2199146ea4eSDavid E. O'Brien.Va NOFOO .
2209146ea4eSDavid E. O'Brien.It
2219146ea4eSDavid E. O'BrienTo optionally build something in the base system,
2229146ea4eSDavid E. O'Brienspell the knob
2239146ea4eSDavid E. O'Brien.Va WITH_FOO
2249146ea4eSDavid E. O'Briennot
22540f3723dSDavid E. O'Brien.Va WANT_FOO
2269146ea4eSDavid E. O'Brienor
2279146ea4eSDavid E. O'Brien.Va USE_FOO .
228db9eea4dSDavid E. O'BrienThe latter are reserved for the
229db9eea4dSDavid E. O'Brien.Fx
230db9eea4dSDavid E. O'BrienPorts Collection.
2319146ea4eSDavid E. O'Brien.It
2329146ea4eSDavid E. O'BrienFor variables that are only checked with
233db9eea4dSDavid E. O'Brien.Fn defined ,
234db9eea4dSDavid E. O'Briendo not provide any fake value.
23591c8d237SDavid E. O'Brien.El
23691c8d237SDavid E. O'Brien.Pp
23791c8d237SDavid E. O'BrienThe desire to express a logical grouping often means not obeying some of the
23891c8d237SDavid E. O'Brienabove.
239b3eaeb0bSRuslan Ermilov.Sh EXAMPLES
240ef91670aSDavid E. O'BrienThe simplest program
241ef91670aSDavid E. O'Brien.Pa Makefile
242ef91670aSDavid E. O'Brienis:
243ef91670aSDavid E. O'Brien.Bd -literal -offset indent
24491c8d237SDavid E. O'BrienPROG=	foo
24591c8d237SDavid E. O'Brien
24691c8d237SDavid E. O'Brien\&.include <bsd.prog.mk>
247ef91670aSDavid E. O'Brien.Ed
24891c8d237SDavid E. O'Brien.Pp
249ef91670aSDavid E. O'BrienThe simplest library
250ef91670aSDavid E. O'Brien.Pa Makefile
251ef91670aSDavid E. O'Brienis:
252ef91670aSDavid E. O'Brien.Bd -literal -offset indent
25391c8d237SDavid E. O'BrienLIB=	foo
25491c8d237SDavid E. O'BrienSHLIB_MAJOR= 1
25591c8d237SDavid E. O'BrienMAN=	libfoo.3
25691c8d237SDavid E. O'BrienSRCS=	foo.c
25791c8d237SDavid E. O'Brien
25891c8d237SDavid E. O'Brien\&.include <bsd.lib.mk>
259ef91670aSDavid E. O'Brien.Ed
26091c8d237SDavid E. O'Brien.Sh SEE ALSO
261ef91670aSDavid E. O'Brien.Xr make 1 ,
26208b91343SYaroslav Tykhiy.Xr make.conf 5 ,
26391c8d237SDavid E. O'Brien.Xr style 9
26491c8d237SDavid E. O'Brien.Sh HISTORY
265*2322159aSDavid E. O'BrienThis manual page is inspired from the
26691c8d237SDavid E. O'Brien.Xr style 9
267*2322159aSDavid E. O'Brienmanual page and first appeared in
268*2322159aSDavid E. O'Brien.Fx 5.1 .
269*2322159aSDavid E. O'Brien.Sh AUTHORS
270*2322159aSDavid E. O'Brien.An David O'Brien Aq deo@NUXI.org
27191c8d237SDavid E. O'Brien.Sh BUGS
27291c8d237SDavid E. O'BrienThere are few hard and fast style rules here.
273ef91670aSDavid E. O'BrienThe style of many things is too dependent on the context of the whole makefile,
27491c8d237SDavid E. O'Brienor the lines surrounding it.
275