forked from klmr/box
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
169 lines (131 loc) · 6.02 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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
R_HOME ?= $(shell Rscript --vanilla -e 'cat(Sys.getenv("R_HOME"))')
rscript = ${R_HOME}/bin/Rscript --no-save --no-restore
r = ${R_HOME}/bin/R --no-save --no-restore
# Helper functions for a recursive wildcard function.
match_files = $(filter $(subst *,%,$2),$1)
filter_out_dirs = $(filter-out %/,$(foreach f,$1,$(wildcard $f/)))
rec_find = $(foreach f,$(wildcard ${1:=/*}),$(call filter_out_dirs,$(call rec_find,$f,$2) $(call match_files,$f,$2)))
r_source_files = $(wildcard R/*.r)
c_source_files = $(wildcard src/*.c src/*.h)
vignette_files = $(call rec_find,vignettes,*)
rmd_files = $(wildcard vignettes/*.rmd)
knit_results = $(patsubst vignettes/%.rmd,doc/%.md,${rmd_files})
pkg_bundle_name := $(shell ${rscript} --vanilla -e 'cat(sprintf("%s.tar.gz\n", paste(read.dcf("DESCRIPTION")[1L, c("Package", "Version")], collapse = "_")))')
cran-tmpdir = tmp.cran
favicons_small = $(addprefix pkgdown/favicon/,$(addprefix favicon-,16x16.png 32x32.png))
favicons_large = $(addprefix pkgdown/favicon/,\
$(addsuffix .png,$(addprefix apple-touch-icon-,60x60 76x76 120x120 152x152)))
favicon_default = pkgdown/favicon/apple-touch-icon.png
favicons = ${favicons_small} ${favicons_large} ${favicon_default}
inkscape = $(shell command -v inkscape || echo /Applications/Inkscape.app/Contents/MacOS/inkscape)
.PHONY: test
## Run unit tests
test: documentation
${rscript} -e "devtools::test(export_all = FALSE)"
## Run a single, named unit test
/test-%: documentation
${rscript} -e "devtools::test(filter = '$*', export_all = FALSE)"
.PHONY: check
## Run R CMD check
check: documentation
ret=0; \
for rule in scripts/check_rule_*; do \
if ! $$rule .; then ret=1; fi \
done; \
mkdir -p check; \
${rscript} -e "devtools::check(check_dir = 'check')"; \
check=$$?; \
let ret='ret | check'; \
exit $$ret
.PHONY: site
## Create package website
site: README.md NAMESPACE NEWS.md ${favicons}
${rscript} -e "pkgdown::build_site(new_process = FALSE)"
scripts/copy-vignette-extra-files . docs/articles 2>/dev/null \
|| scripts/copy-vignette-extra-files . docs/dev/articles \
.PHONY: dev-site
## Create package website [dev mode]
dev-site: README.md NAMESPACE
${rscript} -e "pkgdown::build_site(devel = TRUE)"
## Create just the specified article for the website
/article-%:
${rscript} -e "pkgdown::build_article('$*')"
## Create just the references for the website
reference: documentation
${rscript} -e "pkgdown::build_reference()"
# FIXME: Old reason for building everything twice no longer exists; do we need
# both `all-vignette` and `knit-all` rules?
.PHONY: all-vignettes
## Compile all vignettes and other R Markdown articles
all-vignettes: Meta/vignette.rds
Meta/vignette.rds: DESCRIPTION NAMESPACE ${r_source_files} ${vignette_files}
${rscript} -e "devtools::build_vignettes(dependencies = TRUE)"
.PHONY: knit-all
## Compile R markdown articles and move files to the documentation directory
knit-all: ${knit_results} | doc
doc/%.md: vignettes/%.rmd DESCRIPTION NAMESPACE ${r_source_files} | doc
${rscript} -e "rmarkdown::render('$<', output_format = 'md_document', output_file = '${@F}', output_dir = '${@D}')"
.PHONY: documentation
## Compile the in-line package documentation
documentation: NAMESPACE
# Delete NAMESPACE on compilation failure; otherwise rerunning the rule won’t do
# anything.
NAMESPACE: ${r_source_files} ${c_source_files} DESCRIPTION
echo >NAMESPACE '# Generated by roxygen2: do not edit by hand' # Workaround for bug #1070 in roxygen2 7.1.0
${rscript} -e "devtools::document()" || { ${RM} $@; exit 1; }
README.md: README.rmd NAMESPACE DESCRIPTION man/figures/logo.png
${rscript} -e "devtools::load_all(export_all = FALSE); knitr::knit('$<')"
man/figures/logo.png: figures/logo.svg
${inkscape} -w 240 --export-filename ${@:.png=.tmp.png} $<
pngcrush ${@:.png=.tmp.png} $@
${RM} ${@:.png=.tmp.png}
.PHONY: build
## Build the package tar.gz bundle
build: ${pkg_bundle_name}
${pkg_bundle_name}: DESCRIPTION NAMESPACE ${r_source_files}
${r} CMD build .
.PHONY: build-cran
## Bundle the package with static vignette sources for submission to CRAN
build-cran:
@git diff-index --quiet HEAD || { printf 'ERROR: Uncommitted changes found!\n'; exit 1; }
${RM} -r ${cran-tmpdir} \
&& git clone . ${cran-tmpdir} \
&& sed "s/@YEAR@/$$(date +%Y)/" cran/LICENSE >${cran-tmpdir}/LICENSE \
&& echo 'renv::load("${PWD}")' >${cran-tmpdir}/.Rprofile \
&& ${MAKE} -C ${cran-tmpdir} knit-all \
&& scripts/precompile-vignettes ${cran-tmpdir} \
&& ${MAKE} -C ${cran-tmpdir} build \
&& mv ${cran-tmpdir}/${pkg_bundle_name} . \
&& ${RM} -r ${cran-tmpdir}
.PHONY: favicons
## Generate the documentation site favicons
favicons: ${favicons}
export-favicon = \
@sz=$$(sed 's/.*x\([[:digit:]]*\)\.png/\1/' <<<"$@") \
&& set -x; \
${inkscape} -w $$sz -h $$sz --export-area $1 --export-filename=${@D}/tmp-${@F} $< \
&& pngcrush -q ${@D}/tmp-${@F} $@ && rm ${@D}/tmp-${@F}
${favicons_small}: figures/logo.svg | pkgdown/favicon
$(call export-favicon,-11:1000:181:1192)
${favicons_large}: figures/logo.svg | pkgdown/favicon
$(call export-favicon,-51:0:711:760)
${favicon_default}: figures/logo.svg | pkgdown/favicon
${inkscape} -w 180 -h 180 --export-area -51:0:711:760 --export-filename=${@D}/tmp-${@F} $<
pngcrush -q ${@D}/tmp-${@F} $@ && rm ${@D}/tmp-${@F}
.PHONY: lint
## Lint the package source
lint:
${rscript} -e "lintr::lint_package('.')"
doc pkgdown/favicon:
mkdir -p $@
## Clean up all build files
cleanall:
${RM} -r doc docs Meta
${RM} man/*.Rd
${RM} NAMESPACE
${RM} src/*.o src/*.so
.DEFAULT_GOAL := show-help
# See <https://github.com/klmr/maketools/tree/master/doc>.
.PHONY: show-help
show-help:
@echo "$$(tput bold)Available rules:$$(tput sgr0)";echo;sed -ne"/^## /{h;s/.*//;:d" -e"H;n;s/^## //;td" -e"s/:.*//;G;s/\\n## /---/;s/\\n/ /g;p;}" ${MAKEFILE_LIST}|LC_ALL='C' sort -f|awk -F --- -v n=$$(tput cols) -v i=19 -v a="$$(tput setaf 6)" -v z="$$(tput sgr0)" '{printf"%s%*s%s ",a,-i,$$1,z;m=split($$2,w," ");l=n-i;for(j=1;j<=m;j++){l-=length(w[j])+1;if(l<= 0){l=n-i-length(w[j])-1;printf"\n%*s ",-i," ";}printf"%s ",w[j];}printf"\n";}'|more $$(test $$(uname) = Darwin && echo \-Xr)