-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
152 lines (114 loc) · 4.87 KB
/
Makefile
File metadata and controls
152 lines (114 loc) · 4.87 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
## 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
.DEFAULT_GOAL: all
R_OPTS = --quiet --no-restore --no-init-file --no-site-file
PANDOC_OPTS=--from=markdown --standalone --syntax-highlighting=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 -fuse-ld=lld
CPPFLAGS := $(if $(I),-Werror,) -std=c++11 -Wextra -Wall -fsanitize=address -fsanitize=undefined -std=c++11 -fuse-ld=lld
# Fortran related flags
# compile
FCFLAGS = -g -Wextra -fimplicit-none -fdefault-real-8 -fbacktrace -fno-align-commons -fbounds-check -std=legacy -fopenmp
# link
FLFLAGS =
.PHONY: all
md_files = $(wildcard *.md)
all: $(md_files:.md=.pdf) $(md_files:.md=.html)
.PHONY: update-repo
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 :-(
## https://jwiegley.github.io/git-from-the-bottom-up/4-Stashing-and-the-reflog.html is where i got this idea!
.PHONY: stash-clear
stash-clear:
> git reflog expire --expire=60.days refs/stash || exit 0 ## since I do not use git stash _consistently_ this might raise some errors...
.PHONY: pyshell
## Modify the env to your choice...
PYENV = base
pyshell:
> micromamba run --name $(PYENV) python3 -I -s -E -OO
.PHONY: listpyenv
listpyenv:
> micromamba env list
%: %.f90 Makefile
> gfortran $(FCFLAGS) -o $@ $<
%: %.go Makefile
# > go build -x $<
> go build $<
% %.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=$@ $<
%.py: %.ipynb
> uv run --with jupyter jupyter nbconvert --to script $<
# > micromamba run --name ds jupyter jupyter nbconvert --to script $<
.PHONY: clean
clean:
> @echo "Do cleaning here"
> rm -rf $(md_files:.md=.pdf) $(md_files:.md=.html) $(patsubst %.c,%,$(wildcard *.c)) $(patsubst %.cc,%,$(wildcard *.cc)) $(patsubst %.cpp,%,$(wildcard *.cpp))
.PHONY: cleanall
cleanall: clean
> @echo "Do some specialized cleaning here..."
> rm -rf *.Rout .RData __pycache__
.PHONY: vars
## 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)) ))