forked from mrirecon/bart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
442 lines (273 loc) · 8.13 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
# Copyright 2013-2015. The Regents of the University of California.
# Copyright 2015-2016. Martin Uecker <martin.uecker@med.uni-goettingen.de>
# All rights reserved. Use of this source code is governed by
# a BSD-style license which can be found in the LICENSE file.
# we have a two stage Makefile
MAKESTAGE ?= 1
# silent make
#MAKEFLAGS += --silent
# clear out all implicit rules and variables
MAKEFLAGS += -R
# use for parallel make
AR=./ar_lock.sh
CUDA?=0
ACML?=0
OMP?=1
SLINK?=0
DEBUG?=0
FFTWTHREADS?=1
ISMRMRD?=0
DESTDIR ?= /
BUILDTYPE = Linux
UNAME = $(shell uname -s)
NNAME = $(shell uname -n)
MYLINK=ln
ifeq ($(UNAME),Darwin)
BUILDTYPE = MacOSX
MYLINK = ln -s
endif
ARFLAGS = r
# Paths
here = $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
root := $(here)
srcdir = $(root)/src
libdir = $(root)/lib
bindir = $(root)/bin
export TOOLBOX_PATH=$(root)
# Automatic dependency generation
DEPFILE = $(*D)/.$(*F).d
DEPFLAG = -MMD -MF $(DEPFILE)
ALLDEPS = $(shell find $(srcdir) -name ".*.d")
# Compilation flags
OPT = -O3 -ffast-math
CPPFLAGS ?= -Wall -Wextra
CFLAGS ?= $(OPT) -Wmissing-prototypes
CXXFLAGS ?= $(OPT)
ifeq ($(BUILDTYPE), MacOSX)
CC ?= gcc-mp-4.7
else
CC ?= gcc
endif
CXX ?= g++
# cuda
CUDA_BASE ?= /usr/local/
# acml
ACML_BASE ?= /usr/local/acml/acml4.4.0/gfortran64_mp/
# fftw
ifneq ($(BUILDTYPE), MacOSX)
FFTW_BASE ?= /usr/
else
FFTW_BASE ?= /opt/local/
endif
# Matlab
MATLAB_BASE ?= /usr/local/matlab/
# ISMRM
ISMRM_BASE ?= /usr/local/ismrmrd/
# Main build targets
TBASE=show slice crop resize join transpose zeros ones flip circshift extract repmat bitmask reshape version
TFLP=scale conj fmac saxpy sdot spow cpyphs creal carg normalize cdf97 pattern nrmse mip wavg
TNUM=fft fftmod fftshift noise bench threshold conv rss filter
TRECO=pics pocsense rsense sqpics bpsense itsense nlinv nufft rof sake wave lrmatrix estdims
TCALIB=ecalib ecaltwo caldir walsh cc calmat svd estvar
TMRI=homodyne poisson twixread fakeksp
TSIM=phantom traj
TIO=toimg
MODULES = -lnum -lmisc -lnum -lmisc
MODULES_pics = -lsense -lwavelet2 -liter -llinops -lwavelet3 -llowrank -lnoncart
MODULES_sqpics = -lsense -lwavelet2 -liter -llinops -lwavelet3 -llowrank -lnoncart
MODULES_pocsense = -lsense -lwavelet2 -liter -llinops
MODULES_nlinv = -lnoir -liter
MODULES_rsense = -lgrecon -lsense -lnoir -lwavelet2 -lcalib -liter -llinops
MODULES_bpsense = -lsense -lwavelet2 -lnoncart -liter -llinops
MODULES_itsense = -liter -llinops
MODULES_ecalib = -lcalib
MODULES_ecaltwo = -lcalib
MODULES_caldir = -lcalib
MODULES_walsh = -lcalib
MODULES_calmat = -lcalib
MODULES_cc = -lcalib
MODULES_estvar = -lcalib
MODULES_nufft = -lnoncart -liter -llinops
MODULES_rof = -liter -llinops
MODULES_bench = -lwavelet2 -lwavelet3 -llinops
MODULES_phantom = -lsimu
MODULES_bart = -lbox -lgrecon -lsense -lnoir -lwavelet2 -liter -llinops -lwavelet3 -llowrank -lnoncart -lcalib -lsimu -lsake -ldfwavelet
MODULES_sake = -lsake
MODULES_wave = -liter -lwavelet2 -llinops -lsense
MODULES_threshold = -llowrank -lwavelet2 -liter -ldfwavelet -llinops
MODULES_fakeksp = -lsense -llinops
MODULES_lrmatrix = -llowrank -liter -llinops
MODULES_estdims = -lnoncart -llinops
MODULES_ismrmrd = -lismrm
-include Makefile.$(NNAME)
-include Makefile.local
ifeq ($(ISMRMRD),1)
TMRI += ismrmrd
MODULES_bart += -lismrm
endif
XTARGETS += $(TBASE) $(TFLP) $(TNUM) $(TIO) $(TRECO) $(TCALIB) $(TMRI) $(TSIM)
TARGETS = bart $(XTARGETS)
ifeq ($(DEBUG),1)
CPPFLAGS += -g
CFLAGS += -g
endif
ifeq ($(PARALLEL),1)
MAKEFLAGS += -j
endif
ifeq ($(MAKESTAGE),1)
.PHONY: doc/commands.txt $(TARGETS)
default all clean allclean distclean doc/commands.txt doxygen $(TARGETS):
make MAKESTAGE=2 $(MAKECMDGOALS)
else
CPPFLAGS += $(DEPFLAG) -I$(srcdir)/
CFLAGS += -std=c99 -I$(srcdir)/
CXXFLAGS += -I$(srcdir)/
default: bart doc/commands.txt .gitignore
-include $(ALLDEPS)
# cuda
NVCC = $(CUDA_BASE)/bin/nvcc
ifeq ($(CUDA),1)
CUDA_H := -I$(CUDA_BASE)/include
CPPFLAGS += -DUSE_CUDA $(CUDA_H)
ifeq ($(BUILDTYPE), MacOSX)
CUDA_L := -L$(CUDA_BASE)/lib -lcufft -lcudart -lcublas -m64 -lstdc++
else
CUDA_L := -L$(CUDA_BASE)/lib64 -lcufft -lcudart -lcublas -lstdc++ -Wl,-rpath $(CUDA_BASE)/lib64
endif
else
CUDA_H :=
CUDA_L :=
endif
NVCCFLAGS = -DUSE_CUDA -Xcompiler -fPIC -Xcompiler -fopenmp -O3 -arch=sm_20 -I$(srcdir)/ -m64 -ccbin $(CC)
#NVCCFLAGS = -Xcompiler -fPIC -Xcompiler -fopenmp -O3 -I$(srcdir)/
%.o: %.cu
$(NVCC) $(NVCCFLAGS) -c $^ -o $@
$(NVCC) $(NVCCFLAGS) -M $^ -o $(DEPFILE)
# OpenMP
ifeq ($(OMP),1)
CFLAGS += -fopenmp
CXXFLAGS += -fopenmp
else
CFLAGS += -Wno-unknown-pragmas
CXXFLAGS += -Wno-unknown-pragmas
endif
# BLAS/LAPACK
BLAS_H :=
BLAS_L :=
ifeq ($(ACML),1)
BLAS_H := -I$(ACML_BASE)/include
BLAS_L := -L$(ACML_BASE)/lib -lgfortran -lacml_mp -Wl,-rpath $(ACML_BASE)/lib
CPPFLAGS += -DUSE_ACML
else
ifeq ($(BUILDTYPE), MacOSX)
BLAS_L := -lblas -framework Accelerate
else
BLAS_L := -llapack -lblas #-lgfortran
endif
endif
CPPFLAGS += $(FFTW_H)
# png
PNG_L := -lpng
ifeq ($(SLINK),1)
PNG_L += -lz
endif
# fftw
FFTW_H := -I$(FFTW_BASE)/include/
FFTW_L := -L$(FFTW_BASE)/lib -lfftw3f
ifeq ($(FFTWTHREADS),1)
FFTW_L += -lfftw3f_threads
CPPFLAGS += -DFFTWTHREADS
endif
# Matlab
MATLAB_H := -I$(MATLAB_BASE)/extern/include
MATLAB_L := -Wl,-rpath $(MATLAB_BASE)/bin/glnxa64 -L$(MATLAB_BASE)/bin/glnxa64 -lmat -lmx -lm -lstdc++
# ISMRM
ifeq ($(ISMRMRD),1)
ISMRM_H := -I$(ISMRM_BASE)/include
ISMRM_L := -L$(ISMRM_BASE)/lib -lismrmrd
else
ISMRM_H :=
ISMRM_L :=
endif
# change for static linking
ifeq ($(SLINK),1)
# work around fortran problems with static linking
LDFLAGS += -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -Wl,--allow-multiple-definition
ifneq ($(BUILDTYPE), MacOSX)
BLAS_L += -lgfortran
endif
endif
# Modules
.LIBPATTERNS := lib%.a
vpath %.a lib
DIRS = $(root)/rules/*.mk
include $(DIRS)
# sort BTARGETS after everything is included
BTARGETS:=$(sort $(BTARGETS))
XTARGETS:=$(sort $(XTARGETS))
.gitignore: .gitignore.main Makefile*
@echo '# AUTOGENERATED. DO NOT EDIT. (are you looking for .gitignore.main ?)' > .gitignore
cat .gitignore.main >> .gitignore
@echo $(patsubst %, /%, $(TARGETS)) | tr ' ' '\n' >> .gitignore
doc/commands.txt: bart
@echo AUTOGENERATED. DO NOT EDIT. > doc/commands.new
for cmd in $(XTARGETS) ; do \
printf "\n\n--%s--\n\n" $$cmd ; \
./bart $$cmd -h ; \
done >> doc/commands.new
$(root)/rules/update-if-changed.sh doc/commands.new doc/commands.txt
doxygen: makedoc.sh doxyconfig bart
./makedoc.sh
all: .gitignore $(TARGETS)
# special targets
$(XTARGETS): CPPFLAGS += -DMAIN_LIST="$(XTARGETS:%=%,) ()" -include src/main.h
bart: CPPFLAGS += -DMAIN_LIST="$(XTARGETS:%=%,) ()" -include src/main.h
mat2cfl: $(srcdir)/mat2cfl.c -lnum -lmisc
$(CC) $(CFLAGS) $(MATLAB_H) -omat2cfl $+ $(MATLAB_L) $(CUDA_L)
# implicit rules
%.o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
%.o: %.cc
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
ifeq ($(PARALLEL),1)
(%): %
$(AR) $(ARFLAGS) $@ $%
else
(%): %
$(AR) $(ARFLAGS) $@ $%
rm $%
endif
# we add the rm because intermediate files are not deleted
# automatically for some reason
# (but it produces errors for parallel builds for make all)
.SECONDEXPANSION:
$(TARGETS): % : src/main.c $(srcdir)/%.o $$(MODULES_%) $(MODULES)
$(CC) $(LDFLAGS) $(CFLAGS) -Dmain_real=main_$@ -o $@ $+ $(FFTW_L) $(CUDA_L) $(BLAS_L) $(PNG_L) $(ISMRM_L) -lm
# rm $(srcdir)/$@.o
clean:
rm -f `find $(srcdir) -name "*.o"`
rm -f $(root)/lib/.*.lock
allclean: clean
rm -f $(libdir)/*.a $(ALLDEPS)
rm -f $(patsubst %, %, $(TARGETS))
rm -f $(srcdir)/misc/version.inc
rm -rf doc/dx
rm -f doc/commands.txt
distclean: allclean
endif # MAKESTAGE
install: bart $(root)/doc/commands.txt
install -d $(DESTDIR)/usr/bin/
install bart $(DESTDIR)/usr/bin/
install -d $(DESTDIR)/usr/share/doc/bart/
install $(root)/doc/*.txt $(root)/README $(DESTDIR)/usr/share/doc/bart/
install -d $(DESTDIR)/usr/lib/bart/commands/
# generate release tar balls (identical to github)
%.tar.gz:
git archive --prefix=bart-$(patsubst bart-%.tar.gz,%,$@)/ -o $@ v$(patsubst bart-%.tar.gz,%,$@)
# automatic tests
TOOLDIR=$(root)
TESTS_TMP=$(root)/tests/tmp/
TESTS_OUT=$(root)/tests/out/
include $(root)/tests/*.mk
test:
PARALLEL=0 make ${TESTS}