> 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-5-zhang-pei-zhi-makefile/5.11.-cong-shu-port-he-masterdir.md).

# 5.11.从属 Port 和 MASTERDIR

如果 Port 需要通过让变量（例如分辨率或纸张大小）取不同的值来构建略有不同版本的软件包，则为每个软件包创建一个子目录，以便用户更容易理解该怎么做，但尽量使尽可能多的文件在 Port 之间共享。通常，通过巧妙使用变量，除了一个目录外，其他目录只需要非常简短的 **Makefile**。在唯一的 **Makefile** 中，使用 `MASTERDIR` 来指定其他文件所在的目录。同时，使用变量作为 [`PKGNAMESUFFIX`](https://docs.freebsd.org/en/books/porters-handbook/makefiles/#porting-pkgname) 的一部分，以便使软件包具有不同的名称。

通过一个例子可以更好地展示这一点。以下是 **print/pkfonts300/Makefile** 的一部分：

```makefile
PORTNAME=	pkfonts${RESOLUTION}
PORTVERSION=	1.0
DISTFILES=	pk${RESOLUTION}.tar.gz

PLIST=		${PKGDIR}/pkg-plist.${RESOLUTION}

.if !defined(RESOLUTION)
RESOLUTION=	300
.else
.if ${RESOLUTION} != 118 && ${RESOLUTION} != 240 && \
	${RESOLUTION} != 300 && ${RESOLUTION} != 360 && \
	${RESOLUTION} != 400 && ${RESOLUTION} != 600
.BEGIN:
	@${ECHO_MSG} "Error: invalid value for RESOLUTION: \"${RESOLUTION}\""
	@${ECHO_MSG} "Possible values are: 118, 240, 300, 360, 400 and 600."
	@${FALSE}
.endif
.endif
```

[print/pkfonts300](https://cgit.freebsd.org/ports/tree/print/pkfonts300/) 还包含所有常规的补丁、软件包文件等。在该目录中运行 `make`，它将采用分辨率的默认值（300）并正常构建 Port。

至于其他分辨率，以下是**整个** **print/pkfonts360/Makefile**：

```makefile
RESOLUTION=	360
MASTERDIR=	${.CURDIR}/../pkfonts300

.include	"${MASTERDIR}/Makefile"
```

(**print/pkfonts118/Makefile**、**print/pkfonts600/Makefile**，以及所有其他类似的文件)。`MASTERDIR` 定义告诉 **bsd.port.mk**，像 `FILESDIR` 和 `SCRIPTDIR` 这样的常规子目录位于 **pkfonts300** 下。`RESOLUTION=360` 这一行将覆盖 **pkfonts300/Makefile** 中的 `RESOLUTION=300`，并且该 Port 将以 360 的分辨率进行构建。


---

# 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-5-zhang-pei-zhi-makefile/5.11.-cong-shu-port-he-masterdir.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.
