-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
64 lines (56 loc) · 1.98 KB
/
Copy pathMakefile
File metadata and controls
64 lines (56 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
SHELL := /bin/sh
DOCS_DIR := docs
DOCS_BUILD_DIR:= target/docs
DOC_MAIN := $(DOCS_DIR)/main.tex
DOC_NAME := $(basename $(notdir $(DOC_MAIN)))
DOC_CFG := $(DOCS_DIR)/site.cfg
DOC_CSS := $(DOCS_DIR)/site.css
PDF_DIR := $(DOCS_BUILD_DIR)/pdf
HTML_DIR := $(DOCS_BUILD_DIR)/html
HTML_TEMP_DIR := $(DOCS_BUILD_DIR)/make4ht
PDF_OUTPUT := $(PDF_DIR)/$(DOC_NAME).pdf
HTML_OUTPUT := $(HTML_DIR)/$(DOC_NAME).html
CSS_OUTPUT := $(HTML_DIR)/site.css
.PHONY: all docs pdf html clean switch
define XPU_BLOCK
[tool.uv.sources]
torch = { index = "pytorch-xpu" }
torchvision = { index = "pytorch-xpu" }
torchaudio = { index = "pytorch-xpu" }
[[tool.uv.index]]
name = "pytorch-xpu"
url = "https://download.pytorch.org/whl/xpu"
endef
export XPU_BLOCK
all: docs lib uv
lib:
@cargo b --release
uv:
@uv sync && maturin develop
docs:
@rm -rf "$(DOCS_BUILD_DIR)"
@$(MAKE) pdf html
pdf:
@printf 'Building PDF documentation...\n'
@mkdir -p "$(abspath $(PDF_DIR))"
@cd "$(abspath $(DOCS_DIR))" && latexmk -pdf -interaction=nonstopmode -halt-on-error -file-line-error -outdir="$(abspath $(PDF_DIR))" "$(notdir $(DOC_MAIN))"
html:
@printf 'Building HTML documentation...\n'
@mkdir -p "$(abspath $(HTML_DIR))" "$(abspath $(HTML_TEMP_DIR))"
@cd "$(DOCS_DIR)" && find . -type d | while IFS= read -r dir; do mkdir -p "$(abspath $(HTML_TEMP_DIR))/$$dir"; done
@cd "$(abspath $(DOCS_DIR))" && make4ht -x -u -c "$(notdir $(DOC_CFG))" -f html5 -B "$(abspath $(HTML_TEMP_DIR))" -d "$(abspath $(HTML_DIR))" "$(notdir $(DOC_MAIN))" "fancylogo,mathml,2,fulltoc,next"
@cp "$(DOC_CSS)" "$(CSS_OUTPUT)"
clean:
@cargo clean
switch:
@perl -0pi \
-e '$$b = $$ENV{XPU_BLOCK};' \
-e 'if (/"torch==\d+(?:\.\d+)*\+xpu"/) {' \
-e ' s/("torch==\d+(?:\.\d+)*)\+xpu"/$$1"/;' \
-e ' s/\n*\Q$$b\E\n*/\n/;' \
-e ' print STDOUT "XPU disabled\n";' \
-e '} else {' \
-e ' s/("torch==\d+(?:\.\d+)*)"/$$1+xpu"/;' \
-e ' s/\s*\z/\n\n$$b\n/;' \
-e ' print STDOUT "XPU enabled\n";' \
-e '}' pyproject.toml