如何将 Sphinx Makefile 集成到现有项目 Makefile 中?
How to integrate Sphinx Makefile into existing project Makefile?
我有一个具有以下目录结构的现有项目:
docs/
conf.py
Makefile
index.rst
documentation-foo.rst
documentation-bar.rst
src/
...code...
common.mk
Makefile
README.rst
在存储库的根目录中,Makefile
包含与制作、测试、打包和部署代码相关的各种有用命令。同样,common.mk
包括一个检查以确保用户在他们的系统上有几个可用的实用程序(例如,manipulating/displaying JSON 的 jq
)不能用 pip
。我可以发出 make lint
或 make test
之类的命令,这些命令在该 Makefile 中定义。 (Makefile
的顶部还有一个 include common.mk
,Makefile 内容见下文。)
在docs/
文件夹中,Makefile
是Sphinx自动生成的。这个 Makefile 是独立的,完全独立于存储库根目录中的 Makefile 或 common.mk 文件。我可以发出 make html
之类的命令,它将使用 Sphinx 生成 HTML 格式的文档。
(根目录)/Makefile 的内容:
include common.mk
clean:
...
lint:
...
test:
....
(根目录)/common.mk的内容:
ifeq ($(shell which jq),)
$(error Please install jq using "apt-get install jq" or "brew install jq")
endif
(狮身人面像)的内容/docs/Makefile:
# Minimal makefile for Sphinx documentation
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
...
我的主要问题是:如何在 /docs/Makefile
合并来自 sphinx Makefile 的规则,以便它们可以从根级别 /Makefile
获得?
例如,要制作 HTML 文档,我目前必须从 repo 的根目录 cd docs && make html
,但我希望能够 运行 make html
从 repo 的根目录中,让 repo 根目录中的 Makefile 将目标解析为 docs/Makefile
中定义的 html
目标,并使用该 Makefile 中定义的规则。
第二,相关问题:如果我在 docs/Makefile
中有具有相对路径的命令,必须将路径更新为相对于 make
命令所在的位置 运行(repo 的根而不是 docs/
),或者 make
是否将相对链接解析为相对于 Makefile 在 docs/
中的位置?
你可以用 recursive make:
html:
$(MAKE) -C docs html
有些人非常不喜欢递归 make。您可以阅读 the arguments against it,但我认为它们不适用于您对 make 的使用,因为您并没有试图表达依赖关系。
我有一个具有以下目录结构的现有项目:
docs/
conf.py
Makefile
index.rst
documentation-foo.rst
documentation-bar.rst
src/
...code...
common.mk
Makefile
README.rst
在存储库的根目录中,Makefile
包含与制作、测试、打包和部署代码相关的各种有用命令。同样,common.mk
包括一个检查以确保用户在他们的系统上有几个可用的实用程序(例如,manipulating/displaying JSON 的 jq
)不能用 pip
。我可以发出 make lint
或 make test
之类的命令,这些命令在该 Makefile 中定义。 (Makefile
的顶部还有一个 include common.mk
,Makefile 内容见下文。)
在docs/
文件夹中,Makefile
是Sphinx自动生成的。这个 Makefile 是独立的,完全独立于存储库根目录中的 Makefile 或 common.mk 文件。我可以发出 make html
之类的命令,它将使用 Sphinx 生成 HTML 格式的文档。
(根目录)/Makefile 的内容:
include common.mk
clean:
...
lint:
...
test:
....
(根目录)/common.mk的内容:
ifeq ($(shell which jq),)
$(error Please install jq using "apt-get install jq" or "brew install jq")
endif
(狮身人面像)的内容/docs/Makefile:
# Minimal makefile for Sphinx documentation
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
...
我的主要问题是:如何在 /docs/Makefile
合并来自 sphinx Makefile 的规则,以便它们可以从根级别 /Makefile
获得?
例如,要制作 HTML 文档,我目前必须从 repo 的根目录 cd docs && make html
,但我希望能够 运行 make html
从 repo 的根目录中,让 repo 根目录中的 Makefile 将目标解析为 docs/Makefile
中定义的 html
目标,并使用该 Makefile 中定义的规则。
第二,相关问题:如果我在 docs/Makefile
中有具有相对路径的命令,必须将路径更新为相对于 make
命令所在的位置 运行(repo 的根而不是 docs/
),或者 make
是否将相对链接解析为相对于 Makefile 在 docs/
中的位置?
你可以用 recursive make:
html:
$(MAKE) -C docs html
有些人非常不喜欢递归 make。您可以阅读 the arguments against it,但我认为它们不适用于您对 make 的使用,因为您并没有试图表达依赖关系。