> 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-3-zhang-jian-dan-de-port/3.1.-bian-xie-makefile.md).

# 3.1.编写 Makefile

本节说明了如何快速创建新 Port。对于那些快速方法不够充分的应用程序，完整的“慢速移植”过程在 [慢速移植](https://docs.freebsd.org/en/books/porters-handbook/slow-porting/#slow-porting) 中有详细说明。

首先，获取原始的 tarball 文件并将其放入 `DISTDIR`，默认路径为 **/usr/ports/distfiles**。

> **注意**
>
> 这些步骤假设软件可以开箱即用编译运行。换句话说，应用程序在 FreeBSD 系统上运行时完全不需要修改。如果需要修改，请参考 [慢速移植](https://docs.freebsd.org/en/books/porters-handbook/slow-porting/#slow-porting)。

> **注意**
>
> 建议在进行移植之前，在 **/etc/make.conf** 中设置 [make(1)](https://man.freebsd.org/cgi/man.cgi?query=make\&sektion=1\&format=html) 变量 `DEVELOPER`。
>
> ```sh
> # echo DEVELOPER=yes >> /etc/make.conf
> ```
>
> 此设置启用“开发者模式”，该模式会显示弃用警告，并在调用 `make` 时激活一些额外的质量检查。

***

**Makefile** 的最简版本看起来如下所示：

```makefile
PORTNAME=	oneko
DISTVERSION=	1.1b
CATEGORIES=	games
MASTER_SITES=	ftp://ftp.rediris.es/sites/ftp.freebsd.org/pub/FreeBSD/

MAINTAINER=	youremail@example.com
COMMENT=	Cat chasing a mouse all over the screen
WWW=		http://www.daidouji.com/oneko/

.include <bsd.port.mk>
```

尝试理解它。更详细的示例请参见 [示例 Makefile](https://docs.freebsd.org/en/books/porters-handbook/porting-samplem/#porting-samplem) 部分。


---

# 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-3-zhang-jian-dan-de-port/3.1.-bian-xie-makefile.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.
