-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
Makefile
126 lines (95 loc) · 3.65 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
#https://stackoverflow.com/questions/34603415/makefile-automatic-target-generation
#https://www.gnu.org/software/make/manual/make.html#Static-Pattern
#https://stackoverflow.com/questions/2826029/passing-additional-variables-from-command-line-to-make
#https://stackoverflow.com/questions/2214575/passing-arguments-to-make-run
R_HOME = /usr
PKG_PATH = ${PWD}
TOP = ${PWD}/..
PKG_DESC = ${PKG_PATH}/DESCRIPTION
PKG_NAME = $(shell sed -ne "s/^Package: //p" ${PKG_DESC} | tr -d '\n')
PKG_VER = $(shell sed -ne "s/^Version: \(.*\)/\1/p" ${PKG_DESC} | tr -d '\n')
PKG_TARGZ = $(PKG_NAME)_$(PKG_VER).tar.gz
PKG_BUILD_OPTS ?= --no-build-vignettes
R_LIB ?= $(shell Rscript -e 'cat(.libPaths()[1L])')
PKG_INST_FILE = $(R_LIB)/${PKG_NAME}/DESCRIPTION
PKG_R_FILES := $(wildcard ${PKG_PATH}/R/*.R)
PKG_RD_FILES := $(wildcard ${PKG_PATH}/man/*.Rd)
PKG_SRC_FILES := $(wildcard ${PKG_PATH}/src/*)
PKG_ALL_FILES := ${PKG_PATH}/DESCRIPTION ${PKG_PATH}/NAMESPACE $(PKG_R_FILES) $(PKG_RD_FILES) $(PKG_SRC_FILES)
HTML_FILES := $(patsubst %.Rmd, %.html, $(wildcard *.Rmd)) \
$(patsubst %.md, %.html, $(wildcard *.md))
UNIT_TEST_SUITE = ${PKG_PATH}/tests/doRUnit.R
UNIT_TEST_FILES = $(wildcard ${PKG_PATH}/inst/unitTests/runit*.R)
BENCHMARK_FILE = ${PKG_PATH}/inst/benchmarks/benchmark.subset.R
.PHONY: build install check tests test clean
all: check #benchmark
#man/*.Rd depend on R/*.R files
print:
@echo 'path: $(PKG_PATH) \
inst_file: $(PKG_INST_FILE) \
tar.gz: $(PKG_TARGZ)'
# Build package
build: $(PKG_TARGZ)
$(PKG_TARGZ): $(PKG_ALL_FILES) $(UNIT_TEST_FILES) $(UNIT_TEST_SUITE)
@${R_HOME}/bin/R CMD build ${PKG_BUILD_OPTS} ${PKG_PATH} --no-build-vignettes
# Install package
install: build $(PKG_INST_FILE)
$(PKG_INST_FILE): $(PKG_TARGZ)
@${R_HOME}/bin/R CMD INSTALL ${PKG_TARGZ} --no-byte-compile
# Run R CMD check
check: build
@_R_CHECK_CRAN_INCOMING_=false \
${R_HOME}/bin/R CMD check ${PKG_TARGZ} --as-cran
# Build for CRAN
#build-cran: $(PKG_TARGZ)
#$(PKG_TARGZ): $(PKG_ALL_FILES) $(UNIT_TEST_FILES) $(UNIT_TEST_SUITE)
# @${R_HOME}/bin/R CMD build ${PKG_BUILD_OPTS} ${PKG_PATH}
#
## Install package for CRAN
#install-cran: build-cran $(PKG_INST_FILE)
#$(PKG_INST_FILE): $(PKG_TARGZ)
# @${R_HOME}/bin/R CMD INSTALL ${PKG_TARGZ}
#
## Run R CMD check for CRAN
#check-cran: install-cran
# ${R_HOME}/bin/R CMD check ${PKG_TARGZ}
# Run unit test suite
tests: install ${UNIT_TEST_FILES}
@${R_HOME}/bin/Rscript ${UNIT_TEST_SUITE}
# Run one test file
TEST_FILE = $(wildcard ${PKG_PATH}/inst/unitTests/*${file}*)
TEST_CMD = 'suppressMessages({require(xts); require(RUnit)}); \
out <- runTestFile("${TEST_FILE}", verbose = TRUE); \
printTextProtocol(out)'
test: install
ifndef file
$(error "file not defined")
endif
@${R_HOME}/bin/Rscript -e ${TEST_CMD}
html: $(HTML_FILES)
%.html: %.Rmd
R --slave -e "set.seed(100);rmarkdown::render('$<')"
%.html: %.md
R --slave -e "set.seed(100);rmarkdown::render('$<')"
clean:
$(RM) $(HTML_FILES)
# Run individual unit test file
#%::
# @THING=$(wildcard unitTests/runit*$@*);\
# echo $(foreach f, $(THING), $(echo $(f)))
# @echo $(value ut)
#% :: unitTests/runit%.R
# @echo $<
#runit%.R: runit%.R
# @echo "yay!"#${R_HOME}/bin/Rscript -e 'require(RUnit); runTestFile("unitTests/$@")'"
# @echo "$(filter $(wildcard unitTests/runit*$@*), $(UNIT_TEST_FILES))"
#$(filter $(wildcard unitTests/runit*$@*), $(UNIT_TEST_FILES))"
#.PHONY: runit
#runit: ;
# @echo "$(filter $(wildcard unitTests/runit*$@*), $(UNIT_TEST_FILES))"
#$(filter unitTests/runit.%.R, $(UNIT_TEST_FILES)): runit.%.R
# echo "yay!"
# @${R_HOME}/bin/Rscript -e 'require(RUnit); runTestFile("unitTests/$@")'
# Run benchmarks
#benchmark:
# @${R_HOME}/bin/Rscript ${BENCHMARK_FILE}