freebsd-skq/share/man/man5/style.Makefile.5

253 lines
5.3 KiB
Groff
Raw Normal View History

.\" Copyright (c) 2002-2003 David O'Brien <obrien@FreeBSD.org>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the author nor the names of any contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL DAVID O'BRIEN OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
2003-03-02 02:21:37 +00:00
.Dd February 28, 2003
.Dt STYLE.MAKEFILE 5
.Os
.Sh NAME
.Nm style.Makefile
2003-03-02 02:21:37 +00:00
.Nd
.Fx
.Pa Makefile
file style guide
.Sh DESCRIPTION
2003-03-02 02:21:37 +00:00
This file specifies the preferred style for makefiles in the
.Fx
source tree.
2003-03-02 02:21:37 +00:00
.Bl -bullet
.It
2003-03-02 02:21:37 +00:00
All makefiles should have an SCM ID at the start of the file,
followed by a blank line.
.Bd -literal
2003-03-02 02:21:37 +00:00
# $FreeBSD\&$
.Ed
.It
2003-03-02 02:21:37 +00:00
.Cm .PATH :
comes next if needed, and is spelled
.Dq Li ".PATH: " ,
with a single
.Tn ASCII
space after a colon.
Do not use the
.Va VPATH
variable.
.It
2003-03-02 02:21:37 +00:00
Special variables (i.e.,
.Va LIB , SRCS , MLINKS ,
etc.) are listed in order of
.Dq product ,
then building and installing a binary.
Special variables may also be listed in
.Dq build
order: i.e., ones for the primary program (or library) first.
The general
.Dq product
order is:
2003-03-02 02:21:37 +00:00
.Va PROG Ns / Ns Va LIB Ns / Ns Va SCRIPT
.Va FILES
.Va LINKS
2003-03-02 02:21:37 +00:00
.Oo Va NO Oc Ns Va MAN
.Va MLINKS
.Va INCS
2003-03-02 02:21:37 +00:00
.Va SRCS
.Va WARNS
.Va CFLAGS
.Va DPADD
2003-03-02 02:21:37 +00:00
.Va LDADD .
The general
.Dq build
order is:
.Va PROG Ns / Ns Va LIB Ns / Ns Va SCRIPT
.Va SRCS
.Va WARNS
.Va CFLAGS
.Va DPADD
.Va LDADD
.Va INCS
.Va FILES
.Va LINKS
.Oo Va NO Oc Ns Va MAN
.Va MLINKS .
.It
Omit
2003-03-02 02:21:37 +00:00
.Va SRCS
when using
2003-03-02 02:21:37 +00:00
.Aq Pa bsd.prog.mk
and there is a single source file named the same as the
.Va PROG .
.It
Omit
.Va MAN
when using
2003-03-02 02:21:37 +00:00
.Aq Pa bsd.prog.mk
and the manual page is named the same as the
.Va PROG ,
and is in section 1.
.It
2003-03-02 02:21:37 +00:00
All variable assignments are spelled
.Dq Va VAR Ns Ic = ,
i.e., no space between the variable name and the
.Ic = .
Keep values sorted alphabetically, if possible.
.It
2003-03-02 02:21:37 +00:00
Do not use
.Ic +=
to set variables that are only set once
(or to set variables for the first time).
.It
2003-03-02 02:21:37 +00:00
Do not use vertical whitespace in simple makefiles,
but do use it to group locally related things in more complex/longer ones.
.It
.Va WARNS
comes before
.Va CFLAGS ,
as it is basically a
.Va CFLAGS
modifier.
It comes before
.Va CFLAGS
rather than after
.Va CFLAGS
so it does not get lost in a sea of
.Va CFLAGS
statements as
.Va WARNS
is an important thing.
The usage of
.Va WARNS
is spelled
.Dq Li "WARNS?= " .
so that it may be overriden on the command line or in
.Pa /etc/make.conf .
.It
2003-03-02 02:21:37 +00:00
.Dq Li "NO_WERROR= yes"
should not be used,
it defeats the purpose of
.Va WARNS .
It should only be used on the command line and in special circumstances.
.It
.Va CFLAGS
is spelled
2003-03-02 02:21:37 +00:00
.Dq Li "CFLAGS+= " .
.It
2003-03-02 02:21:37 +00:00
Listing
.Fl D Ns 's
before
.Fl I Ns 's
in
.Va CFLAGS
2003-03-02 02:21:37 +00:00
is preferred for alphabetical ordering and to make
.Fl D Ns 's
easier to see.
The
.Fl D Ns 's
often affect conditional compilation,
and
.Fl I Ns 's
tend to be quite long.
Split long
.Va CFLAGS
settings between the
.Fl D Ns 's
and
.Fl I Ns 's.
.It
2003-03-02 02:21:37 +00:00
Do not use GCCisms (such as
.Fl g
and
.Fl Wall )
in
.Va CFLAGS .
.It
2003-03-02 02:21:37 +00:00
Typically, there is one
.Tn ASCII
tab between
.Va VAR Ns Ic =
and the value in order to start the value in column 9.
2003-03-02 02:21:37 +00:00
An
.Tn ASCII
space is allowed for variable names that extend beyond column 9.
A lack of whitespace is also allowed for very long variable names.
.It
2003-03-02 02:21:37 +00:00
.Ic .include Aq Pa bsd.*.mk
goes last.
.It
Do not use anachronisms like
.Va $<
and
.Va $@ .
Instead use
.Va ${.IMPSRC}
or
.Va ${.ALLSRC}
and
.Va ${.TARGET} .
.El
.Pp
The desire to express a logical grouping often means not obeying some of the
above.
2003-03-02 02:21:37 +00:00
.Sh EXAMPLE
The simplest program
.Pa Makefile
is:
.Bd -literal -offset indent
# $FreeBSD\&$
PROG= foo
\&.include <bsd.prog.mk>
2003-03-02 02:21:37 +00:00
.Ed
.Pp
2003-03-02 02:21:37 +00:00
The simplest library
.Pa Makefile
is:
.Bd -literal -offset indent
# $FreeBSD\&$
LIB= foo
SHLIB_MAJOR= 1
MAN= libfoo.3
SRCS= foo.c
\&.include <bsd.lib.mk>
2003-03-02 02:21:37 +00:00
.Ed
.Sh SEE ALSO
2003-03-02 02:21:37 +00:00
.Xr make 1 ,
.Xr style 9
.Sh HISTORY
2003-03-02 02:21:37 +00:00
This manual page is inspired from the same source as
.Xr style 9
2003-03-02 02:21:37 +00:00
manual page in
.Fx .
.Sh BUGS
There are few hard and fast style rules here.
2003-03-02 02:21:37 +00:00
The style of many things is too dependent on the context of the whole makefile,
or the lines surrounding it.