-
Notifications
You must be signed in to change notification settings - Fork 25
/
Makefile
180 lines (138 loc) · 5.75 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
R?=R
PACKAGE=stockassessment
VERSION := $(shell sed -n '/^Version: /s///p' stockassessment/DESCRIPTION)
THISSHA := $(shell git log -1 --format="%H")
TARBALL := $(PACKAGE)_$(VERSION).tar.gz
ZIPFILE := $(PACKAGE)_$(VERSION).zip
CPP_SRC := $(PACKAGE)/src/*.cpp $(PACKAGE)/src/*.h $(PACKAGE)/inst/include/*.hpp $(PACKAGE)/inst/include/SAM/*.hpp
R_FILES := $(PACKAGE)/R/*.R
SUBDIRS := $(wildcard testmore/*/.)
ifeq (testonemore,$(firstword $(MAKECMDGOALS)))
ARG := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(ARG):;@:)
endif
ifeq (webtestone,$(firstword $(MAKECMDGOALS)))
ARG := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(ARG):;@:)
endif
ifeq (webtest,$(firstword $(MAKECMDGOALS)))
ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(ARGS):;@:)
endif
testfiles := $(foreach dir,$(ARGS),$(dir)/OK)
.PHONY: webtestfromfile webtestone webtest test testmoreseq testonemore testmore $(SUBDIRS) all updateData qi quick-install vignette-update
all:
make install
$(PACKAGE)/configure: $(PACKAGE)/configure.ac
cd $(PACKAGE) && autoconf
doc-update: $(R_FILES)
echo "library(roxygen2);roxygenize(\"$(PACKAGE)\")" | $(R) --slave
sed -i /RoxygenNote/d $(PACKAGE)/DESCRIPTION
@touch doc-update
vignette-update: vignettes/*.Rnw vignettes/*.Rmd
cd vignettes; echo "knitr::knit2pdf('stockassessment.Rnw')" | $(R) --slave
cd vignettes; echo "rmarkdown::render('simulate.Rmd')" | $(R) --slave
mv vignettes/*.pdf $(PACKAGE)/inst/doc
cd vignettes; rm -f *.{log,aux,out,tex}
namespace-update :: $(PACKAGE)/NAMESPACE
$(PACKAGE)/NAMESPACE: $(R_FILES)
echo "library(roxygen2);roxygenize(\"$(PACKAGE)\")" | $(R) --slave
build-package: $(TARBALL)
$(TARBALL): $(PACKAGE)/NAMESPACE $(CPP_SRC) $(PACKAGE)/R/*.R $(PACKAGE)/configure
sed s/dummySHA/$(THISSHA)/g description-addon > description-addon-tmp
mv $(PACKAGE)/DESCRIPTION old-description
sed -i -E '/^(Remote|Github)/d' old-description
cat old-description description-addon-tmp > $(PACKAGE)/DESCRIPTION
rm description-addon-tmp
$(R) CMD build --no-manual --resave-data=no $(PACKAGE)
rm $(PACKAGE)/DESCRIPTION
mv old-description $(PACKAGE)/DESCRIPTION
sed -i /RoxygenNote/d $(PACKAGE)/DESCRIPTION
install: $(TARBALL)
$(R) CMD INSTALL --preclean --html $<
@touch $@
qi: $(PACKAGE)/configure
cd $(PACKAGE)/src; echo "library(TMB); compile('stockassessment.cpp')" | $(R) --slave
$(R) CMD INSTALL $(PACKAGE)
quick-install: $(CPP_SRC) $(PACKAGE)/configure $(R_FILES)
$(R) CMD INSTALL $(PACKAGE)
quick-install-debug: $(CPP_SRC) $(PACKAGE)/configure $(R_FILES)
$(R) CMD INSTALL --configure-args='--enable-debug' $(PACKAGE)
$(PACKAGE)/src/stockassessment.so: $(PACKAGE)/src/stockassessment.cpp $(CPP_SRC) $(PACKAGE)/configure
touch $(PACKAGE)/src/stockassessment.cpp
cd $(PACKAGE)/src; echo "library(TMB); compile('stockassessment.cpp','-O0 -g', libinit=FALSE)" | $(R) --slave
unexport TEXINPUTS
pdf: $(PACKAGE).pdf
$(PACKAGE).pdf: $(PACKAGE)/man/*.Rd
rm -f $(PACKAGE).pdf
$(R) CMD Rd2pdf --no-preview $(PACKAGE)
build:
$(R) CMD build $(PACKAGE)
check: $(TARBALL)
$(R) CMD check $(TARBALL)
check-cran: $(TARBALL)
$(R) CMD check --as-cran $(TARBALL)
quick-check: quick-install ex-test
ex-test:
echo "library(stockassessment); example(sam.fit)" | $(R) --slave
clean:
cd $(PACKAGE) && ./cleanup && cd ..
rm -f install doc-update $(TARBALL) $(PACKAGE).pdf $(PACKAGE)/src/*.so $(PACKAGE)/src/*.o
rm -rf $(PACKAGE).Rcheck
rm -f stockassessment/vignettes/stockassessment.{aux,log,out,pdf,tex}
test:
echo "devtools::test('stockassessment')" | $(R) --slave
updateData:
echo "library(stockassessment); \
source('stockassessment/tests/nscod/script.R', chdir=TRUE, echo=TRUE); \
attr(par,'what') <- NULL; par$missing <- NULL; \
nscodData <- dat; nscodConf <- conf; nscodParameters <- par; \
save(nscodData, file='stockassessment/data/nscodData.RData', version=2); \
save(nscodConf, file='stockassessment/data/nscodConf.RData', version=2); \
save(nscodParameters, file='stockassessment/data/nscodParameters.RData', version=2); " | $(R) --slave
updateDocs:
rm -rf docs
mkdir docs
echo "library(Rd2md); \
fn<-dir('$(PACKAGE)/man'); \
d<-sapply(fn, function(f)Rd2markdown(paste0('$(PACKAGE)/man/',f), sub('Rd','md',paste0('docs/',f))));\
file.copy(paste0(find.package('$(PACKAGE)'),'/html/00Index.html'), 'docs/index.html')" | $(R) --slave
R CMD Rdconv -t html $(PACKAGE)/man/sam.fit.Rd -o temp.html
sed -i '/page for sam.fit/d' temp.html
pandoc temp.html -t markdown_github -o docs/sam.fit.md; rm temp.html;
cd docs; sed -i '/<img/d; /DESCRIPTION/d; /User guides/d; s/html/md/' index.html
cd docs; pandoc index.html -t markdown_github -o index.md
cd docs; rm index.html
NPROCS:=1
OS:=$(shell uname -s)
ifeq ($(OS),Linux)
NPROCS:=$(shell grep -c ^processor /proc/cpuinfo)
endif
MAKEFLAGS += --silent
testmore:
$(MAKE) -j $(NPROCS) testmoreseq
testmoreseq: $(SUBDIRS)
testonemore:
@$(MAKE) testmore/$(ARG)/.
$(SUBDIRS):
@cp testmore/Makefile $@
@$(MAKE) -i -s -C $@
@rm -f $@/Makefile
webtestfromfile:
$(MAKE) -j $(NPROCS) webtest $$(< webteststocklist)
webtest: $(testfiles)
webtestone:
@wget -q -r -np -nH --cut-dirs=4 -R index.html* https://www.stockassessment.org/datadisk/stockassessment/userdirs/user3/$(ARG)/
@sed -i 's/useR = Rnewest/useR = R/' $(ARG)/Makefile
@sed -i 's/--vanilla/ /' $(ARG)/Makefile
@mv $(ARG)/run/model.RData $(ARG);
@rm -f $(ARG)/run/curver
@touch $(ARG)/data/*
@$(MAKE) -s -C $(ARG) model
@echo "load('$(ARG)/model.RData'); old<-tail(summary(fit),1); \
load('$(ARG)/run/model.RData'); new<-tail(summary(fit),1);\
cat('$(ARG)...',ifelse(all.equal(old,new,check.attributes=FALSE),'OK','FAIL'),'\n')" | R --slave
@touch $(ARG)/OK
$(testfiles):
@$(MAKE) -s webtestone $(@D)
@rm -rf $(@D)