Chapter 14. A Sample Makefile

Table of Contents

Here is a sample Makefile that can be used to create a new port.

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. Refer to the chapter about testing to learn more about tools for linting, formatting, and checking the Makefile.

PORTNAME=	xdvi (1)
DISTVERSION=	18.2
CATEGORIES=	print
MASTER_SITES=	${MASTER_SITE_XCONTRIB} (2)
MASTER_SITE_SUBDIR=	applications
PKGNAMEPREFIX=	ja-
DISTNAME=	xdvi-pl18
EXTRACT_SUFX=	.tar.Z (3)

PATCH_SITES=	ftp://ftp.sra.co.jp/pub/X11/japanese/ (4)
PATCHFILES=	xdvi-18.patch1.gz xdvi-18.patch2.gz
PATCH_DIST_STRIP=	-p1 (5)

MAINTAINER=	asami@FreeBSD.org (6)
COMMENT=	DVI Previewer for the X Window System
WWW=		http://xdvi.sourceforge.net/

LICENSE=	BSD2CLAUSE (7)
LICENSE_FILE=	${WRKSRC}/LICENSE

RUN_DEPENDS=	gs:print/ghostscript (8)

USES=		gmake (9)

(10)
IS_INTERACTIVE=	yes (11)
WRKSRC=		${WRKDIR}/xdvi-new (12)
GNU_CONFIGURE=	yes (13)

(14)
OPTIONS_DEFINE=	DOCS EXAMPLES FOO
OPTIONS_DEFAULT=FOO
OPTIONS_SUB=	yes (15)

FOO_DESC=		Enable foo support
FOO_CONFIGURE_ENABLE=	foo

(16)
MY_FAVORITE_RESPONSE=	"yeah, right"

(17)
pre-fetch:
	i go fetch something, yeah

post-patch:
	i need to do something after patch, great

pre-install:
	and then some more stuff before installing, wow

.include <bsd.port.mk> (18)
1Section to describe the port itself and the master site — PORTNAME and PORTVERSION or the DISTVERSION* variables 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.
2Do not forget the trailing slash (/) if not using MASTER_SITE_* macros.
3Set this if the source is not in the standard ".tar.gz" form.
4Section for distributed patches — can be empty.
5If the distributed patches were not made relative to WRKSRC, this may need to be tweaked.
6Maintainer; 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 do not accept new ports that are assigned to "ports@FreeBSD.org".
7License — should not be empty.
8Dependencies — can be empty.
9If the port requires GNU make instead of the default FreeBSD make (make(1)) to build. For example, some X applications require xmkmf -a to run, in which case the port would need USES=imake.
10This section is for other standard bsd.port.mk variables that do not belong to any of the above.
11If the ports asks interactive questions during configure, build, install.
12If it extracts to a directory other than DISTNAME.
13If it requires a configure script generated by GNU autoconf to be run.
14This section is for handling ports options.
15Set OPTIONS_SUB if options will change the list of files in the plist.
16Non-standard variables to be used in the rules below.
17Special rules, in the order they are called by the ports framework.
18Finally, the epilogue.

Last modified on: July 23, 2025 by Mateusz Piotrowski