Chapter 13. A Sample Makefile

Table of Contents
13.1. Order of Variables in Port Makefiles

Here is a sample Makefile that can be used to create a new port. Make sure to remove all the extra comments (ones between brackets).

The format shown is the recommended one for ordering variables, empty lines between sections, and so on. This format is designed so that the most important information is easy to locate. We recommend using portlint to check the Makefile.

[the header...just to make it easier for us to identify the ports.]
# $FreeBSD$
[ ^^^^^^^^^ This will be automatically replaced with RCS ID string by SVN
when it is committed to our repository.  If upgrading a port, do not alter
this line back to "$FreeBSD$".  SVN deals with it automatically.]

[section to describe the port itself and the master site - PORTNAME
 and PORTVERSION are always first, followed by CATEGORIES,
 and then MASTER_SITES, which can be followed by MASTER_SITE_SUBDIR.
 PKGNAMEPREFIX and PKGNAMESUFFIX, if needed, will be after that.
 Then comes DISTNAME, EXTRACT_SUFX and/or DISTFILES, and then
 EXTRACT_ONLY, as necessary.]
[do not forget the trailing slash ("/")!
 if not using MASTER_SITE_* macros]
MASTER_SITE_SUBDIR=	applications
DISTNAME=	xdvi-pl18
[set this if the source is not in the standard ".tar.gz" form]

[section for distributed patches -- can be empty]
PATCHFILES=	xdvi-18.patch1.gz xdvi-18.patch2.gz

[maintainer; *mandatory*!  This is the person who is volunteering to
 handle port updates, build breakages, and to whom a users can direct
 questions and bug reports.  To keep the quality of the Ports Collection
 as high as possible, we no longer accept new ports that are assigned to
COMMENT=	DVI Previewer for the X Window System

[license -- should not be empty]

[dependencies -- can be empty]
RUN_DEPENDS=	gs:print/ghostscript

[this section is for other standard variables that do not
 belong to any of the above]
[If it asks questions during configure, build, install...]
[If it extracts to a directory other than ${DISTNAME}...]
WRKSRC=		${WRKDIR}/xdvi-new
[If the distributed patches were not made relative to ${WRKSRC},
 this may need to be tweaked]
[If it requires a "configure" script generated by GNU autoconf to be run]
[If it requires GNU make, not /usr/bin/make, to build...]
USES= gmake
[If it is an X application and requires "xmkmf -a" to be run...]
USES= imake
[et cetera.]

[non-standard variables to be used in the rules below]

[then the special rules, in the order they are called]
	i go fetch something, yeah

	i need to do something after patch, great

	and then some more stuff before installing, wow

[and then the epilogue]

.include <>

13.1. Order of Variables in Port Makefiles

The first sections of the Makefile must always come in the same order. This standard makes it so everyone can easily read any port without having to search for variables in a random order.

The first line of a Makefile is always a comment containing the Subversion version control ID, followed by an empty line. In new ports, it looks like this:

# $FreeBSD$

In existing ports, Subversion has expanded it to look like this:

# $FreeBSD: head/ports-mgmt/pkg/Makefile 437007 2017-03-26 21:25:47Z bapt $


The sections and variables described here are mandatory in a ordinary port. In a slave port, many sections variables and can be skipped.


Each following block must be separated from the previous block by a single blank line.

In the following blocks, only set the variables that are required by the port. Define these variables in the order they are shown here.

13.1.1. PORTNAME Block

This block is the most important. It defines the port name, version, distribution file location, and category. The variables must be in this order:


Only one of PORTVERSION and DISTVERSION can be used.

13.1.2. PATCHFILES Block

This block is optional. The variables are:

13.1.3. MAINTAINER Block

This block is mandatory. The variables are:

13.1.4. LICENSE Block

This block is optional, although it is highly recommended. The variables are:

If there are multiple licenses, sort the different LICENSE_VAR_NAME variables by license name.

13.1.5. Generic BROKEN/IGNORE/DEPRECATED Messages

This block is optional. The variables are:


BROKEN* and IGNORE* can be any generic variables, for example, IGNORE_amd64, BROKEN_FreeBSD_10, BROKEN_SSL, etc.

If the port is marked BROKEN when some conditions are met, and such conditions can only be tested after including or, then those variables should be set later, in Section 13.1.9, “The Rest of the Variables”.

13.1.6. The Dependencies Block

This block is optional. The variables are:

13.1.7. USES and USE_x

Start this section with defining USES, and then possible USE_x.

Keep related variables close together. For example, if using USE_GITHUB, always put the GH_* variables right after it.

13.1.8. Options

If the port uses the options framework, define OPTIONS_DEFINE and OPTIONS_DEFAULT first, then the other OPTIONS_* variables first, then the *_DESC descriptions, then the options helpers. Try and sort all of those alphabetically.

13.1.9. The Rest of the Variables

And then, the rest of the variables that are not mentioned in the previous blocks.

13.1.10. The Targets

After all the variables are defined, the optional make(1) targets can be defined. Keep pre-* before post-* and in the same order as the different stages run:

  • fetch

  • extract

  • patch

  • configure

  • build

  • install

  • test

All FreeBSD documents are available for download at

Questions that are not answered by the documentation may be sent to <>.
Send questions about this document to <>.