> 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-9-zhang-pkg/9.5.-shi-yong-subfiles-he-sublist.md).

# 9.5.使用 SUB\_FILES 和 SUB\_LIST

`SUB_FILES` 和 `SUB_LIST` 是用于在 Port 文件中动态插入值的工具，例如在 **pkg-message** 中插入安装的 `PREFIX`。

`SUB_FILES` 指定一个文件列表，这些文件会被自动修改。`SUB_FILES` 列表中的每个文件必须在 `FILESDIR` 中有对应的 **file.in** 文件。修改后的文件将创建在 **${WRKDIR}/file** 中。定义为 `USE_RC_SUBR` 值的文件会自动添加到 `SUB_FILES` 中。对于文件 **pkg-message**、**pkg-install** 和 **pkg-deinstall**，相应的 **Makefile** 变量会自动设置为指向处理过的版本。

`SUB_LIST` 是一组 `VAR=VALUE` 键值对。对于每一对，`SUB_FILES` 列出的每个文件中的 `%%VAR%%` 都会被替换为 `VALUE`。几个常见的键值对会自动定义：`PREFIX`、`LOCALBASE`、`DATADIR`、`DOCSDIR`、`EXAMPLESDIR`、`WWWDIR` 和 `ETCDIR`。任何以 `@comment` 开头并后跟空格的行，在变量替换后将从结果文件中删除。

以下示例在 **pkg-message** 中将 `%%ARCH%%` 替换为系统架构：

```makefile
SUB_FILES=	pkg-message
SUB_LIST=	ARCH=${ARCH}
```

注意：在这个例子中，**pkg-message.in** 必须存在于 `FILESDIR` 中。

一个良好的 **pkg-message.in** 示例：

```sh
Now it is time to configure this package.
Copy %%PREFIX%%/shared/examples/putsy/%%ARCH%%.conf into your home directory
as .putsy.conf and edit it.
```


---

# 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-9-zhang-pkg/9.5.-shi-yong-subfiles-he-sublist.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.
