# 8.5.自动创建软件包列表

首先，确保 Port 几近完工，仅缺失 **pkg-plist**。运行 `make makeplist` 会显示 **pkg-plist** 的示例。`makeplist` 的输出必须仔细检查其正确性，因为它会自动猜测一些内容，可能会出错。

用户配置文件应该安装为 **filename.sample**，如 [Configuration Files](https://docs.freebsd.org/en/books/porters-handbook/plist/#plist-config) 中所述。**info/dir** 不能列出，并且必须按照 [info files](https://docs.freebsd.org/en/books/porters-handbook/makefiles/#makefile-info) 部分的说明添加适当的 **install-info** 行。Port 安装的任何库必须按 [shared libraries](https://docs.freebsd.org/en/books/porters-handbook/special/#porting-shlibs) 部分的说明列出。

### 8.5.1. 使用正则表达式扩展 `PLIST_SUB`

有时要替换的字符串需要非常具体，以避免不必要的替换。这是一个常见的问题，特别是对于较短的值。

为了解决这个问题，可以为每个 `PLACEHOLDER=value` 设置 `PLACEHOLDER_regex=regex`，其中 `regex` 部分会更精确地匹配 *value*。

**示例 1. 使用正则表达式的 PLIST\_SUB**

Perl Port 可以在特定的树中安装依赖于架构的文件。在 FreeBSD 上，为了简化 Port 移植，这个树叫做 `mach`。例如，一个安装文件路径中包含 `mach` 的 Port，可能会错误地替换路径字符串中的一部分。考虑以下 **Makefile**：

```makefile
PORTNAME=	Machine-Build
DISTVERSION=	1
CATEGORIES=	devel perl5
MASTER_SITES=	CPAN
PKGNAMEPREFIX=	p5-

MAINTAINER=	perl@FreeBSD.org
COMMENT=	Building machine
WWW=		https://search.cpan.org/dist/Machine-Build

USES=		perl5
USE_PERL5=	configure

PLIST_SUB=	PERL_ARCH=mach
```

该 Port 安装的文件如下：

```sh
/usr/local/bin/machine-build
/usr/local/lib/perl5/site_perl/man/man1/machine-build.1.gz
/usr/local/lib/perl5/site_perl/man/man3/Machine::Build.3.gz
/usr/local/lib/perl5/site_perl/Machine/Build.pm
/usr/local/lib/perl5/site_perl/mach/5.20/Machine/Build/Build.so
```

运行 `make makeplist` 错误地生成：

```sh
bin/%%PERL_ARCH%%ine-build
%%PERL5_MAN1%%/%%PERL_ARCH%%ine-build.1.gz
%%PERL5_MAN3%%/Machine::Build.3.gz
%%SITE_PERL%%/Machine/Build.pm
%%SITE_PERL%%/%%PERL_ARCH%%/%%PERL_VER%%/Machine/Build/Build.so
```

将 **Makefile** 中的 `PLIST_SUB` 行更改为：

```makefile
PLIST_SUB=	PERL_ARCH=mach \
		PERL_ARCH_regex=\bmach\b
```

现在 `make makeplist` 正确生成：

```sh
bin/machine-build
%%PERL5_MAN1%%/machine-build.1.gz
%%PERL5_MAN3%%/Machine::Build.3.gz
%%SITE_PERL%%/Machine/Build.pm
%%SITE_PERL%%/%%PERL_ARCH%%/%%PERL_VER%%/Machine/Build/Build.so
```


---

# 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-8-zhang-gao-ji-pkgplist-shi-jian/8.5.-zi-dong-chuang-jian-ruan-jian-bao-lie-biao.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.
