2003-02-26 20:43:47 +00:00
|
|
|
.\" 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
|
2003-02-26 20:43:47 +00:00
|
|
|
.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
|
2003-02-26 20:43:47 +00:00
|
|
|
.Sh DESCRIPTION
|
2003-03-02 02:21:37 +00:00
|
|
|
This file specifies the preferred style for makefiles in the
|
2003-02-26 20:43:47 +00:00
|
|
|
.Fx
|
|
|
|
source tree.
|
2003-03-02 02:21:37 +00:00
|
|
|
.Bl -bullet
|
2003-02-26 20:43:47 +00:00
|
|
|
.It
|
2003-03-02 02:21:37 +00:00
|
|
|
All makefiles should have an SCM ID at the start of the file,
|
2003-02-26 20:43:47 +00:00
|
|
|
followed by a blank line.
|
|
|
|
.Bd -literal
|
2003-03-02 02:21:37 +00:00
|
|
|
# $FreeBSD\&$
|
2003-02-26 20:43:47 +00:00
|
|
|
|
|
|
|
.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.
|
2003-03-02 02:40:38 +00:00
|
|
|
Do not use the
|
|
|
|
.Va VPATH
|
|
|
|
variable.
|
2003-02-26 20:43:47 +00:00
|
|
|
.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 ,
|
2003-02-26 20:43:47 +00:00
|
|
|
then building and installing a binary.
|
2003-03-02 18:57:12 +00:00
|
|
|
Special variables may also be listed in
|
2003-03-02 02:51:40 +00:00
|
|
|
.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
|
2003-02-26 20:43:47 +00:00
|
|
|
.Va FILES
|
|
|
|
.Va LINKS
|
2003-03-02 02:21:37 +00:00
|
|
|
.Oo Va NO Oc Ns Va MAN
|
|
|
|
.Va MLINKS
|
2003-02-26 20:43:47 +00:00
|
|
|
.Va INCS
|
2003-03-02 02:21:37 +00:00
|
|
|
.Va SRCS
|
2003-02-26 20:43:47 +00:00
|
|
|
.Va WARNS
|
|
|
|
.Va CFLAGS
|
|
|
|
.Va DPADD
|
2003-03-02 02:21:37 +00:00
|
|
|
.Va LDADD .
|
2003-03-02 02:51:40 +00:00
|
|
|
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
|
2003-03-02 18:57:12 +00:00
|
|
|
.Va MLINKS .
|
2003-02-26 20:43:47 +00:00
|
|
|
.It
|
|
|
|
Omit
|
2003-03-02 02:21:37 +00:00
|
|
|
.Va SRCS
|
2003-02-26 20:43:47 +00:00
|
|
|
when using
|
2003-03-02 02:21:37 +00:00
|
|
|
.Aq Pa bsd.prog.mk
|
2003-02-26 20:43:47 +00:00
|
|
|
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 ,
|
2003-02-26 20:43:47 +00:00
|
|
|
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 = .
|
2003-02-26 20:43:47 +00:00
|
|
|
Keep values sorted alphabetically, if possible.
|
|
|
|
.It
|
2003-03-02 02:21:37 +00:00
|
|
|
Do not use
|
|
|
|
.Ic +=
|
2003-02-26 20:43:47 +00:00
|
|
|
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,
|
2003-02-26 20:43:47 +00:00
|
|
|
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.
|
2003-03-02 02:40:38 +00:00
|
|
|
The usage of
|
|
|
|
.Va WARNS
|
|
|
|
is spelled
|
|
|
|
.Dq Li "WARNS?= " .
|
2003-03-02 18:57:12 +00:00
|
|
|
so that it may be overriden on the command line or in
|
2003-03-02 02:40:38 +00:00
|
|
|
.Pa /etc/make.conf .
|
2003-02-26 20:43:47 +00:00
|
|
|
.It
|
2003-03-02 02:21:37 +00:00
|
|
|
.Dq Li "NO_WERROR= yes"
|
|
|
|
should not be used,
|
|
|
|
it defeats the purpose of
|
2003-02-26 20:43:47 +00:00
|
|
|
.Va WARNS .
|
2003-03-02 18:57:12 +00:00
|
|
|
It should only be used on the command line and in special circumstances.
|
2003-02-26 20:43:47 +00:00
|
|
|
.It
|
|
|
|
.Va CFLAGS
|
|
|
|
is spelled
|
2003-03-02 02:21:37 +00:00
|
|
|
.Dq Li "CFLAGS+= " .
|
2003-02-26 20:43:47 +00:00
|
|
|
.It
|
2003-03-02 02:21:37 +00:00
|
|
|
Listing
|
|
|
|
.Fl D Ns 's
|
|
|
|
before
|
|
|
|
.Fl I Ns 's
|
|
|
|
in
|
2003-02-26 20:43:47 +00:00
|
|
|
.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.
|
2003-03-02 02:40:38 +00:00
|
|
|
Split long
|
|
|
|
.Va CFLAGS
|
|
|
|
settings between the
|
|
|
|
.Fl D Ns 's
|
|
|
|
and
|
|
|
|
.Fl I Ns 's.
|
2003-02-26 20:43:47 +00:00
|
|
|
.It
|
2003-03-02 02:21:37 +00:00
|
|
|
Do not use GCCisms (such as
|
|
|
|
.Fl g
|
|
|
|
and
|
|
|
|
.Fl Wall )
|
|
|
|
in
|
2003-02-26 20:43:47 +00:00
|
|
|
.Va CFLAGS .
|
|
|
|
.It
|
2003-03-02 02:21:37 +00:00
|
|
|
Typically, there is one
|
|
|
|
.Tn ASCII
|
|
|
|
tab between
|
|
|
|
.Va VAR Ns Ic =
|
2003-02-26 20:43:47 +00:00
|
|
|
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.
|
2003-02-26 20:43:47 +00:00
|
|
|
.It
|
2003-03-02 02:21:37 +00:00
|
|
|
.Ic .include Aq Pa bsd.*.mk
|
2003-02-26 20:43:47 +00:00
|
|
|
goes last.
|
2003-03-02 02:40:38 +00:00
|
|
|
.It
|
|
|
|
Do not use anachronisms like
|
|
|
|
.Va $<
|
|
|
|
and
|
|
|
|
.Va $@ .
|
|
|
|
Instead use
|
2003-03-02 18:57:12 +00:00
|
|
|
.Va ${.IMPSRC}
|
2003-03-02 02:40:38 +00:00
|
|
|
or
|
2003-03-02 18:57:12 +00:00
|
|
|
.Va ${.ALLSRC}
|
2003-03-02 02:40:38 +00:00
|
|
|
and
|
2003-03-02 18:57:12 +00:00
|
|
|
.Va ${.TARGET} .
|
2003-02-26 20:43:47 +00:00
|
|
|
.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\&$
|
2003-02-26 20:43:47 +00:00
|
|
|
|
|
|
|
PROG= foo
|
|
|
|
|
|
|
|
\&.include <bsd.prog.mk>
|
2003-03-02 02:21:37 +00:00
|
|
|
.Ed
|
2003-02-26 20:43:47 +00:00
|
|
|
.Pp
|
2003-03-02 02:21:37 +00:00
|
|
|
The simplest library
|
|
|
|
.Pa Makefile
|
|
|
|
is:
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
# $FreeBSD\&$
|
2003-02-26 20:43:47 +00:00
|
|
|
|
|
|
|
LIB= foo
|
|
|
|
SHLIB_MAJOR= 1
|
|
|
|
MAN= libfoo.3
|
|
|
|
SRCS= foo.c
|
|
|
|
|
|
|
|
\&.include <bsd.lib.mk>
|
2003-03-02 02:21:37 +00:00
|
|
|
.Ed
|
2003-02-26 20:43:47 +00:00
|
|
|
.Sh SEE ALSO
|
2003-03-02 02:21:37 +00:00
|
|
|
.Xr make 1 ,
|
2003-02-26 20:43:47 +00:00
|
|
|
.Xr style 9
|
|
|
|
.Sh HISTORY
|
2003-03-02 02:21:37 +00:00
|
|
|
This manual page is inspired from the same source as
|
2003-02-26 20:43:47 +00:00
|
|
|
.Xr style 9
|
2003-03-02 02:21:37 +00:00
|
|
|
manual page in
|
2003-02-26 20:43:47 +00:00
|
|
|
.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,
|
2003-02-26 20:43:47 +00:00
|
|
|
or the lines surrounding it.
|