> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/porters-handbook/di-14-zhang-yi-ge-shi-li-makefile/di-14-zhang-makefile-shi-li.md).

# 第 14 章 一个示例 Makefile

这里是一个可以用来创建新 Port 的 **Makefile** 示例。

所示格式是在变量排序、节间空行等方面的推荐格式。这种格式旨在让最重要的信息易于查找。关于 lint、格式化和检查 **Makefile** 的工具的更多信息，请参阅测试章节。

```sh
[描述 Port 本身和主站的部分 - PORTNAME 和 PORTVERSION 或 DISTVERSION* 变量总是放在第一位，接着是 CATEGORIES，然后是 MASTER_SITES，后面可以跟 MASTER_SITE_SUBDIR。如果需要，PKGNAMEPREFIX 和 PKGNAMESUFFIX 会排在后面。然后是 DISTNAME，EXTRACT_SUFX 和/或 DISTFILES，然后根据需要是 EXTRACT_ONLY。]
PORTNAME=	xdvi
DISTVERSION=	18.2
CATEGORIES=	print
[如果没有使用 MASTER_SITE_* 宏，不要忘记尾部的斜杠（/）！]
MASTER_SITES=	${MASTER_SITE_XCONTRIB}
MASTER_SITE_SUBDIR=	applications
PKGNAMEPREFIX=	ja-
DISTNAME=	xdvi-pl18
[如果源代码不是标准的 ".tar.gz" 格式，设置此项]
EXTRACT_SUFX=	.tar.Z

[分发的补丁部分 -- 可以为空]
PATCH_SITES=	ftp://ftp.sra.co.jp/pub/X11/japanese/
PATCHFILES=	xdvi-18.patch1.gz xdvi-18.patch2.gz
[如果分发的补丁不是相对于 WRKSRC 制作的，可能需要调整此项]
PATCH_DIST_STRIP=	-p1

[维护者；*必需的*！这是自愿处理 Port 更新和构建中断，并接收用户问题与错误报告的人。为了尽可能保持 Ports Collection 的高质量，我们不接受将新 Port 分配给 "ports@FreeBSD.org"。]
MAINTAINER=	asami@FreeBSD.org
COMMENT=	DVI Previewer for the X Window System
WWW=		http://xdvi.sourceforge.net/

[许可证 -- 不应为空]
LICENSE=	BSD2CLAUSE
LICENSE_FILE=	${WRKSRC}/LICENSE

[依赖关系 -- 可以为空]
RUN_DEPENDS=	gs:print/ghostscript

[如果 Port 需要 GNU make 而不是默认的 FreeBSD make（make(1)）来构建。例如，某些 X 应用程序需要运行 xmkmf -a，在这种情况下 Port 需要 USES=imake。]
USES=		gmake

[此部分用于其他不属于上述任何类别的标准 bsd.port.mk 变量]
[如果在配置、构建、安装过程中会询问问题]
IS_INTERACTIVE=	yes
[如果解压到与 DISTNAME 不同的目录]
WRKSRC=		${WRKDIR}/xdvi-new
[如果需要运行由 GNU autoconf 生成的 "configure" 脚本]
GNU_CONFIGURE=	yes

[此部分用于处理 Port 选项]
OPTIONS_DEFINE=	DOCS EXAMPLES FOO
OPTIONS_DEFAULT=FOO
[如果选项会更改 plist 中的文件列表，设置 OPTIONS_SUB]
OPTIONS_SUB=	yes

FOO_DESC=		Enable foo support
FOO_CONFIGURE_ENABLE=	foo

[用于下面规则中的非标准变量]
MY_FAVORITE_RESPONSE=	"yeah, right"

[特殊规则，按 Ports 框架调用的顺序排列]
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>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/porters-handbook/di-14-zhang-yi-ge-shi-li-makefile/di-14-zhang-makefile-shi-li.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
