-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
123 lines (90 loc) · 4.08 KB
/
Makefile
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
## The next few lines from https://tech.davis-hansson.com/p/make/ "Your Makefiles are wrong"
##
## So that we can use brace expansion which is unavailable in sh! Sheesh!
SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
.RECIPEPREFIX = >
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
.PHONY: all clean message cleanall pyshell update-repo stash-clear
.DEFAULT_GOAL: all
R_OPTS = --quiet --no-restore --no-init-file --no-site-file
PANDOC_OPTS=--from=markdown --standalone --highlight-style=tango --wrap=none --citeproc --toc --toc-depth=2
PANDOC_HTML_OPTS=--to=html5 --number-sections --mathjax --email-obfuscation=references
LILYPOND=lilypond
CC := $(shell command -v clang || command -v gcc 2>/dev/null)
CXX := $(shell command -v clang++ || command -v g++ 2>/dev/null)
CFLAGS := $(if $(I),-Werror,) -Wextra -Wall -fsanitize=address -fsanitize=undefined
CPPFLAGS := $(if $(I),-Werror,) -Wextra -Wall -fsanitize=address -fsanitize=undefined
md_files = $(wildcard *.md)
all: $(md_files:.md=.pdf) $(md_files:.md=.html)
update-repo:
> git stash push --include-untracked
> git pull --ff-only
> git stash apply || exit 0 ## '...' ## no stash entry generates a non-zero exit indicating error :-(
stash-clear:
> git reflog expire --expire=60.days refs/stash || exit 0 ## since I do not use git stash this might raise some errors...
## Modify the env to your choice...
pyshell:
> micromamba run --name base python3 -I -s -E -OO
% %.o: %.c Makefile
> $(CC) $(CFLAGS) -o $@ $<
% %.o: %.cc Makefile
> $(CXX) $(CPPFLAGS) -o $@ $<
% %.o: %.cpp Makefile
> $(CXX) $(CPPFLAGS) -o $@ $<
%.pdf: %.dot
> ## sed -i -E -e 's/([0-9]{4})-([0-9]{2})-([0-9]{2})/\1.\2.\3/g' $<
> dot -Tpdf -o $@ $<
%.pdf: %.gv
> sed -i -E -e 's/([0-9]{4})-([0-9]{2})-([0-9]{2})/\1.\2.\3/g' $<
> dot -Tpdf -o $@ $<
%.svg: %.dot
> dot -Tsvg -o $@ $<
%.svg: %.gv
> sed -i -E -e 's/([0-9]{4})-([0-9]{2})-([0-9]{2})/\1.\2.\3/g' $<
> dot -Tsvg -o $@ $<
%: %.rs
> rustc $<
## For debugging
%.native: %.md
> docker run --rm --platform=linux/amd64 --mount "type=bind,src=$$(pwd),dst=/data" --user "$$(id -u):$$(id -g)" pandoc-komascript ${PANDOC_OPTS} --to=native --output=$@ $<
%.pdf: %.md Makefile
> docker run --rm --platform=linux/amd64 --mount "type=bind,src=$$(pwd),dst=/data" --user "$$(id -u):$$(id -g)" pandoc-komascript ${PANDOC_OPTS} --to=latex --output=$@ $<
%.html: %.md Makefile
> docker run --rm --platform=linux/amd64 --mount "type=bind,src=$$(pwd),dst=/data" --user "$$(id -u):$$(id -g)" pandoc-komascript ${PANDOC_OPTS} ${PANDOC_HTML_OPTS} --output=$@ $<
%.docx: %.md Makefile
> docker run --rm --platform=linux/amd64 --mount "type=bind,src=$$(pwd),dst=/data" --user "$$(id -u):$$(id -g)" pandoc-komascript ${PANDOC_OPTS} --to=docx --output=$@ $<
%.odt: %.md Makefile
> docker run --rm --platform=linux/amd64 --mount "type=bind,src=$$(pwd),dst=/data" --user "$$(id -u):$$(id -g)" pandoc-komascript ${PANDOC_OPTS} --to=odt --output=$@ $<
%.pdf: %.ly Makefile
> ${LILYPOND} $<
%.pdf: %.qmd Makefile
> quarto render $< --to pdf --toc
%.html: %.qmd Makefile
> quarto render $< --to html --toc
%.pdf: %.Rmd Makefile
> R ${R_OPTS} -e "rmarkdown::render('$<', 'pdf_document')"
%.html: %.Rmd Makefile
> R ${R_OPTS} -e "rmarkdown::render('$<', 'html_document')"
>
%.docx: %.Rmd Makefile
> R ${R_OPTS} -e "rmarkdown::render('$<', 'word_document')"
%.Rout: %.R Makefile
> R CMD BATCH ${R_OPTS} $<
%.R: %.Rmd Makefile
> R ${R_OPTS} -e "knitr::purl(input='$<',output='$@',documentation=0)"
%.html: %.tex Makefile
> docker run --rm --platform linux/amd64 --mount "type=bind,src=$$(pwd),dst=/data" --user "$$(id -u):$$(id -g)" pandoc/latex:3.1 $(PANDOC_OPTS) ${PANDOC_HTML_OPTS} --from=latex --output=$@ $<
clean:
> @echo "Do cleaning here"
> rm -rf $(md_files:.md=.pdf) $(md_files:.md=.html)
cleanall: clean
> @echo "Do some specialized cleaning here..."
> rm -rf *.Rout .RData __pycache__
## to debug variables define in Makefile...
## bash $ make -n vars 2>/dev/null ## suppress --warn-undefined-variables flag set earlier...
## from https://stackoverflow.com/a/7119460
vars:; $(foreach v,$(.VARIABLES),$(info $(v) = $($(v)) ))