# 5.18. 使用 BINARY\_ALIAS 来重命名命令，而不是在编译中打补丁

## 5.17.6. `BINARY_ALIAS` 用法

当定义了 `BINARY_ALIAS` 时，它会在一个目录中创建所给命令的符号链接，并将该目录添加到 `PATH` 中。

使用它可以替换构建阶段依赖的硬编码命令，而无需修补任何构建文件。

**示例 48. 使用 `BINARY_ALIAS` 让 `gsed` 作为 `sed` 使用**

某些 Port 期望 `sed` 行为像 GNU sed，并使用 [sed(1)](https://man.freebsd.org/cgi/man.cgi?query=sed\&sektion=1\&format=html) 不提供的功能。GNU sed 可以通过 [textproc/gsed](https://cgit.freebsd.org/ports/tree/textproc/gsed/) 在 FreeBSD 上获得。

使用 `BINARY_ALIAS` 将 `sed` 替换为 `gsed` 以便在构建期间使用：

```makefile
BUILD_DEPENDS=	gsed:textproc/gsed
...
BINARY_ALIAS=	sed=gsed
```

**示例 49. 使用 `BINARY_ALIAS` 为硬编码的 `python3` 命令提供别名**

一个 Port 如果在其构建脚本中硬编码了对 `python3` 的引用，需要在构建时使其在 `PATH` 中可用。使用 `BINARY_ALIAS` 创建一个指向正确 Python 3 二进制文件的别名：

```makefile
USES=	python:3.4+,build
...
BINARY_ALIAS=	python3=${PYTHON_CMD}
```

更多关于 `USES=python` 的信息，请参见 [使用 Python](https://docs.freebsd.org/en/books/porters-handbook/special/#using-python)。

> **注意**
>
> 二进制别名是在处理完 `BUILD_DEPENDS` 和 `LIB_DEPENDS` 提供的依赖关系之后，以及 `configure` 目标之前创建的。这会导致一些限制。例如，通过 `TEST_DEPENDS` 安装的程序不能用于创建二进制别名，因为此方式指定的测试依赖关系是在创建二进制别名之后处理的。


---

# 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.18.-shi-yong-binaryalias-lai-zhong-ming-ming-ming-ling-er-bu-shi-zai-bian-yi-zhong-da-bu-ding.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.
