xref: /freebsd/share/man/man5/style.Makefile.5 (revision 8979ef39014e4563787f62f1dd41fbad73865da7)
191c8d237SDavid E. O'Brien.\" Copyright (c) 2002-2003 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.\"
2891c8d237SDavid E. O'Brien.\" $FreeBSD$
2991c8d237SDavid E. O'Brien.\"
30ef91670aSDavid E. O'Brien.Dd February 28, 2003
3191c8d237SDavid E. O'Brien.Dt STYLE.MAKEFILE 5
3291c8d237SDavid E. O'Brien.Os
3391c8d237SDavid E. O'Brien.Sh NAME
3491c8d237SDavid E. O'Brien.Nm style.Makefile
35ef91670aSDavid E. O'Brien.Nd
36ef91670aSDavid E. O'Brien.Fx
37ef91670aSDavid E. O'Brien.Pa Makefile
38ef91670aSDavid E. O'Brienfile style guide
3991c8d237SDavid E. O'Brien.Sh DESCRIPTION
40ef91670aSDavid E. O'BrienThis file specifies the preferred style for makefiles in the
4191c8d237SDavid E. O'Brien.Fx
4291c8d237SDavid E. O'Briensource tree.
43ef91670aSDavid E. O'Brien.Bl -bullet
4491c8d237SDavid E. O'Brien.It
45ef91670aSDavid E. O'BrienAll makefiles should have an SCM ID at the start of the file,
4691c8d237SDavid E. O'Brienfollowed by a blank line.
4791c8d237SDavid E. O'Brien.Bd -literal
48ef91670aSDavid E. O'Brien# $FreeBSD\&$
4991c8d237SDavid E. O'Brien
5091c8d237SDavid E. O'Brien.Ed
5191c8d237SDavid E. O'Brien.It
52ef91670aSDavid E. O'Brien.Cm .PATH :
53ef91670aSDavid E. O'Briencomes next if needed, and is spelled
54ef91670aSDavid E. O'Brien.Dq Li ".PATH: " ,
55ef91670aSDavid E. O'Brienwith a single
56ef91670aSDavid E. O'Brien.Tn ASCII
57ef91670aSDavid E. O'Brienspace after a colon.
58a250a461SDavid E. O'BrienDo not use the
59a250a461SDavid E. O'Brien.Va VPATH
60a250a461SDavid E. O'Brienvariable.
6191c8d237SDavid E. O'Brien.It
62ef91670aSDavid E. O'BrienSpecial variables (i.e.,
63ef91670aSDavid E. O'Brien.Va LIB , SRCS , MLINKS ,
64ef91670aSDavid E. O'Brienetc.) are listed in order of
65ef91670aSDavid E. O'Brien.Dq product ,
6691c8d237SDavid E. O'Brienthen building and installing a binary.
677b5570bfSDavid E. O'BrienSpecial variables may also be listed in
68ed403545SDavid E. O'Brien.Dq build
69ed403545SDavid E. O'Brienorder: i.e., ones for the primary program (or library) first.
70ed403545SDavid E. O'BrienThe general
71ed403545SDavid E. O'Brien.Dq product
72ed403545SDavid E. O'Brienorder is:
73b37af785SBruce Evans.Va PROG Ns / Ns Oo Va SH Oc Ns Va LIB Ns / Ns Va SCRIPTS
7491c8d237SDavid E. O'Brien.Va FILES
7591c8d237SDavid E. O'Brien.Va LINKS
76ef91670aSDavid E. O'Brien.Oo Va NO Oc Ns Va MAN
77ef91670aSDavid E. O'Brien.Va MLINKS
7891c8d237SDavid E. O'Brien.Va INCS
79ef91670aSDavid E. O'Brien.Va SRCS
8091c8d237SDavid E. O'Brien.Va WARNS
8191c8d237SDavid E. O'Brien.Va CFLAGS
8291c8d237SDavid E. O'Brien.Va DPADD
83ef91670aSDavid E. O'Brien.Va LDADD .
84ed403545SDavid E. O'BrienThe general
85ed403545SDavid E. O'Brien.Dq build
86ed403545SDavid E. O'Brienorder is:
87b37af785SBruce Evans.Va PROG Ns / Ns Oo Va SH Oc Ns Va LIB Ns / Ns Va SCRIPTS
88ed403545SDavid E. O'Brien.Va SRCS
89ed403545SDavid E. O'Brien.Va WARNS
90ed403545SDavid E. O'Brien.Va CFLAGS
91ed403545SDavid E. O'Brien.Va DPADD
92ed403545SDavid E. O'Brien.Va LDADD
93ed403545SDavid E. O'Brien.Va INCS
94ed403545SDavid E. O'Brien.Va FILES
95ed403545SDavid E. O'Brien.Va LINKS
96ed403545SDavid E. O'Brien.Oo Va NO Oc Ns Va MAN
97ed403545SDavid E. O'Brien.Va MLINKS .
9891c8d237SDavid E. O'Brien.It
9991c8d237SDavid E. O'BrienOmit
100ef91670aSDavid E. O'Brien.Va SRCS
10191c8d237SDavid E. O'Brienwhen using
102fe08efe6SRuslan Ermilov.In bsd.prog.mk
10391c8d237SDavid E. O'Brienand there is a single source file named the same as the
10491c8d237SDavid E. O'Brien.Va PROG .
10591c8d237SDavid E. O'Brien.It
10691c8d237SDavid E. O'BrienOmit
10791c8d237SDavid E. O'Brien.Va MAN
10891c8d237SDavid E. O'Brienwhen using
109fe08efe6SRuslan Ermilov.In bsd.prog.mk
110ef91670aSDavid E. O'Brienand the manual page is named the same as the
111ef91670aSDavid E. O'Brien.Va PROG ,
11291c8d237SDavid E. O'Brienand is in section 1.
11391c8d237SDavid E. O'Brien.It
114ef91670aSDavid E. O'BrienAll variable assignments are spelled
115ef91670aSDavid E. O'Brien.Dq Va VAR Ns Ic = ,
116ef91670aSDavid E. O'Brieni.e., no space between the variable name and the
117ef91670aSDavid E. O'Brien.Ic = .
11891c8d237SDavid E. O'BrienKeep values sorted alphabetically, if possible.
11991c8d237SDavid E. O'Brien.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
148a250a461SDavid E. O'Brien.Pa /etc/make.conf .
14991c8d237SDavid E. O'Brien.It
150ef91670aSDavid E. O'Brien.Dq Li "NO_WERROR= yes"
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} .
21291c8d237SDavid E. O'Brien.El
21391c8d237SDavid E. O'Brien.Pp
21491c8d237SDavid E. O'BrienThe desire to express a logical grouping often means not obeying some of the
21591c8d237SDavid E. O'Brienabove.
216b3eaeb0bSRuslan Ermilov.Sh EXAMPLES
217ef91670aSDavid E. O'BrienThe simplest program
218ef91670aSDavid E. O'Brien.Pa Makefile
219ef91670aSDavid E. O'Brienis:
220ef91670aSDavid E. O'Brien.Bd -literal -offset indent
221ef91670aSDavid E. O'Brien# $FreeBSD\&$
22291c8d237SDavid E. O'Brien
22391c8d237SDavid E. O'BrienPROG=	foo
22491c8d237SDavid E. O'Brien
22591c8d237SDavid E. O'Brien\&.include <bsd.prog.mk>
226ef91670aSDavid E. O'Brien.Ed
22791c8d237SDavid E. O'Brien.Pp
228ef91670aSDavid E. O'BrienThe simplest library
229ef91670aSDavid E. O'Brien.Pa Makefile
230ef91670aSDavid E. O'Brienis:
231ef91670aSDavid E. O'Brien.Bd -literal -offset indent
232ef91670aSDavid E. O'Brien# $FreeBSD\&$
23391c8d237SDavid E. O'Brien
23491c8d237SDavid E. O'BrienLIB=	foo
23591c8d237SDavid E. O'BrienSHLIB_MAJOR= 1
23691c8d237SDavid E. O'BrienMAN=	libfoo.3
23791c8d237SDavid E. O'BrienSRCS=	foo.c
23891c8d237SDavid E. O'Brien
23991c8d237SDavid E. O'Brien\&.include <bsd.lib.mk>
240ef91670aSDavid E. O'Brien.Ed
24191c8d237SDavid E. O'Brien.Sh SEE ALSO
242ef91670aSDavid E. O'Brien.Xr make 1 ,
24391c8d237SDavid E. O'Brien.Xr style 9
24491c8d237SDavid E. O'Brien.Sh HISTORY
245ef91670aSDavid E. O'BrienThis manual page is inspired from the same source as
24691c8d237SDavid E. O'Brien.Xr style 9
247ef91670aSDavid E. O'Brienmanual page in
24891c8d237SDavid E. O'Brien.Fx .
24991c8d237SDavid E. O'Brien.Sh BUGS
25091c8d237SDavid E. O'BrienThere are few hard and fast style rules here.
251ef91670aSDavid E. O'BrienThe style of many things is too dependent on the context of the whole makefile,
25291c8d237SDavid E. O'Brienor the lines surrounding it.
253