# 4.2.获取源代码

获取原始源代码（通常是压缩的 tarball 文件，**foo.tar.gz** 或 **foo.tar.bz2**），并将其复制到 `DISTDIR` 中。尽可能使用 *主流* 的源代码。

将变量 `MASTER_SITES` 设置为原始 tarball 存放的位置。对于大多数主流站点，**bsd.sites.mk** 中有快捷方式定义。如果可能的话，请使用这些站点及其相关定义，以避免在源代码中重复相同的信息。由于这些站点会随着时间的推移发生变化，因此如果不使用这些快捷方式，可能会给每个人带来维护上的噩梦。有关详细信息，请参见 [`MASTER_SITES`](https://docs.freebsd.org/en/books/porters-handbook/makefiles/#makefile-master_sites)。

如果没有一个 FTP/HTTP 站点与互联网连接良好，或者只能找到格式不标准的站点，请将源文件放在可靠的 FTP 或 HTTP 服务器上（例如，个人主页）。

如果找不到合适且可靠的地方来存放 distfile，我们可以将其“寄存”在 `ftp.FreeBSD.org` 上；然而，这种方法是最不推荐的。distfile 必须放在某个 `freefall` 账户的 **\~/public\_distfiles/** 目录下。请向提交该 Port 的人请求帮助。这个人还会将 `MASTER_SITES` 设置为 `LOCAL/username`，其中 `username` 是他们的 FreeBSD 集群登录名。

如果 Port 的 distfile 经常变化，而作者没有进行版本更新，请考虑将 distfile 放在个人主页上，并将其列为第一个 `MASTER_SITES`。尝试说服作者停止这样做；这确实有助于建立某种源代码管理。托管特定版本将防止用户遇到 `checksum mismatch` 错误，并减少我们 FTP 站点维护者的工作量。此外，如果一个 Port 只有一个主站点，建议将备份放在个人主页上，并将其列为第二个 `MASTER_SITES`。

如果 Port 需要额外的补丁，并且这些补丁可以从互联网下载，请同样将它们下载并放入 `DISTDIR`。即使这些补丁来自与主要源代码 tarball 不同的网站，也不需要担心，我们有办法处理这种情况（请参见下文对 [PATCHFILES](https://docs.freebsd.org/en/books/porters-handbook/makefiles/#porting-patchfiles) 的描述）。


---

# Agent Instructions: 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:

```
GET https://porters-handbook.bsdcn.org/di-4-zhang-fu-za-de-port/4.2.-huo-qu-yuan-dai-ma.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
