forked from stan-dev/cmdstan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
243 lines (213 loc) · 8.14 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
##
# CmdStan users: if you need to customize make options,
# you should add variables to a new file called
# make/local (no file extension)
#
# A typical option might be:
# CXX = clang++
#
# Users should only need to set these variables:
# - CXX: The compiler to use. Expecting g++ or clang++.
# - O: Optimization level. Valid values are {s, 0, 1, 2, 3}.
# Default is 3.
# - O_STANC: Optimization level for compiling stanc.
# Valid values are {s, 0, 1, 2, 3}. Default is 0
# - STANCFLAGS: Extra options for calling stanc
##
# The default target of this Makefile is...
help:
-include $(HOME)/.config/stan/make.local # user-defined variables
-include make/local # user-defined variables
STAN ?= stan/
MATH ?= $(STAN)lib/stan_math/
RAPIDJSON ?= lib/rapidjson_1.1.0/
ifeq ($(OS),Windows_NT)
O_STANC ?= 3
endif
O_STANC ?= 0
INC_FIRST ?= -I src -I $(STAN)src -I $(RAPIDJSON)
USER_HEADER ?= $(dir $<)user_header.hpp
-include $(MATH)make/compiler_flags
-include $(MATH)make/dependencies
-include $(MATH)make/libraries
include make/stanc
include make/program
include make/tests
include make/command
ifneq ($(filter-out clean clean-% print-% help help-% manual stan-update/% stan-update stan-pr/%,$(MAKECMDGOALS)),)
-include $(patsubst %.cpp,%.d,$(STANC_TEMPLATE_INSTANTIATION_CPP))
-include src/cmdstan/stanc.d
endif
CMDSTAN_VERSION := 2.20.0
.PHONY: help
help:
@echo '--------------------------------------------------------------------------------'
@echo 'CmdStan v$(CMDSTAN_VERSION) help'
@echo ''
@echo ' Build CmdStan utilities:'
@echo ' > make build'
@echo ''
@echo ' This target will:'
@echo ' 1. Download the Stan compiler bin/stanc$(EXE).'
@echo ' 2. Build the print utility bin/print$(EXE) (deprecated; will be removed in v3.0)'
@echo ' 3. Build the stansummary utility bin/stansummary$(EXE)'
@echo ' 4. Build the diagnose utility bin/diagnose$(EXE)'
@echo ''
@echo ' Note: to build using multiple cores, use the -j option to make. '
@echo ' For 4 cores:'
@echo ' > make build -j4'
@echo ''
@echo ''
@echo ' Build a Stan program:'
@echo ''
@echo ' Given a Stan program at foo/bar.stan, build an executable by typing:'
@echo ' > make foo/bar$(EXE)'
@echo ''
@echo ' This target will:'
@echo ' 1. Build the Stan compiler and the print utility if not built.'
@echo ' 2. Use the Stan compiler to generate C++ code, foo/bar.hpp.'
@echo ' 3. Compile the C++ code using $(CC) $(CC_MAJOR).$(CC_MINOR) to generate foo/bar$(EXE)'
@echo ''
@echo ' Additional make options:'
@echo ' STANCFLAGS: defaults to "". These are extra options passed to bin/stanc$(EXE)'
@echo ' when generating C++ code. If you want to allow undefined functions in the'
@echo ' Stan program, either add this to make/local or the command line:'
@echo ' STANCFLAGS = --allow_undefined'
@echo ' USER_HEADER: when STANCFLAGS has --allow_undefined, this is the name of the'
@echo ' header file that is included. This defaults to "user_header.hpp" in the'
@echo ' directory of the Stan program.'
@echo ''
@echo ''
@echo ' Example - bernoulli model: examples/bernoulli/bernoulli.stan'
@echo ''
@echo ' 1. Build the model:'
@echo ' > make examples/bernoulli/bernoulli$(EXE)'
@echo ' 2. Run the model:'
ifeq ($(OS),Windows_NT)
@echo ' > examples\bernoulli\bernoulli$(EXE) sample data file=examples/bernoulli/bernoulli.data.R'
else
@echo ' > examples/bernoulli/bernoulli$(EXE) sample data file=examples/bernoulli/bernoulli.data.R'
endif
@echo ' 3. Look at the samples:'
ifeq ($(OS),Windows_NT)
@echo ' > bin\stansummary$(EXE) output.csv'
else
@echo ' > bin/stansummary$(EXE) output.csv'
endif
@echo ''
@echo ''
@echo ' Clean CmdStan:'
@echo ''
@echo ' Remove the built CmdStan tools:'
@echo ' > make clean-all'
@echo ''
@echo '--------------------------------------------------------------------------------'
.PHONY: help-dev
help-dev:
@echo '--------------------------------------------------------------------------------'
@echo 'CmdStan help for developers:'
@$(MAKE) print-compiler-flags
@echo ' - O_STANC (Opt for stanc): ' $(O_STANC)
@echo ''
@echo ' If this copy of CmdStan has been cloned using git,'
@echo ' before building CmdStan utilities the first time you need'
@echo ' to initialize the Stan repository with:'
@echo ' make stan-update'
@echo ''
@echo ''
@echo 'Developer relevant targets:'
@echo ' Stan management targets:'
@echo ' - stan-update : Initializes and updates the Stan repository'
@echo ' - stan-update/* : Updates the Stan repository to the specified'
@echo ' branch or commit hash.'
@echo ' - stan-revert : Reverts changes made to Stan library back to'
@echo ' what is in the repository.'
@echo ''
@echo 'Model related:'
@echo '- bin/stanc$(EXE): Build the Stan compiler.'
@echo '- bin/print$(EXE): Build the print utility. (deprecated)'
@echo '- bin/stansummary$(EXE): Build the print utility.'
@echo '- bin/diagnostic$(EXE): Build the diagnostic utility.'
@echo '- bin/libstanc.a : Build the Stan compiler static library (used in linking'
@echo ' bin/stanc$(EXE))'
@echo '- *$(EXE) : If a Stan model exists at *.stan, this target will build'
@echo ' the Stan model as an executable.'
@echo '- compile_info : prints compiler flags for compiling a CmdStan executable.'
@echo ''
@echo 'Documentation:'
@echo ' - manual: Build the Stan manual and the CmdStan user guide.'
@echo '--------------------------------------------------------------------------------'
.PHONY: build-mpi
build-mpi: $(MPI_TARGETS)
@echo ''
@echo '--- boost mpi bindings built ---'
.PHONY: build
build: bin/stanc$(EXE) bin/stansummary$(EXE) bin/print$(EXE) bin/diagnose$(EXE) $(LIBSUNDIALS) $(MPI_TARGETS) $(TBB_TARGETS) $(CMDSTAN_MAIN_O)
@echo ''
ifeq ($(OS),Windows_NT)
@echo 'NOTE: Please add $(TBB_BIN_ABSOLUTE_PATH) to your PATH variable.'
@echo 'You may call'
@echo ''
@echo 'mingw32-make install-tbb'
@echo ''
@echo 'to automatically update your user configuration.'
endif
@echo '--- CmdStan v$(CMDSTAN_VERSION) built ---'
ifeq ($(CXX_TYPE),clang)
build: $(STAN)src/stan/model/model_header.hpp.gch
endif
.PHONY: install-tbb
install-tbb: $(TBB_TARGETS)
ifeq ($(OS),Windows_NT)
$(shell echo "cmd.exe /C install-tbb.bat")
endif
##
# Clean up.
##
.PHONY: clean clean-deps clean-manual clean-all
clean: clean-manual
$(RM) -r test
$(RM) $(wildcard $(patsubst %.stan,%.hpp,$(TEST_MODELS)))
$(RM) $(wildcard $(patsubst %.stan,%$(EXE),$(TEST_MODELS)))
clean-deps:
@echo ' removing dependency files'
$(shell find src $(STAN)src/stan $(MATH)stan -type f -name '*.d' -exec rm {} +)
$(shell find src $(STAN)src/stan $(MATH)stan -type f -name '*.d.*' -exec rm {} +)
$(shell find src $(STAN)src/stan $(MATH)stan -type f -name '*.dSYM' -exec rm {} +)
clean-manual:
$(RM) -r doc
cd src/docs/cmdstan-guide; $(RM) *.brf *.aux *.bbl *.blg *.log *.toc *.pdf *.out *.idx *.ilg *.ind *.cb *.cb2 *.upa
clean-all: clean clean-deps clean-libraries clean-manual
$(RM) -r bin
$(RM) -r $(CMDSTAN_MAIN_O)
$(RM) $(wildcard $(STAN)src/stan/model/model_header.hpp.gch)
##
# Submodule related tasks
##
.PHONY: stan-update
stan-update :
git submodule update --init --recursive
stan-update/%: stan-update
cd stan && git fetch --all && git checkout $* && git pull
stan-pr/%: stan-update
cd stan && git reset --hard origin/develop && git checkout $* && git checkout develop && git merge $* --ff --no-edit --strategy=ours
.PHONY: stan-revert
stan-revert:
git submodule update --init --recursive
##
# Manual related
##
.PHONY: src/docs/cmdstan-guide/cmdstan-guide.tex
manual: src/docs/cmdstan-guide/cmdstan-guide.pdf
mkdir -p doc
mv -f src/docs/cmdstan-guide/cmdstan-guide.pdf doc/cmdstan-guide-$(CMDSTAN_VERSION).pdf
%.pdf: %.tex
cd $(dir $@); latexmk -pdf -pdflatex="pdflatex -file-line-error" -use-make $(notdir $^)
.PHONY: compile_info
compile_info:
@echo '$(LINK.cpp) $(CXXFLAGS_PROGRAM) $(CMDSTAN_MAIN_O) $(LDLIBS) $(LIBSUNDIALS) $(MPI_TARGETS) $(TBB_TARGETS)'
##
# Debug target that allows you to print a variable
##
.PHONY: print-%
print-% : ; @echo $* = $($*)