> 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/port/di-8-zhang-gao-ji-pkgplist-shi-jian/8.1.-gen-ju-make-bian-liang-dui-pkgplist-jin-hang-xiu-gai.md).

# 8.1.根据 make 变量对 pkg-plist 进行修改

某些 Port，尤其是以 `p5-` 开头的 Port，需要根据配置的选项（或 `p5-` Port 中 `perl` 的版本）更改其 **pkg-plist**。为简化此操作，**pkg-plist** 中出现的 `%%OSREL%%`、`%%PERL_VER%%` 和 `%%PERL_VERSION%%` 会被自动替换为适当的值。`%%OSREL%%` 的值是操作系统的数字版本（例如 `4.9`）；`%%PERL_VERSION%%` 和 `%%PERL_VER%%` 是 `perl` 的完整版本号（例如 `5.8.9`）。还有其他一些与 Port 文档文件相关的 `%%_VARS_%%` 替换项，在[相关章节](https://docs.freebsd.org/en/books/porters-handbook/makefiles/#install-documentation)中有说明。

要进行自定义替换，可以在 **Makefile** 中设置 `PLIST_SUB` 为 *VAR=VALUE* 形式的列表，**pkg-plist** 中出现的 `%%_VAR_%%` 就会被替换为 *VALUE*。

例如，如果一个 Port 在按版本划分的子目录中安装了多个文件，可以使用占位符表示版本号，这样 Port 升级时就无需每次都重新生成 **pkg-plist**。可以这样设置：

```makefile
OCTAVE_VERSION=	${PORTREVISION}
PLIST_SUB=	OCTAVE_VERSION=${OCTAVE_VERSION}
```

然后在 **pkg-plist** 中使用 `%%OCTAVE_VERSION%%` 来代表版本号出现的位置。这样当 Port 升级时，就无需编辑数十（在某些情况下，数百）行 **pkg-plist**。

如果文件的安装取决于 Port 的选项设置，则常见的处理方法是在 **pkg-plist** 行前加上 `%%OPT%%`（表示启用该选项时需要安装该文件），或 `%%NO_OPT%%`（表示禁用该选项时需要安装该文件），并在 **Makefile** 中添加 `OPTIONS_SUB=yes`。详见 [`OPTIONS_SUB`](https://docs.freebsd.org/en/books/porters-handbook/makefiles/#options_sub)。

例如，如果有些文件只在启用了 `X11` 选项时才安装，并且 **Makefile** 中有：

```makefile
OPTIONS_DEFINE=	X11
OPTIONS_SUB=	yes
```

则在 **pkg-plist** 中，应在仅在启用该选项时才安装的行前加上 `%%X11%%`，例如：

```sh
%%X11%%bin/foo-gui
```

这种替换是在 `pre-install` 和 `do-install` 目标之间完成的，通过读取 **PLIST** 并写入 **TMPPLIST**（默认为 **WRKDIR/.PLIST.mktmp**）。因此，如果 Port 是动态构建 **PLIST**，则必须在 `pre-install` 或之前完成此操作。如果需要修改生成后的文件，应在 `post-install` 中对 **TMPPLIST** 文件进行操作。

另一种修改 Port 软件包列表的方式是设置变量 `PLIST_FILES` 和 `PLIST_DIRS`。它们的值被视为路径列表，将连同 **PLIST** 内容一并写入 **TMPPLIST**。尽管这些名称同样支持 `%%_VAR_%%` 替换，但建议直接使用 `${_VAR_}`。除此之外，`PLIST_FILES` 中的名称会原样出现在最终的软件包列表中，而 `PLIST_DIRS` 中的名称前会加上 `@dir`。这两个变量必须在写入 **TMPPLIST** 之前设置，也就是要在 `pre-install` 或更早的时候设置。

有时，仅使用 `OPTIONS_SUB` 并不够。在这些情况下，可以在 **Makefile** 的 `PLIST_SUB` 中为某个特定 *TAG* 设置特殊值 `@comment`，从而使打包工具忽略对应的行。例如，某些文件只在启用了 `X11` 且架构为 `i386` 时才会被安装，可以这样设置：

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

.if ${PORT_OPTIONS:MX11} && ${ARCH} == "i386"
PLIST_SUB+=	X11I386=""
.else
PLIST_SUB+=	X11I386="@comment "
.endif
```


---

# 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/port/di-8-zhang-gao-ji-pkgplist-shi-jian/8.1.-gen-ju-make-bian-liang-dui-pkgplist-jin-hang-xiu-gai.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.
