# 5.16.解决冲突

有三个不同的变量用于注册包和 Port 之间的冲突：`CONFLICTS`、`CONFLICTS_INSTALL` 和 `CONFLICTS_BUILD`。

> **注意**
>
> 冲突变量会自动设置 `IGNORE` 变量，详细说明请参见 [使用 `BROKEN` 标记 Port 为不可安装](https://docs.freebsd.org/en/books/porters-handbook/porting-dads/#dads-noinstall)。

在删除多个冲突的 Port 之一时，建议在其他 Port 中保留 `CONFLICTS` 变量几个月，以便适应那些偶尔更新的用户。

`CONFLICTS_INSTALL`\
如果包无法与其他包共存（由于文件冲突、运行时不兼容等）。`CONFLICTS_INSTALL` 检查在构建阶段后，安装阶段前进行。

`CONFLICTS_BUILD`\
如果 Port 无法在安装了其他特定 Port 的情况下构建。构建冲突不会被记录到结果包中。

`CONFLICTS`\
如果在某个 Port 已安装的情况下，该 Port 无法构建，且结果包无法与其他包共存。`CONFLICTS` 检查在构建阶段前和安装阶段前进行。

`CONFLICTS*` 变量值中的每个由空格分隔的项都会与包进行匹配，除了正在构建的包，使用的是 shell 通配符规则。这允许列出 Port 的所有变体作为冲突项，而不需要排除正在构建的变体。例如，如果安装了 `git-lite`，`CONFLICTS_INSTALL=git git-lite` 将允许执行：

```sh
% make -C devel/git FLAVOR=lite all deinstall install
```

但是以下命令会报告冲突，因为安装的包基础名称是 `git-lite`，而 `git` 将被构建，但无法与 `git-lite` 一起安装：

```sh
% make -C devel/git FLAVOR=default all deinstall install
```

如果没有这个功能，Makefile 将需要为每个变体添加一个 `_flavor__CONFLICTS_INSTALL`，列出每个其他变体。

这些变量最常见的内容是另一个 Port 的包基础名。包基础名是没有附加版本的包名，可以通过运行 `make -V PKGBASE` 获取。

**示例 46. `CONFLICTS*` 的基本用法**

[dns/bind99](https://cgit.freebsd.org/ports/tree/dns/bind99/) 不能与 [dns/bind910](https://cgit.freebsd.org/ports/tree/dns/bind910/) 一起安装，因为它们安装了相同的文件。首先获取要使用的包基础名：

```sh
% make -C dns/bind99 -V PKGBASE
bind99
% make -C dns/bind910 -V PKGBASE
bind910
```

然后在 [dns/bind99](https://cgit.freebsd.org/ports/tree/dns/bind99/) 的 **Makefile** 中添加：

```makefile
CONFLICTS_INSTALL=	bind910
```

并在 [dns/bind910](https://cgit.freebsd.org/ports/tree/dns/bind910/) 的 **Makefile** 中添加：

```makefile
CONFLICTS_INSTALL=	bind99
```

有时，只有另一个 Port 的某些版本是不兼容的。当发生这种情况时，请使用完整的包名，包括版本。如果有必要，可以使用 shell 通配符，如 `*` 和 `?`，以便匹配所有必要的版本。

**示例 47. 使用通配符的 `CONFLICTS*`**

从 2.0 版本到 2.4.1\_2 版本，[deskutils/gnotime](https://cgit.freebsd.org/ports/tree/deskutils/gnotime/) 曾经安装一个捆绑的 [databases/qof](https://cgit.freebsd.org/ports/tree/databases/qof/) 版本。

为了反映这一点，[databases/qof](https://cgit.freebsd.org/ports/tree/databases/qof/) 的 **Makefile** 包含：

```makefile
CONFLICTS_INSTALL=	gnotime-2.[0-3]* \
			gnotime-2.4.0* gnotime-2.4.1 \
			gnotime-2.4.1_[12]
```

第一个条目匹配版本 `2.0` 到 `2.3`，第二个条目匹配所有 `2.4.0` 版本，第三个条目匹配精确的 `2.4.1` 版本，最后一个条目匹配 `2.4.1` 版本的第一个和第二个修订版。

[deskutils/gnotime](https://cgit.freebsd.org/ports/tree/deskutils/gnotime/) 没有任何冲突行，因为它的当前版本与其他任何版本不冲突。

`DISABLE_CONFLICTS` 变量可在执行不受冲突影响的目标时暂时设置。此变量不应在 Port 的 **Makefile** 中设置。

```sh
% make -DDISABLE_CONFLICTS patch
```


---

# 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-5-zhang-pei-zhi-makefile/5.16.-jie-jue-chong-tu.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.
