-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
206 lines (188 loc) · 6.4 KB
/
Copy pathMakefile
File metadata and controls
206 lines (188 loc) · 6.4 KB
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
## settings
SHELL := /bin/bash
.ONESHELL:
.SHELLFLAGS := -euo pipefail -c
## Package information
package_name := $(shell grep "^Package:" DESCRIPTION | sed "s/Package: //")
package_version := $(shell grep "^Version:" DESCRIPTION | sed "s/Version: //")
tarball_location := $(package_name)_$(package_version).tar.gz
## default target
.PHONY: help
help:
@grep -h -E '^[[:space:]]*[A-Za-z0-9_.-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| sed -E 's/^[[:space:]]*//' \
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[1;34m%-15s\033[m \xE2\x80\x94 %s\n", $$1, $$2}'
## This target are mainly included to
## ease the the development process of {talib}
## - The configure will always prefer system-level
## TA-Lib, which means that downstream installs/checks
## will be faster if pre-installed.
##
## NOTE: It currently only works UNIX.
.PHONY: TA-Lib
TA-Lib: ## Install TA-Lib on system (Requires sudo)
@if ! pkg-config --exists ta-lib; then \
cd src/ta-lib; \
sudo chmod +x ./autogen.sh; \
./autogen.sh && ./configure; \
make; \
sudo make install; \
sudo ldconfig; \
fi
## This target is a precursor to all
## targets either directly or recursively
## and its a good idea to run to prevent shenanigans
## when creating new S3 functions or similar.
.PHONY: document
document: fmt ## Document R package using {devtools}
@Rscript --verbose -e "devtools::document()"
## pkgdown
## Build the online documentation
## and preview the built site
.PHONY: pkgdown
pkgdown: ## Build {pkgdown} documentation
@$(MAKE) document
@Rscript -e "pkgdown::clean_site()"
@Rscript dev/favicons.R
@Rscript -e "pkgdown::init_site()"
@Rscript -e "pkgdown::build_site()"
@rm -rf pkgdown/favicon
@rmdir pkgdown 2>/dev/null || true
@Rscript -e "pkgdown::preview_site()"
.PHONY: build
build: document
@R CMD build . --no-build-vignettes --no-manual
.PHONY: install
install: build ## Install the R package
@R CMD INSTALL $(tarball_location) --no-multiarch
## benchmarking
## This target runs the full benchmark suite
## against {TTR} - if there is a need for modifying
## plots and such do it in the folder
.PHONY: bench
bench: ## Run benchmark(s) against {TTR}
@echo -e "Running full benchmark suite (overhead + TTR comparison)..."
@echo -e ""
@Rscript ./benchmark/run-all.R
@echo -e ""
@echo -e "Rendering benchmark/README.Rmd..."
@cd benchmark && Rscript -e "rmarkdown::render('README.Rmd', output_format = rmarkdown::github_document(html_preview = FALSE), clean = TRUE)"
## Checks
## check:
## This target is for R CMD checks during
## local development
## check-cran:
## This target is for full R CMD checks
## that uses the vendored TA-Lib primarily
## meant to be run before CRAN submissions
## or pushes to Github
##
## NOTE: There is no need to install the package
## before checks.
.PHONY: check
check: build ## Check R package
@R CMD check --no-multiarch --ignore-vignettes --no-manual $(tarball_location)
@$(MAKE) README
.PHONY: check-cran
check-cran: document ## Check R package (CRAN)
@R CMD build .
@R CMD check --install-args=--configure-args="--force-vendor" --as-cran --use-valgrind $(tarball_location)
@$(MAKE) README
## Test
## This target runs the unit-tests including
## the parity tests without conducting the full check suite
.PHONY: test
test: install parity-prepare ## Run unit-tests
@TALIB_PARITY_SNAPSHOT_DIR=$$(pwd)/tests/parity/snapshot \
Rscript --verbose -e "library(talib); testthat::test_dir('tests/testthat', stop_on_failure = TRUE)"
@rm -f codegen/parity/parity_gen
@rm -f tests/testthat/test-parity.R
@rm -rf tests/parity/snapshot
## Janitor
## clean:
## Deletes simple build artifacts
## purge:
## Uninstalls TA-Lib and restores the
## vendored folder to its original state
##
## NOTE:
## If the system library is installed, and the
## unistall fails, its no longer possible to uninstall
## but it can be fixed by reinstalling TA-Lib and then
## running purge again!
.PHONY: clean
clean: ## Remove artifacts
@rm -rf src/*.o
@rm -rf src/*.so
@rm -rf $(tarball_location)
@rm -rf src/Makevars
@rm -rf $(package_name).Rcheck
@rm -rf docs
.PHONY: purge
purge: clean ## Remove TA-Lib arifacts and system libraries
@if pkg-config --exists ta-lib; then \
(cd src/ta-lib && sudo $(MAKE) uninstall); \
fi
@git -C src/ta-lib restore --staged --worktree .
@git -C src/ta-lib clean -fdx
@Rscript -e "try(remove.packages('$(package_name)'))"
@rm -rf tests/parity/snapshot
@rm -f codegen/parity/parity_gen
.PHONY: fmt
fmt: ## Format code
@clang-format \
-style='{
BasedOnStyle: LLVM,
BinPackArguments: false,
BinPackParameters: false,
AlignAfterOpenBracket: AlwaysBreak,
AllowAllArgumentsOnNextLine: false,
ContinuationIndentWidth: 2
}' \
-i src/*.c src/*.h
@air format R
@air format tests/testthat
@rm -rf ./.clang-format
@cargo fmt --manifest-path codegen/Cargo.toml
.PHONY: codegen
codegen: ## Generate R wrappers and unit-tests
@cargo run --manifest-path codegen/Cargo.toml
$(MAKE) fmt
## Make helpers
##
## These helpers are not really meant to be run
## directly but are used internally to support the
## development in one form or the other
## Parity against upstream
## This target is an internal helper
## used for the test target which compares
## the output against upstream
.PHONY: parity-prepare
parity-prepare:
@CC=$${CC:-gcc}; \
if pkg-config --exists ta-lib; then \
$$CC -O2 -Wall -Wextra \
$$(pkg-config --cflags ta-lib) \
codegen/parity/parity_gen.c \
$$(pkg-config --libs ta-lib) -lm \
-o codegen/parity/parity_gen; \
else \
$$CC -O2 -Wall -Wextra \
-Isrc/ta-lib/local/include -Isrc/ta-lib/local/include/ta-lib \
codegen/parity/parity_gen.c \
src/ta-lib/local/lib/libta-lib.a -lm \
-o codegen/parity/parity_gen; \
fi
@TMPDIR=$$(mktemp -d); \
trap 'rm -rf "$$TMPDIR"' EXIT; \
mkdir -p "$$TMPDIR/csv" tests/parity/snapshot; \
Rscript codegen/parity/btc_to_csv.R "$$TMPDIR/btc.csv"; \
./codegen/parity/parity_gen "$$TMPDIR/btc.csv" "$$TMPDIR/csv"; \
Rscript codegen/parity/csv_to_rds.R "$$TMPDIR/csv" tests/parity/snapshot
@cp codegen/parity/test_parity_template.R tests/testthat/test-parity.R
## README
## Rebuild README
.PHONY: README
README:
@rm -rf README.md
@Rscript -e "rmarkdown::render('dev/README.Rmd', output_dir = '.', output_format = rmarkdown::github_document(html_preview = FALSE), clean = TRUE)"