-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
278 lines (218 loc) · 11.1 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
## ideas and most of the code stolen from https://github.com/tudo-r/makeR
## updated to be run outside of the package directory
## Documentation is done directly in the Makefile using roxygen2-like syntax.
## To document a target use #' directly after the target and it dependencies
## (in the same line). Use @section to start a new section and @note to create
## a new note in the help output.
R_HOME = "$(shell R RHOME)"
R = "$(R_HOME)/bin/R"
RSCRIPT = "$(R_HOME)/bin/Rscript"
RM := rm -rf
PKG := maker## default package (there must be no whitespace behind the PKG name)
PKGDIR = ${PKG}/
PKGNAME = $(shell sed -n 's/Package: *//p' ${PKGDIR}/DESCRIPTION 2> /dev/null)
VERSION = $(shell sed -n 's/Version: *//p' ${PKGDIR}/DESCRIPTION 2> /dev/null)
TARGZ = ${PKGNAME}_${VERSION}.tar.gz
BUILDARGS := --no-build-vignettes
CHECKARGS := --no-vignettes --no-build-vignettes --no-stop-on-test-error
RELEASERARGS := --no-save --no-restore --no-site-file --no-environ --vanilla --no-init-file
RELEASETARGETS := | clean-all build check-only
INSTALLARGS := --install-tests
IGNORE := ".git/* .svn/* sandbox/*"
IGNOREPATTERN = $(shell echo "${IGNORE}" | sed 's:\([^[:space:]]\+\):-a -not -path "${PKGDIR}/\1":g; s:/\{2,\}:/:g; s:^-a \+::')
MAKERDIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
INCLUDEDIR := ${MAKERDIR}/include/
PKGFILES = $(shell find ${PKGDIR} -type f \( ${IGNOREPATTERN} \) 2>/dev/null)
VIGFILES = $(shell find ${PKGDIR} -type f -name *.Rnw 2>/dev/null)
MAKERVERSION := $(shell cd ${MAKERDIR} && git log -1 --format="%h [%ci]")
MAKERMAKEFILE := $(lastword $(MAKEFILE_LIST))
## targets that don't need an R package (PKG could be empty)
NONPKGTARGETS := get-default-pkg help maker maker-README.md targets usage version
PKGBUILDFLAGSFILE := /tmp/${PKGNAME}.buildflags
## user variables
MAKERRC := ~/.makerrc
WARNINGS_AS_ERRORS := 1
VIG := 1
CRAN := 0
BIOC = $(shell grep -s "biocViews" ${PKGDIR}/DESCRIPTION >/dev/null && echo 1 || echo 0)
COLOURS := 1
RPROFILE := ${INCLUDEDIR}/Rprofile
TIMEFORMAT :=
.DEFAULT_GOAL := help
## overwrite default variables by variables in ~/.makerrc
ifneq ($(wildcard ${MAKERRC}),)
include ${MAKERRC}
endif
## test whether PKGDIR is an R package
## if not throw an error if the user ask for a PKG-specific target
ifeq ($(wildcard ${PKGDIR}/DESCRIPTION),)
ifneq ($(filter-out ${NONPKGTARGETS},${MAKECMDGOALS}),)
$(error ${PKGDIR} seems to be no R package. Did you set PKG/PKGDIR?)
endif
endif
ifeq (${VIG},1)
BUILDARGS := $(filter-out --no-build-vignettes,$(BUILDARGS))
CHECKARGS := $(filter-out --no-vignettes,$(CHECKARGS))
endif
ifeq (${CRAN},1)
CHECKARGS += --as-cran
RELEASECHECKARGSCHECKARGS += --as-cran
endif
ifeq (${BIOC},1)
RELEASETARGETS += bioccheck-only
endif
.PHONY: build vignettes check check-only bioccheck bioccheck-only \
check-downstream check-reverse-dependencies clean clean-all clean-tar \
compile-attributes force help install install-only install-dependencies install-upstream \
maker .maker maker-README.md remove release roxygen document rd run-demos \
setup-git-hooks targets usage win-builder version \
pkg-home pkg-news pkg-refs pkg-vigs pkg-all pkgdown README.md NEWS
#'@section Usage
#'@note make TARGET PKG=package
#'@note e.g. make build PKG=MSnbase
## pseudo target to force evaluation of other targets, e.g. ${PKGBUILDFLAGSFILE}
force:
${PKGBUILDFLAGSFILE}: force
echo "${VIG}" | cmp --silent - $@ || echo "${VIG}" > $@
#'@section Build
build: clean ${TARGZ} #' build source package
${TARGZ}: ${PKGFILES} ${PKGBUILDFLAGSFILE}
${R} CMD build ${BUILDARGS} ${PKGDIR} | \
COLOURS=$(COLOURS) ${INCLUDEDIR}/color-output.sh
vignettes: #' build vignettes in ./${PKGDIR}/vignettes/
cd ${PKGDIR}/vignettes/ && \
test -f Makefile && \
make all || \
( for v in $$(ls *.Rnw *.Rmd 2>/dev/null); do \
${R} CMD Sweave --engine=knitr::knitr --pdf $$v; \
done )
compile-attributes: #' run Rcpp::compileAttributes()
${R} -e "library(Rcpp); compileAttributes('"$(PKGDIR)"')";
release: export R_PROFILE_USER=${RPROFILE}
release: R := ${R} ${RELEASERARGS}
release: CHECKARGS := ${RELEASECHECKARGS}
release: BUILDARGS := ${RELEASEBUILDARGS}
release: ${RELEASETARGETS} #' build package for Bioc/CRAN release (includes vignettes etc.)
#'@section Check
check: CHECKARGS := $(filter-out --no-vignettes,$(CHECKARGS))
check: | build check-only #' build and check package; the check will always use "--no-vignettes" because vignettes are checked by the build process before
check-only: #' check package and time checking
{ time ${TIMEFORMAT} ${R} CMD check ${CHECKARGS} ${TARGZ} 2>&1; } | \
COLOURS=$(COLOURS) ${INCLUDEDIR}/color-output.sh && \
grep "WARNING" ${PKGNAME}.Rcheck/00check.log > /dev/null ; \
if [ $$? -eq 0 ] ; then exit ${WARNINGS_AS_ERRORS}; fi
bioccheck: | check bioccheck-only #' build, check and BiocCheck package
bioccheck-only: #' BiocCheck package
${R} -e 'BiocCheck::BiocCheck("${TARGZ}")' 2>&1 | \
COLOURS=$(COLOURS) ${INCLUDEDIR}/color-output.sh && \
grep "WARNING" ${PKGNAME}.Rcheck/00check.log > /dev/null ; \
if [ $$? -eq 0 ] ; then exit ${WARNINGS_AS_ERRORS}; fi
check-reverse-dependencies: #' check packages which depend on this package
check-downstream: #' check packages which depend on this package
check-reverse-dependencies check-downstream: install
cd ${PKGDIR} && ${RSCRIPT} ${INCLUDEDIR}/check-reverse-dependencies.R
#'@section Clean
clean: #' remove temporary files and .Rcheck
${RM} ${PKGDIR}/src/*.o ${PKGNAME}/src/*.so
${RM} ${PKGDIR}/*~
find . -name '.Rhistory' -exec rm '{}' \;
${RM} ${PKGDIR}/vignettes/.\#*
${RM} ${PKGDIR}/vignettes/\#*
${RM} ${PKGNAME}.Rcheck
clean-tar: #' remove .tar.gz archive
${RM} ${TARGZ}
clean-vignettes: #' remove vignettes in inst/doc/
test -f ${PKGDIR}/vignettes/Makefile && \
(cd ${PKGDIR}/vignettes/ && make clean) || \
( ${RM} $(VIGFILES:.Rnw=.pdf) && \
${RM} ${PKGDIR}/vignettes/.build.timestamp )
clean-all: clean clean-tar clean-vignettes #' combine "clean", "clean-tar" and "clean-vignettes"
#'@section Increment version
increment-version-major: #' increment major version number (X++.1) and set the "Date" field in the DESCRIPTION file
@cd ${PKGDIR} && ${RSCRIPT} ${INCLUDEDIR}/increment-version.R major
increment-version-minor: #' increment minor version number (1.X++) and set the "Date" field in the DESCRIPTION file
@cd ${PKGDIR} && ${RSCRIPT} ${INCLUDEDIR}/increment-version.R minor
increment-version-patch: #' increment patch version number (1.1.X++) and set the "Date" field in the DESCRIPTION file
@cd ${PKGDIR} && ${RSCRIPT} ${INCLUDEDIR}/increment-version.R patch
#'@section Adminstration
install: | build install-only #' build and install package
install-only: #' install package
${R} CMD INSTALL ${INSTALLARGS} ${TARGZ} | \
COLOURS=$(COLOURS) ${INCLUDEDIR}/color-output.sh
install-dependencies install-upstream: '# install package dependencies
cd ${PKGDIR} && ${RSCRIPT} ${INCLUDEDIR}/install-dependencies.R
remove: #' remove package
${R} CMD REMOVE ${PKGNAME}
#'@section Documentation
roxygen: clean #' roxygenize package
${R} -e "library(roxygen2); roxygenize('"$(PKGDIR)"')";
document: clean #' document package
${R} -e "library(devtools); document('"$(PKGDIR)"')";
rd: clean #' roxygenize rd rocklet
${R} -e "library(devtools); document('"$(PKGDIR)"', roclets=\"rd\")";
pkg-home: clean #' pkgdown home
${R} -e "setwd('"$(PKGDIR)"'); library(pkgdown); build_home()";
pkg-news: clean #' pkgdown news
${R} -e "setwd('"$(PKGDIR)"'); library(pkgdown); build_news()";
pkg-refs: clean #' pkgdown references (manuals)
${R} -e "setwd('"$(PKGDIR)"'); library(pkgdown); build_reference()";
pkg-vigs: clean #' pkgdown articles (Rmd vignettes)
${R} -e "setwd('"$(PKGDIR)"'); library(pkgdown); build_articles()";
pkg-all: clean #' pkgdonw home, refs, articles and news (in that order)
$(MAKE) -f $(MAKERMAKEFILE) pkg-home
$(MAKE) -f $(MAKERMAKEFILE) pkg-refs
$(MAKE) -f $(MAKERMAKEFILE) pkg-vigs
$(MAKE) -f $(MAKERMAKEFILE) pkg-news
pkgdown: clean #' full pkgdown site using the pkgdown::build_site
${R} -e "setwd('"$(PKGDIR)"'); library(pkgdown); build_site()";
deploy: clean #' deploy pkgdown to branch
${R} -e "setwd('"$(PKGDIR)"'); pkgdown::deploy_to_branch(new_process = FALSE)";
README.md: #' knit README.Rmd if available
cd ${PKGDIR} && ${R} -e "if (file.exists('README.Rmd')) knitr::knit('README.Rmd')";
NEWS: #' defunct: see issue 33 (`news()` supports `NEWS.md` now)
@echo "Defunct: \`news()\` supports \`NEWS.md\` files since R 3.6.0; see also https://github.com/ComputationalProteomicsUnit/maker/issues/33."
#'@section Maker specific targets
maker: .maker #' update maker toolbox
.maker:
cd ${MAKERDIR} && git checkout master && git pull
maker-README.md: #' update help output in README.md
$(MAKE) --silent help | sed -i '/^\$$ make help/,/^```$$/{/^\$$ make help$$/!{/^```$$/!d}}; /^\$$ make help/r /dev/stdin' README.md
version: #' prints latest git hash and date of maker
@echo ${MAKERVERSION}
#'@section Available variables
#'@param PKG/PKGDIR path to the target package (default is 'maker')
#'@param MAKERRC path to the maker configuration file (default is '~/.makerrc')
#'@param VIG vignettes be build (default is 1). If 0, build --no-build-vignettes is used
#'@param WARNINGS_AS_ERRORS fail on warnings (default is 1)
#'@param CRAN check using --as-cran (default is 0)
#'@param COLOURS using colours for R CMD check results (default is 1)
#'@param RPROFILE path to .Rprofile (default is ${MAKEDIR}/include/Rprofile)
#'@param TIMEFORMAT time format (default: empty)
#'@section Misc
#'@note Vignettes are not build when checking: R CMD check --no-build-vignettes\n
win-builder: check #' build package and send to win-builder.r-project.org
ncftpput win-builder.r-project.org R-devel ${TARGZ}
run-demos: #' source and run demo/*.R files
cd ${PKGDIR} && ${RSCRIPT} ${INCLUDEDIR}/run-demos.R
get-default-pkg: #' print current default PKG
@grep "^[[:space:]]*PKG[[:space:]]*=" ${MAKERRC} || echo "No default PKG set."
set-default-pkg: #' set new default PKG
(test -f ${MAKERRC} && \
grep -q "^[[:space:]]*PKG[[:space:]]*=" ${MAKERRC} && \
sed -i --follow-symlinks 's/^[[:space:]]*PKG[[:space:]]*=.*/PKG=${PKG}/' ${MAKERRC}) || \
(echo PKG=${PKG} >> ${MAKERRC})
@echo
@echo "Default PKG set to ${PKG}."
remove-default-pkg: #' remove current default PKG
(test -f ${MAKERRC} && \
sed -i --follow-symlinks '/^[[:space:]]*PKG[[:space:]]*=.*/d' ${MAKERRC})
setup-git-hooks: #' setup git hooks
${MAKERDIR}/hooks/setup-hooks.sh ${PKGDIR}
#'@section Getting help
help target usage: #' print this help text
@sed -n "s/\\\\n/|/g; \
s/^#' *@section \(.*\)$$/\n\1:\n/p; \
s/^#' *@note \(.*\)$$/ \1/p; \
s/^#' *@param \([^ ]*\) \+\(.*\)\$$/ \1\t\2/p; \
s/^\([^:]\+\):.*#' \([^@]\+\)\$$/ \1\t\2/p" $(MAKEFILE_LIST) | expand -t 30 | tr '|' '\n'
#'@note \n Create an issue on https://github.com/ComputationalProteomicsUnit/maker/issues/ or \n write an e-mail to Sebastian Gibb <[email protected]> and Laurent Gatto <[email protected]>.