forked from mrirecon/bart
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
509 lines (323 loc) · 9.34 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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
# Copyright 2013-2015. The Regents of the University of California.
# Copyright 2015-2016. Martin Uecker <[email protected]>
# 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 ?= /
PREFIX ?= usr/
BUILDTYPE = Linux
UNAME = $(shell uname -s)
NNAME = $(shell uname -n)
MYLINK=ln
ifeq ($(UNAME),Darwin)
BUILDTYPE = MacOSX
MYLINK = ln -s
endif
ifeq ($(BUILDTYPE), MacOSX)
MACPORTS ?= 1
endif
ifeq ($(BUILDTYPE), Linux)
# as the defaults changed on most Linux distributions
# explicitly specify non-deterministic archives to not break make
ARFLAGS ?= rsU
else
ARFLAGS ?= rs
endif
ifeq ($(UNAME),Cygwin)
BUILDTYPE = Cygwin
NOLAPACKE ?= 1
endif
ifeq ($(UNAME),CYGWIN_NET-10.0)
BUILDTYPE = Cygwin
NOLAPACKE ?= 1
endif
# 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) utests -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
# for symbols in backtraces
LDFLAGS += -rdynamic
endif
CXX ?= g++
# openblas
ifneq ($(BUILDTYPE), MacOSX)
BLAS_BASE ?= /usr/
else
ifeq ($(MACPORTS),1)
BLAS_BASE ?= /opt/local/
CPPFLAGS += -DUSE_MACPORTS
endif
BLAS_BASE ?= /usr/local/opt/openblas/
endif
# 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 are defined in build_targets.mk so that both CMake and Make can use the same definitions
# set values for TBASE TFLP TNUM TRECO TCALIB TMRI TSIM TIO in build_targets.mk
include build_targets.mk
MODULES = -lnum -lmisc -lnum -lmisc
MODULES_pics = -lgrecon -lsense -liter -llinops -lwavelet -llowrank -lnoncart
MODULES_sqpics = -lsense -liter -llinops -lwavelet -llowrank -lnoncart
MODULES_pocsense = -lsense -liter -llinops -lwavelet
MODULES_nlinv = -lnoir -liter
MODULES_bpsense = -lsense -lnoncart -liter -llinops -lwavelet
MODULES_itsense = -liter -llinops
MODULES_ecalib = -lcalib
MODULES_ecaltwo = -lcalib
MODULES_caldir = -lcalib
MODULES_walsh = -lcalib
MODULES_calmat = -lcalib
MODULES_cc = -lcalib
MODULES_ccapply = -lcalib
MODULES_estvar = -lcalib
MODULES_nufft = -lnoncart -liter -llinops
MODULES_rof = -liter -llinops
MODULES_bench = -lwavelet -llinops
MODULES_phantom = -lsimu
MODULES_bart = -lbox -lgrecon -lsense -lnoir -liter -llinops -lwavelet -llowrank -lnoncart -lcalib -lsimu -lsake -ldfwavelet
MODULES_sake = -lsake
MODULES_wave = -liter -lwavelet -llinops -lsense
MODULES_threshold = -llowrank -liter -ldfwavelet -llinops -lwavelet
MODULES_fakeksp = -lsense -llinops
MODULES_lrmatrix = -llowrank -liter -llinops
MODULES_estdims = -lnoncart -llinops
MODULES_ismrmrd = -lismrm
MODULES_wavelet = -llinops -lwavelet
MAKEFILES = $(root)/Makefiles/Makefile.*
-include Makefile.$(NNAME)
-include Makefile.local
-include $(MAKEFILES)
ifeq ($(ISMRMRD),1)
TMRI += ismrmrd
MODULES_bart += -lismrm
endif
ifeq ($(NOLAPACKE),1)
MODULES += -llapacke
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 test utest gputest $(TARGETS):
make MAKESTAGE=2 $(MAKECMDGOALS)
else
CPPFLAGS += $(DEPFLAG) -I$(srcdir)/
CFLAGS += -std=gnu11 -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
# sm_20 no longer supported in CUDA 9
GPUARCH_FLAGS ?=
NVCCFLAGS = -DUSE_CUDA -Xcompiler -fPIC -Xcompiler -fopenmp -O3 $(GPUARCH_FLAGS) -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
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
BLAS_H := -I$(BLAS_BASE)/include
ifeq ($(BUILDTYPE), MacOSX)
BLAS_L := -L$(BLAS_BASE)/lib -lopenblas
else
ifeq ($(NOLAPACKE),1)
BLAS_L := -L$(BLAS_BASE)/lib -llapack -lblas
CPPFLAGS += -Isrc/lapacke
else
BLAS_L := -L$(BLAS_BASE)/lib -llapacke -lblas
endif
endif
endif
CPPFLAGS += $(FFTW_H) $(BLAS_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
BLAS_L += -llapack -lblas -lgfortran -lquadmath
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) $(UTARGETS)) | tr ' ' '\n' >> .gitignore
doc/commands.txt: bart
./rules/update_commands.sh ./bart doc/commands.txt $(XTARGETS)
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)/[email protected]
UTESTS=$(shell $(root)/utests/utests-collect.sh ./utests/[email protected])
.SECONDEXPANSION:
$(UTARGETS): % : utests/utest.c utests/%.o $$(MODULES_%) $(MODULES)
$(CC) $(LDFLAGS) $(CFLAGS) -DUTESTS="$(UTESTS)" -o $@ $+ $(FFTW_L) $(CUDA_L) $(BLAS_L) -lm
# linker script version - does not work on MacOS X
# $(CC) $(LDFLAGS) -Wl,-Tutests/utests.ld $(CFLAGS) -o $@ $+ $(FFTW_L) $(CUDA_L) $(BLAS_L) -lm
clean:
rm -f `find $(srcdir) -name "*.o"`
rm -f utests/*.o
rm -f $(patsubst %, %, $(UTARGETS))
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
# automatic tests
# system tests
TOOLDIR=$(root)
TESTS_TMP=$(root)/tests/tmp/$$$$/
TESTS_OUT=$(root)/tests/out/
include $(root)/tests/*.mk
test: ${TESTS}
gputest: ${TESTS_GPU}
pythontest: ${TESTS_PYTHON}
# unit tests
# define space to faciliate running executables
define \n
endef
utests-all: $(UTARGETS)
$(patsubst %,$(\n)./%,$(UTARGETS))
utest: utests-all
@echo ALL UNIT TESTS PASSED.
endif # MAKESTAGE
install: bart $(root)/doc/commands.txt
install -d $(DESTDIR)/$(PREFIX)/bin/
install bart $(DESTDIR)/$(PREFIX)/bin/
install -d $(DESTDIR)/$(PREFIX)/share/doc/bart/
install $(root)/doc/*.txt $(root)/README $(DESTDIR)/$(PREFIX)/share/doc/bart/
install -d $(DESTDIR)/$(PREFIX)/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,%,$@)
# symbol table
bart.syms: bart
rules/make_symbol_table.sh bart bart.syms