-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
165 lines (131 loc) · 5.56 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
# makefile written using https://yuukidach.github.io/p/makefile-for-projects-with-subdirectories/ as template
TARGET = r-source
OUTDIR = ./build
# includes all src dirs excluding R/
SRCDIR = ./demo ./inst/stan ./inst/stan/include ./man-roxygen
##DIR_OBJ = ./obj
OUTDIR_ABS=$(abspath $(OUTDIR))
PROJROOT_ABS=$(abspath .)
RPKG=$(patsubst ‘%’, %, $(word 2, $(shell grep ^Package: DESCRIPTION)))
INCS =
R_PKG_SRCS = $(wildcard R/*.R)
R_SRCS = $(wildcard *.R $(foreach fd, $(SRCDIR), $(fd)/*.R))
RMD_SRCS = $(wildcard *.Rmd $(foreach fd, $(SRCDIR), $(fd)/x*.Rmd))
STAN_SRCS = $(wildcard *.stan $(foreach fd, $(SRCDIR), $(fd)/*.stan))
SRCS = $(R_PKG_SRCS) $(R_SRCS) $(RMD_SRCS) $(STAN_SRCS)
NODIR_SRC = $(notdir $(SRCS))
BIN_OBJS = src/package-binary R/sysdata.rda
DOC_OBJS = man/package-doc inst/doc/$(RPKG).pdf
RCMD ?= R_PROFILE_USER="$(PROJROOT_ABS)/.Rprofile" "${R_HOME}/bin/R" -q
R_HOME ?= $(shell R RHOME)
PKG_VERSION ?= $(patsubst ‘%’, %, $(word 2, $(shell grep ^Version DESCRIPTION)))
GIT_TAG ?= v$(PKG_VERSION)
MD5 ?= md5sum
all : $(TARGET)
# tell makefile how to turn a Rmd into an md file
%.md : %.Rmd
cd $(@D); echo running $(RCMD) -e "rmarkdown::render('$(<F)', output_format=rmarkdown::md_document(variant='markdown'))"
cd $(@D); $(RCMD) -e "rmarkdown::render('$(<F)', output_format=rmarkdown::md_document(variant='markdown'))"
%.md : %.R
cd $(@D); echo running $(RCMD) -e "rmarkdown::render('$(<F)', output_format=rmarkdown::md_document(variant='markdown'))"
cd $(@D); $(RCMD) -q -e "rmarkdown::render('$(<F)', output_format=rmarkdown::md_document(variant='markdown'))"
# render an html via the respective md file
%.html : %.md
cd $(@D); echo running $(RCMD) -e "rmarkdown::render('$(<F)', output_format=rmarkdown::html_document(self_contained=TRUE))"
cd $(@D); $(RCMD) -e "rmarkdown::render('$(<F)', output_format=rmarkdown::html_document(self_contained=TRUE))"
R/stanmodels.R:
## ensure that NAMESPACE contains load directive
echo "# Generated by roxygen2: do not edit by hand" > NAMESPACE
echo "import(Rcpp)" >> NAMESPACE
echo "import(methods)" >> NAMESPACE
echo "importFrom(rstan, sampling)" >> NAMESPACE
echo "useDynLib($(RPKG), .registration = TRUE)" >> NAMESPACE
"${R_HOME}/bin/Rscript" -e "rstantools::rstan_config()"
src/package-binary: $(STAN_SRCS) R/stanmodels.R
## ensure that NAMESPACE contains load directive
echo "# Generated by roxygen2: do not edit by hand" > NAMESPACE
echo "import(Rcpp)" >> NAMESPACE
echo "import(methods)" >> NAMESPACE
echo "importFrom(rstan, sampling)" >> NAMESPACE
echo "useDynLib($(RPKG), .registration = TRUE)" >> NAMESPACE
"${R_HOME}/bin/R" --slave -e 'library(pkgbuild); pkgbuild::compile_dll()'
touch src/package-binary
man/package-doc: $(R_PKG_SRCS) $(BIN_OBJS)
"${R_HOME}/bin/R" --slave -e 'library(roxygen2); roxygen2::roxygenize()'
touch man/package-doc
inst/sbc/calibration.rds :
@echo Please run inst/sbc/make_reference_rankhist.R
exit 1
R/sysdata.rda: inst/sbc/calibration.rds
"${R_HOME}/bin/R" --slave --file=tools/make-ds.R
inst/doc/$(RPKG).pdf : man/package-doc
install -d inst/doc
"${R_HOME}/bin/R" CMD Rd2pdf --batch --no-preview --force --output=inst/doc/$(RPKG).pdf .
"${R_HOME}/bin/R" --vanilla --slave -e 'library(tools); tools::compactPDF("inst/doc/$(RPKG).pdf")'
NAMESPACE: man/package-doc
PHONY := $(TARGET)
$(TARGET): build/r-source
build/r-source : $(BIN_OBJS) $(DOC_OBJS) $(SRCS)
install -d build
cd build; $(RCMD) CMD build .. --no-build-vignettes --no-manual
cd build; mv $(RPKG)_$(PKG_VERSION).tar.gz $(RPKG)-source.tar.gz
touch build/r-source-fast
build/r-source-release : $(BIN_OBJS) $(DOC_OBJS) $(SRCS) inst/sbc/sbc_report.html
install -d build
git archive --format=tar.gz --prefix $(RPKG)-$(GIT_TAG)/ HEAD > build/$(RPKG)-$(GIT_TAG).tar.gz
rm -rf build/$(RPKG)-$(GIT_TAG)
cd build; tar xf $(RPKG)-$(GIT_TAG).tar.gz
cp -v NAMESPACE build/$(RPKG)-$(GIT_TAG)
install -d build/$(RPKG)-$(GIT_TAG)/inst/doc
cp -v inst/doc/$(RPKG).pdf build/$(RPKG)-$(GIT_TAG)/inst/doc
cp -v inst/sbc/sbc_report.html build/$(RPKG)-$(GIT_TAG)/inst/sbc/sbc_report.html
cd build/$(RPKG)-$(GIT_TAG); "${R_HOME}/bin/R" --slave --file=tools/make-ds.R
install -d build/$(RPKG)-$(GIT_TAG)/man
cp -v man/*.Rd build/$(RPKG)-$(GIT_TAG)/man
# set NOT_CRAN=true to get vignettes render with full sampling
cd build; NOT_CRAN=true $(RCMD) CMD build --compact-vignettes=both $(RPKG)-$(GIT_TAG)
#cd build; NOT_CRAN=false "${R_HOME}/bin/R" CMD build $(RPKG)-$(GIT_TAG) --no-build-vignettes --no-manual
rm -rf build/$(RPKG)-$(GIT_TAG)
cd build; $(MD5) $(RPKG)-$(GIT_TAG).tar.gz > $(RPKG)-$(GIT_TAG).md5
cd build; $(MD5) $(RPKG)_$(PKG_VERSION).tar.gz > $(RPKG)_$(PKG_VERSION).md5
touch build/r-source-release
PHONY += r-source-release
r-source-release : build/r-source-release
PHONY += binary
binary : NAMESPACE src/package-binary
PHONY += derived
derived : NAMESPACE $(BIN_OBJS) $(DOC_OBJS)
PHONY += r-source-check
r-source-check : r-source
cd build; tar xvzf RBesT-source.tar.gz
cd build; NOT_CRAN=true $(RCMD) CMD check RBesT
#$(DIR_OBJ)/%.o: %.c $(INCS)
# mkdir -p $(@D)
# $(CC) -o $@ $(CFLAGS) -c $< $(INC_DIRS)
PHONY += clean
clean:
rm -rf build/*
rm -f man/*.Rd
rm -f NAMESPACE
rm -f inst/doc/$(RPKG).pdf
rm -f src/$(RPKG).so
rm -f src/*.o
rm -f man/package-doc
rm -f src/package-binary
rm -f R/sysdata.rda
rm -f demo/*.html
rm -f vignettes/*.html
rm -f vignettes/*.docx
rm -rf .Rd2pdf*
PHONY += doc
doc: $(DOC_OBJS)
PHONY += echoes
echoes:
@echo "INC files: $(INCS)"
@echo "SRC files: $(SRCS)"
@echo "OBJ files: $(OBJS)"
##
# Debug target that allows you to print a variable
##
print-% : ; @echo $* = $($*)
.PHONY = $(PHONY)