]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man5/style.Makefile.5
pf.conf.5: minor improvements
[FreeBSD/FreeBSD.git] / share / man / man5 / style.Makefile.5
1 .\" Copyright (c) 2002-2003 David O'Brien <obrien@FreeBSD.org>
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the author nor the names of any contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL DAVID O'BRIEN OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\" $FreeBSD$
29 .\"
30 .Dd November 18, 2021
31 .Dt STYLE.MAKEFILE 5
32 .Os
33 .Sh NAME
34 .Nm style.Makefile
35 .Nd
36 .Fx
37 .Pa Makefile
38 file style guide
39 .Sh DESCRIPTION
40 This file specifies the preferred style for makefiles in the
41 .Fx
42 source tree.
43 .Bl -bullet
44 .It
45 .Cm .PATH :
46 comes next if needed, and is spelled
47 .Dq Li ".PATH: " ,
48 with a single
49 .Tn ASCII
50 space after a colon.
51 Do not use the
52 .Va VPATH
53 variable.
54 .It
55 Special variables (i.e.,
56 .Va LIB , SRCS , MLINKS ,
57 etc.) are listed in order of
58 .Dq product ,
59 then building and installing a binary.
60 Special variables may also be listed in
61 .Dq build
62 order: i.e., ones for the primary program (or library) first.
63 The general
64 .Dq product
65 order is:
66 .Va PROG Ns / Ns Oo Va SH Oc Ns Va LIB Ns / Ns Va SCRIPTS
67 .Va FILES
68 .Va LINKS
69 .Oo Va NO_ Oc Ns Va MAN
70 .Va MLINKS
71 .Va INCS
72 .Va SRCS
73 .Va WARNS
74 .Va CSTD
75 .Va CFLAGS
76 .Va DPADD
77 .Va LDADD .
78 The general
79 .Dq build
80 order is:
81 .Va PROG Ns / Ns Oo Va SH Oc Ns Va LIB Ns / Ns Va SCRIPTS
82 .Va SRCS
83 .Va WARNS
84 .Va CSTD
85 .Va CFLAGS
86 .Va DPADD
87 .Va LDADD
88 .Va INCS
89 .Va FILES
90 .Va LINKS
91 .Oo Va NO_ Oc Ns Va MAN
92 .Va MLINKS .
93 .It
94 Omit
95 .Va SRCS
96 when using
97 .In bsd.prog.mk
98 and there is a single source file named the same as the
99 .Va PROG .
100 .It
101 Omit
102 .Va MAN
103 when using
104 .In bsd.prog.mk
105 and the manual page is named the same as the
106 .Va PROG ,
107 and is in section 1.
108 .It
109 All variable assignments are spelled
110 .Dq Va VAR Ns Ic = ,
111 i.e., no space between the variable name and the
112 .Ic = .
113 Keep values sorted alphabetically, if possible.
114 .It
115 Variables are expanded with
116 .Sy {} ,
117 not
118 .Sy () .
119 Such as
120 .Va ${VARIABLE} .
121 .It
122 Do not use
123 .Ic +=
124 to set variables that are only set once
125 (or to set variables for the first time).
126 .It
127 Do not use vertical whitespace in simple makefiles,
128 but do use it to group locally related things in more complex/longer ones.
129 .It
130 .Va WARNS
131 comes before
132 .Va CFLAGS ,
133 as it is basically a
134 .Va CFLAGS
135 modifier.
136 It comes before
137 .Va CFLAGS
138 rather than after
139 .Va CFLAGS
140 so it does not get lost in a sea of
141 .Va CFLAGS
142 statements as
143 .Va WARNS
144 is an important thing.
145 The usage of
146 .Va WARNS
147 is spelled
148 .Dq Li "WARNS?= " ,
149 so that it may be overridden on the command line or in
150 .Xr make.conf 5 .
151 .It
152 .Dq Li "MK_WERROR=no"
153 should not be used,
154 it defeats the purpose of
155 .Va WARNS .
156 It should only be used on the command line and in special circumstances.
157 .It
158 .Va CFLAGS
159 is spelled
160 .Dq Li "CFLAGS+= " .
161 .It
162 Listing
163 .Fl D Ns 's
164 before
165 .Fl I Ns 's
166 in
167 .Va CFLAGS
168 is preferred for alphabetical ordering and to make
169 .Fl D Ns 's
170 easier to see.
171 The
172 .Fl D Ns 's
173 often affect conditional compilation,
174 and
175 .Fl I Ns 's
176 tend to be quite long.
177 Split long
178 .Va CFLAGS
179 settings between the
180 .Fl D Ns 's
181 and
182 .Fl I Ns 's.
183 .It
184 Do not use GCCisms (such as
185 .Fl g
186 and
187 .Fl Wall )
188 in
189 .Va CFLAGS .
190 .It
191 Typically, there is one
192 .Tn ASCII
193 tab between
194 .Va VAR Ns Ic =
195 and the value in order to start the value in column 9.
196 An
197 .Tn ASCII
198 space is allowed for variable names that extend beyond column 9.
199 A lack of whitespace is also allowed for very long variable names.
200 .It
201 .Ic .include In bsd.*.mk
202 goes last.
203 .It
204 Do not use anachronisms like
205 .Va $<
206 and
207 .Va $@ .
208 Instead use
209 .Va ${.IMPSRC}
210 or
211 .Va ${.ALLSRC}
212 and
213 .Va ${.TARGET} .
214 .It
215 To not build the
216 .Dq foo
217 part of the base system,
218 use
219 .Va NO_FOO ,
220 not
221 .Va NOFOO .
222 .It
223 To optionally build something in the base system,
224 spell the knob
225 .Va WITH_FOO
226 not
227 .Va WANT_FOO
228 or
229 .Va USE_FOO .
230 The latter are reserved for the
231 .Fx
232 Ports Collection.
233 .It
234 For variables that are only checked with
235 .Fn defined ,
236 do not provide any fake value.
237 .El
238 .Pp
239 The desire to express a logical grouping often means not obeying some of the
240 above.
241 .Sh EXAMPLES
242 The simplest program
243 .Pa Makefile
244 is:
245 .Bd -literal -offset indent
246 # $FreeBSD\&$
247
248 PROG=   foo
249
250 \&.include <bsd.prog.mk>
251 .Ed
252 .Pp
253 The simplest library
254 .Pa Makefile
255 is:
256 .Bd -literal -offset indent
257 # $FreeBSD\&$
258
259 LIB=    foo
260 SHLIB_MAJOR= 1
261 MAN=    libfoo.3
262 SRCS=   foo.c
263
264 \&.include <bsd.lib.mk>
265 .Ed
266 .Sh SEE ALSO
267 .Xr make 1 ,
268 .Xr make.conf 5 ,
269 .Xr style 9
270 .Sh HISTORY
271 This manual page is inspired from the same source as
272 .Xr style 9
273 manual page in
274 .Fx .
275 .Sh BUGS
276 There are few hard and fast style rules here.
277 The style of many things is too dependent on the context of the whole makefile,
278 or the lines surrounding it.