summaryrefslogtreecommitdiffstats
path: root/build/linux/Makefile.in
blob: 14df491d5217e22d5aebe71301ea749134a305ed (plain)
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
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
install_type=@INSTALL_TYPE@

cuda=@HAVECUDA@
matlab=@HAVEMATLAB@
python=@HAVEPYTHON@
boostutf=@HAVEBOOSTUTF@
macos=@IS_MACOS@

MATLAB_ROOT=@MATLAB_ROOT@
octave=@HAVEOCTAVE@

MKDIR=mkdir -p
CXX=@CXX@
LD=@CXX@
SHELL=@SHELL@
INSTALL_SH=$(SHELL) $(srcdir)/install-sh

TARGETS=libastra.la

ifeq ($(matlab),yes)
TARGETS+=mex
endif

ifeq ($(python),yes)
TARGETS+=py
endif

ifeq ($(octave),yes)
TARGETS+=oct
endif

all: $(TARGETS)

prefix=@prefix@
exec_prefix=@exec_prefix@
datarootdir=@datarootdir@
includedir=@includedir@
libdir=@libdir@

srcdir=@srcdir@
abs_top_builddir=@abs_top_builddir@

VPATH=@VPATH_SRCDIR@/../..

CPPFLAGS=@SAVED_CPPFLAGS@
CXXFLAGS=@SAVED_CXXFLAGS@
NVCCFLAGS=@SAVED_NVCCFLAGS@
LDFLAGS=@SAVED_LDFLAGS@
LIBS=@SAVED_LIBS@

CXXFLAGS+=-g -O3 -Wall -Wshadow
LIBS+=-lpthread
LDFLAGS+=-g

CXXFLAGS+=@CXXFLAGS_OS@
LDFLAGS+=@LDFLAGS_OS@

BOOSTUTF_LIBS=@LIBS_BOOSTUTF@

ifeq ($(cuda),yes)
CPPFLAGS  += @CPPFLAGS_CUDA@ -DASTRA_CUDA
NVCCFLAGS += @NVCCFLAGS_EXTRA@ @CPPFLAGS_CUDA@ -I$(srcdir)/../../include -DASTRA_CUDA
LDFLAGS   += @LDFLAGS_CUDA@
LIBS      += -lcudart -lcufft
NVCC       = @NVCC@
endif

ifeq ($(matlab),yes)
# TODO: Do we also want -fopenmp for octave?
CPPFLAGS+=-I$(MATLAB_ROOT)/extern/include -DMATLAB_MEX_FILE
ifeq ($(macos),no)
CXXFLAGS+=-fopenmp
LDFLAGS+=-fopenmp
endif
endif

# MODLDFLAGS are the base LDFLAGS for matlab, octave, python modules
MODLDFLAGS=$(LDFLAGS) -L$(abs_top_builddir)/.libs
ifeq ($(install_type),module)
MODLDFLAGS+=-Wl,-rpath,'\$$ORIGIN'
endif

ifeq ($(python),yes)
PYTHON      = @PYTHON@
PYINCDIR := $(shell $(PYTHON) -c 'from __future__ import print_function; from distutils.sysconfig import get_python_inc; print(get_python_inc())')
PYLIBDIR := $(shell $(PYTHON) -c 'from distutils.sysconfig import get_config_var; import six; six.print_(get_config_var("LIBDIR"))')
PYLIBVER = `basename $(PYINCDIR)`
CPPFLAGS += -DASTRA_PYTHON -I$(PYINCDIR)
PYCPPFLAGS  := $(CPPFLAGS)
PYCPPFLAGS  += -I../include

# copy the current MODLDFLAGS to PYLDFLAGS, and then add flags for matlab/octave
PYLDFLAGS := $(MODLDFLAGS)
MODLDFLAGS += -L$(PYLIBDIR)

MODPYLIBS=-l$(PYLIBVER)
endif

# This is below where PYCPPFLAGS copies CPPFLAGS.  The python code is built
# from a different directory, so these relative includes would be wrong.
CPPFLAGS+=-I$(srcdir)/../../include -I$(srcdir)/../../lib/include

ifeq ($(matlab),yes)
MEXFLAGS  = -cxx
MEXLDFLAGS=\$$LDFLAGS $(MODLDFLAGS)
MEXLIBS   = -lut
MEXSUFFIX = @MEXSUFFIX@
MEX       = @MEX@

ifeq ($(cuda),yes)
MEXFLAGS += -DASTRA_CUDA
endif

endif


ifeq ($(octave),yes)
OCTLDFLAGS:=$(MODLDFLAGS)
CPPFLAGS += @OCTAVE_CPPFLAGS@
ifeq ($(cuda),yes)
OCTFLAGS=-DASTRA_CUDA
else
OCTFLAGS=
endif

endif


DEPDIR=.deps

BASE_OBJECTS=\
	src/Algorithm.lo \
	src/AsyncAlgorithm.lo \
	src/ReconstructionAlgorithm2D.lo \
	src/ReconstructionAlgorithm3D.lo \
	src/ArtAlgorithm.lo \
	src/AstraObjectFactory.lo \
	src/AstraObjectManager.lo \
	src/BackProjectionAlgorithm.lo \
	src/CglsAlgorithm.lo \
	src/CompositeGeometryManager.lo \
	src/ConeProjectionGeometry3D.lo \
	src/ConeVecProjectionGeometry3D.lo \
	src/Config.lo \
	src/DataProjector.lo \
	src/DataProjectorPolicies.lo \
	src/FanFlatBeamLineKernelProjector2D.lo \
	src/FanFlatBeamStripKernelProjector2D.lo \
	src/FanFlatProjectionGeometry2D.lo \
	src/FanFlatVecProjectionGeometry2D.lo \
	src/Features.lo \
	src/FilteredBackProjectionAlgorithm.lo \
	src/Filters.lo \
	src/Float32Data2D.lo \
	src/Float32Data3D.lo \
	src/Float32Data3DMemory.lo \
	src/Float32Data.lo \
	src/Float32ProjectionData2D.lo \
	src/Float32ProjectionData3D.lo \
	src/Float32ProjectionData3DMemory.lo \
	src/Float32VolumeData2D.lo \
	src/Float32VolumeData3D.lo \
	src/Float32VolumeData3DMemory.lo \
	src/ForwardProjectionAlgorithm.lo \
	src/Fourier.lo \
	src/GeometryUtil2D.lo \
	src/GeometryUtil3D.lo \
	src/Globals.lo \
	src/Logging.lo \
	src/ParallelBeamBlobKernelProjector2D.lo \
	src/ParallelBeamLinearKernelProjector2D.lo \
	src/ParallelBeamLineKernelProjector2D.lo \
	src/ParallelBeamStripKernelProjector2D.lo \
	src/ParallelProjectionGeometry2D.lo \
	src/ParallelVecProjectionGeometry2D.lo \
	src/ParallelProjectionGeometry3D.lo \
	src/ParallelVecProjectionGeometry3D.lo \
	src/PlatformDepSystemCode.lo \
	src/PluginAlgorithmFactory.lo \
	src/ProjectionGeometry2D.lo \
	src/ProjectionGeometry3D.lo \
	src/Projector2D.lo \
	src/Projector3D.lo \
	src/SartAlgorithm.lo \
	src/SirtAlgorithm.lo \
	src/SparseMatrixProjectionGeometry2D.lo \
	src/SparseMatrixProjector2D.lo \
	src/SparseMatrix.lo \
	src/Utilities.lo \
	src/VolumeGeometry2D.lo \
	src/VolumeGeometry3D.lo \
	src/XMLDocument.lo \
	src/XMLNode.lo

CUDA_CXX_OBJECTS=\
	src/CudaProjector2D.lo \
	src/CudaProjector3D.lo \
	src/CudaReconstructionAlgorithm2D.lo \
	src/CudaBackProjectionAlgorithm.lo \
	src/CudaDartMaskAlgorithm.lo \
	src/CudaDartMaskAlgorithm3D.lo \
	src/CudaDataOperationAlgorithm.lo \
	src/CudaRoiSelectAlgorithm.lo \
	src/CudaDartSmoothingAlgorithm.lo \
	src/CudaDartSmoothingAlgorithm3D.lo \
	src/CudaFilteredBackProjectionAlgorithm.lo \
	src/CudaForwardProjectionAlgorithm.lo \
	src/CudaSartAlgorithm.lo \
	src/CudaSirtAlgorithm.lo \
	src/CudaCglsAlgorithm.lo \
	src/CudaCglsAlgorithm3D.lo \
	src/CudaEMAlgorithm.lo \
	src/CudaFDKAlgorithm3D.lo \
	src/CudaSirtAlgorithm3D.lo \
	src/CudaBackProjectionAlgorithm3D.lo \
	src/CudaForwardProjectionAlgorithm3D.lo \
	src/Float32Data3DGPU.lo \
	src/Float32ProjectionData3DGPU.lo \
	src/Float32VolumeData3DGPU.lo

CUDA_OBJECTS=\
	cuda/2d/algo.lo \
	cuda/2d/par_fp.lo \
	cuda/2d/par_bp.lo \
	cuda/2d/fan_fp.lo \
	cuda/2d/fan_bp.lo \
	cuda/2d/fbp.lo \
	cuda/2d/sirt.lo \
	cuda/2d/sart.lo \
	cuda/2d/cgls.lo \
	cuda/2d/em.lo \
	cuda/2d/astra.lo \
	cuda/2d/util.lo \
	cuda/2d/arith.lo \
	cuda/2d/fft.lo \
	cuda/2d/darthelper.lo \
	cuda/3d/darthelper3d.lo \
	cuda/3d/algo3d.lo \
	cuda/3d/cgls3d.lo \
	cuda/3d/cone_fp.lo \
	cuda/3d/cone_bp.lo \
	cuda/3d/fdk.lo \
	cuda/3d/par3d_fp.lo \
	cuda/3d/par3d_bp.lo \
	cuda/3d/sirt3d.lo \
	cuda/3d/astra3d.lo \
	cuda/3d/util3d.lo \
	cuda/3d/arith3d.lo \
	cuda/3d/mem3d.lo

ALL_OBJECTS=$(BASE_OBJECTS)
ifeq ($(cuda),yes)
ALL_OBJECTS+=$(CUDA_CXX_OBJECTS) $(CUDA_OBJECTS)
endif

TEST_OBJECTS=\
	tests/main.o \
	tests/test_AstraObjectManager.o \
	tests/test_ParallelBeamLineKernelProjector2D.o \
	tests/test_ParallelBeamLinearKernelProjector2D.o \
	tests/test_Float32Data2D.o \
	tests/test_VolumeGeometry2D.o \
	tests/test_ParallelProjectionGeometry2D.o \
	tests/test_FanFlatProjectionGeometry2D.o \
	tests/test_Float32VolumeData2D.o \
	tests/test_Float32ProjectionData2D.o \
	tests/test_Fourier.o \
	tests/test_XMLDocument.o

MATLAB_CXX_OBJECTS=\
	matlab/mex/mexHelpFunctions.o \
	matlab/mex/mexCopyDataHelpFunctions.o \
	matlab/mex/mexInitFunctions.o \
	matlab/mex/mexDataManagerHelpFunctions.o

MATLAB_MEX=\
	matlab/mex/astra_mex_algorithm_c.$(MEXSUFFIX) \
	matlab/mex/astra_mex_data2d_c.$(MEXSUFFIX) \
	matlab/mex/astra_mex_c.$(MEXSUFFIX) \
	matlab/mex/astra_mex_matrix_c.$(MEXSUFFIX) \
	matlab/mex/astra_mex_projector_c.$(MEXSUFFIX) \
	matlab/mex/astra_mex_projector3d_c.$(MEXSUFFIX) \
	matlab/mex/astra_mex_log_c.$(MEXSUFFIX) \
	matlab/mex/astra_mex_data3d_c.$(MEXSUFFIX) \
	matlab/mex/astra_mex_direct_c.$(MEXSUFFIX)

OCTAVE_CXX_OBJECTS=\
	matlab/mex/octave_support.o

OCTAVE_MEX=\
	matlab/mex/astra_mex_algorithm_c.mex \
	matlab/mex/astra_mex_data2d_c.mex \
	matlab/mex/astra_mex_c.mex \
	matlab/mex/astra_mex_matrix_c.mex \
	matlab/mex/astra_mex_projector_c.mex \
	matlab/mex/astra_mex_projector3d_c.mex \
	matlab/mex/astra_mex_log_c.mex \
	matlab/mex/astra_mex_data3d_c.mex \
	matlab/mex/astra_mex_direct_c.mex

ifeq ($(python),yes)
MATLAB_MEX+=matlab/mex/astra_mex_plugin_c.$(MEXSUFFIX)
OCTAVE_MEX+=matlab/mex/astra_mex_plugin_c.mex
endif


OBJECT_DIRS = src/ tests/ cuda/2d/ cuda/3d/ matlab/mex/ ./
DEPDIRS = $(addsuffix $(DEPDIR),$(OBJECT_DIRS))
-include $(wildcard $(addsuffix /*.d,$(DEPDIRS)))
LIBDIRS = $(addsuffix .libs,./ src/ cuda/2d/ cuda/3d/)

SONAME=$(shell . ${abs_top_builddir}/libastra.la; echo $$dlname)

ifeq ($(matlab),yes)
mex: $(MATLAB_MEX)

%.$(MEXSUFFIX): %.o $(MATLAB_CXX_OBJECTS) libastra.la
	$(MEX) LDFLAGS="$(MEXLDFLAGS)" $(MEXFLAGS) $(LIBS) $(MEXLIBS) -lastra -output $* $*.o $(MATLAB_CXX_OBJECTS)
ifeq ($(install_type),module)
ifeq ($(macos),yes)
	@# tell macOS dynamic loader to look in mex directory for libastra.0.dylib
	@# CHECKME: some versions of otool return a two-line output for otool -DX?
	@# (xcode 8.2.1 / macos 10.11.6 ?)
	install_name_tool -change `otool -DX .libs/$(SONAME) | tail -n 1` @loader_path/$(SONAME) $@
endif
endif

ifeq ($(python),yes)
matlab/mex/astra_mex_plugin_c.$(MEXSUFFIX): matlab/mex/astra_mex_plugin_c.o $(MATLAB_CXX_OBJECTS) libastra.la
	$(MEX) LDFLAGS="$(MEXLDFLAGS)" $(MEXFLAGS) $(LIBS) $(MEXLIBS) $(MODPYLIBS) -lastra -output matlab/mex/astra_mex_plugin_c $< $(MATLAB_CXX_OBJECTS)
endif
endif

ifeq ($(python),yes)
py: libastra.la
	$(MKDIR) python/build
# TODO: Avoid writing into source dir
	ln -s $(abs_top_builddir)/.libs/$(SONAME) $(srcdir)/../../python/astra
# Note: setting CC to CXX is intentional. Python uses CC for compilation even if input is C++.
	(cd $(srcdir)/../../python; ASTRA_INSTALL_LIBRARY_AS_DATA=$(PYPKGDATA) CXX="${CXX}" CC="${CXX}" CPPFLAGS="${PYCPPFLAGS}" LDFLAGS='${PYLDFLAGS}' $(PYTHON) builder.py build --build-base=$(abs_top_builddir)/python/build) || (rm $(srcdir)/../../python/astra/$(SONAME); false)
	rm $(srcdir)/../../python/astra/$(SONAME)

endif


ifeq ($(octave),yes)
oct: $(OCTAVE_MEX)

%.mex: %.o $(MATLAB_CXX_OBJECTS) $(OCTAVE_CXX_OBJECTS) libastra.la
	mkoctfile --mex $(OCTFLAGS) $(OCTLDFLAGS) $(LIBS) -lastra --output $* $*.o $(MATLAB_CXX_OBJECTS) $(OCTAVE_CXX_OBJECTS)

ifeq ($(python),yes)
matlab/mex/astra_mex_plugin_c.mex: matlab/mex/astra_mex_plugin_c.o $(MATLAB_CXX_OBJECTS) $(OCTAVE_CXX_OBJECTS) libastra.la
	mkoctfile --mex $(OCTFLAGS) $(OCTLDFLAGS) $(LIBS) $(MODPYLIBS) -lastra --output matlab/mex/astra_mex_plugin_c $< $(MATLAB_CXX_OBJECTS) $(OCTAVE_CXX_OBJECTS)
endif
endif

libastra.la: $(ALL_OBJECTS)
	./libtool --mode=link --tag=CXX $(LD) -rpath $(libdir) -o $@ $(LDFLAGS) $(LIBS) $+

%.o: %.cpp
	$(MKDIR) $(*D)/$(DEPDIR)
	$(CXX) -Wp,-MMD,"$(*D)/$(DEPDIR)/$(*F).d",-MQ,"$@",-MP $(CXXFLAGS) -fPIC -DPIC $(CPPFLAGS) -c $(<) -o $*.o

%.lo: %.cpp
	$(MKDIR) $(*D)/$(DEPDIR)
	./libtool --mode=compile --tag=CXX $(CXX) -Wp,-MMD,"$(*D)/$(DEPDIR)/$(*F).d",-MQ,"$@",-MP $(CXXFLAGS) $(CPPFLAGS) -c $(<) -o $*.o

gen_static_libs := `./libtool --features | grep -q 'disable static' && echo no || echo yes`

ifeq ($(cuda),yes)
%.lo: %.cu
	@# Behave like libtool: compile both a PIC and a non-PIC object file
	@$(MKDIR) $(*D)
	@$(MKDIR) $(*D)/.libs
	@$(MKDIR) $(*D)/$(DEPDIR)
	$(NVCC) $(NVCCFLAGS) -c $(<) -Xcompiler -fPIC -DPIC -o $(*D)/.libs/$(*F).o
ifeq ($(gen_static_libs),yes)
	@$(NVCC) $(NVCCFLAGS) -c $(<) -o $*.o >/dev/null 2>&1
endif
	@# Generate a .d file, and change the target name in it from .o to .lo
	@# CUDA 5.5's nvcc doesn't have the -MT option we would like to use.
	@$(NVCC) $(NVCCFLAGS) -M $(<) -odir $(*D) -o $(*D)/$(DEPDIR)/$(*F).d2
	@sed '1s/\.o :/.lo :/' < $(*D)/$(DEPDIR)/$(*F).d2 > $(*D)/$(DEPDIR)/$(*F).d
	@rm -f $(*D)/$(DEPDIR)/$(*F).d2
	@# Generate empty targets for all dependencies listed in the .d file.
	@# This mimics gcc's -MP option.
	@for x in `cat $(*D)/$(DEPDIR)/$(*F).d`; do if test a$$x != a: -a a$$x != a\\; then (echo; echo "$$x:") >> $(*D)/$(DEPDIR)/$(*F).d; fi; done
	@# Generate a fake libtool .lo file
	@echo "# $*.lo - a libtool object file" > $*.lo
	@echo "# Generated by" `./libtool --version | head -n 1` >> $*.lo
	@echo "#" >> $*.lo
	@echo "# Please DO NOT delete this file!" >> $*.lo
	@echo "# It is necessary for linking the library." >> $*.lo
	@echo >> $*.lo
	@echo "# Name of the PIC object." >> $*.lo
	@echo "pic_object='.libs/$(*F).o'" >> $*.lo
	@echo >> $*.lo
	@echo "# Name of the non-PIC object." >> $*.lo
ifeq ($(gen_static_libs),yes)
	@echo "non_pic_object='$(*F).o'" >> $*.lo
else
	@echo "non_pic_object=none" >> $*.lo
endif
	@# Remove generated .linkinfo file
	@rm -f $(*F).linkinfo
endif

ifeq ($(boostutf),yes)
test.bin: $(ALL_OBJECTS) $(TEST_OBJECTS)
	./libtool --mode=link $(LD) -o $@ $(LDFLAGS) $+ $(LIBS) $(BOOSTUTF_LIBS)

test: test.bin
	./test.bin
else
test:
	@echo "Tests have been disabled by configure"
endif

clean:
	rm -f $(MATLAB_MEX) libastra.la
	rm -f $(addsuffix /*.lo,$(OBJECT_DIRS))
	rm -f $(addsuffix /*.o,$(OBJECT_DIRS))
	rm -f $(addsuffix /*.d,$(DEPDIRS))
	rm -f $(addsuffix /*,$(LIBDIRS))
	rm -f $(TEST_OBJECTS) test.bin
	rm -fr python/finalbuild/
	rm -fr python/build/
	rm -f $(srcdir)/../../python/astra/*.cpp
	rm -f $(srcdir)/../../python/astra/*.c

distclean: clean
	rm -f $(srcdir)/config.guess $(srcdir)/config.sub $(srcdir)/ltmain.sh libtool $(srcdir)/install-sh
	rm -f config.log config.status
	rm -f $(srcdir)/aclocal.m4
	rm -rf $(srcdir)/autom4te.cache
	rm -f $(srcdir)/configure Makefile

install-libraries: libastra.la
	$(INSTALL_SH) -m 755 -d $(libdir)
	./libtool --mode=install $(INSTALL_SH) -m 644 libastra.la $(libdir)
	./libtool --mode=finish $(libdir)


# ------------------------
# INSTALLATION
# ------------------------

ifeq ($(install_type),prefix)
# libraries into @libdir@, python into site-packages, mex into @datadir@
install: install-libraries install-matlab install-python-site-packages install-octave

PYPKGDATA=
MATLABBASE=@datadir@/astra/matlab
OCTAVEBASE=@datadir@/astra/octave
endif

ifeq ($(install_type),dir)
# everything into @prefix@
install: install-libraries install-matlab install-python install-octave

PYPKGDATA=
MATLABBASE=@prefix@/matlab
OCTAVEBASE=@prefix@/octave
PYTHONBASE=@prefix@/python
endif

ifeq ($(install_type),module)
# python into site-packages, mex into @datadir@
# library copied into python/mex directories
# modules built with rpath=$ORIGIN
install: install-matlab install-python-site-packages install-octave

PYPKGDATA=$(SONAME)
MATLABBASE=@prefix@/matlab
OCTAVEBASE=@prefix@/octave

install-matlab-so: libastra.la
	$(INSTALL_SH) -m 755 -d $(MATLABBASE)/mex
	$(INSTALL_SH) -m 755 $(abs_top_builddir)/.libs/$(SONAME) $(MATLABBASE)/mex
install-octave-so: libastra.la
	$(INSTALL_SH) -m 755 -d $(OCTAVEBASE)/mex
	$(INSTALL_SH) -m 755 $(abs_top_builddir)/.libs/$(SONAME) $(OCTAVEBASE)/mex
else
install-matlab-so:
install-octave-so:
endif



ifeq ($(python),yes)
install-python: py
	$(MKDIR) python/finalbuild
	# Note: setting CC to CXX is intentional. Python uses CC for compilation even if input is C++.
	cd $(srcdir)/../../python; ASTRA_INSTALL_LIBRARY_AS_DATA=$(PYPKGDATA) CXX="${CXX}" CC="${CXX}" CPPFLAGS="${PYCPPFLAGS}" LDFLAGS="${PYLDFLAGS}" $(PYTHON) builder.py build --build-base=$(abs_top_builddir)/python/build install \
	--install-base=$(abs_top_builddir)/python/finalbuild --install-headers=$(abs_top_builddir)/python/finalbuild --install-purelib=$(abs_top_builddir)/python/finalbuild \
	--install-platlib=$(abs_top_builddir)/python/finalbuild --install-scripts=$(abs_top_builddir)/python/finalbuild --install-data=$(abs_top_builddir)/python/finalbuild
	$(INSTALL_SH) -m 755 -d @prefix@/python
	$(INSTALL_SH) -m 755 -d @prefix@/python/astra
	$(INSTALL_SH) -m 755 -d @prefix@/python/astra/plugins
	$(INSTALL_SH) -m 755 python/finalbuild/astra/*.so @prefix@/python/astra
	$(INSTALL_SH) -m 644 python/finalbuild/astra/*.py @prefix@/python/astra
	$(INSTALL_SH) -m 644 python/finalbuild/astra/plugins/*.py @prefix@/python/astra/plugins
	$(INSTALL_SH) -m 644 python/finalbuild/*.egg-info @prefix@/python/
# TODO: docs

install-python-site-packages: py
# Note: setting CC to CXX is intentional. Python uses CC for compilation even if input is C++.
	cd $(srcdir)/../../python; ASTRA_INSTALL_LIBRARY_AS_DATA=$(PYPKGDATA) CXX="${CXX}" CC="${CXX}" CPPFLAGS="${PYCPPFLAGS}" LDFLAGS="${PYLDFLAGS}" $(PYTHON) builder.py build --build-base=$(abs_top_builddir)/python/build install
else
install-python-site-packages:
install-python:
endif

ifeq ($(matlab),yes)
install-matlab: $(MATLAB_MEX) install-matlab-so
	$(INSTALL_SH) -m 755 -d $(MATLABBASE)
	$(INSTALL_SH) -m 755 -d $(MATLABBASE)/mex
	$(INSTALL_SH) -m 755 -d $(MATLABBASE)/tools
	$(INSTALL_SH) -m 755 -d $(MATLABBASE)/algorithms
	$(INSTALL_SH) -m 755 $(MATLAB_MEX) $(MATLABBASE)/mex
	$(INSTALL_SH) -m 644 $(srcdir)/../../matlab/tools/*.m $(MATLABBASE)/tools

	# TODO: there must be a more efficient way to do this than to create and fill every single folder
	# install plot_geom
	$(INSTALL_SH) -m 755 -d $(MATLABBASE)/algorithms/plot_geom
	$(INSTALL_SH) -m 644 $(srcdir)/../../matlab/algorithms/plot_geom/*.m $(MATLABBASE)/algorithms/plot_geom

	$(INSTALL_SH) -m 755 -d $(MATLABBASE)/algorithms/plot_geom/draw
	$(INSTALL_SH) -m 644 $(srcdir)/../../matlab/algorithms/plot_geom/draw/*.m $(MATLABBASE)/algorithms/plot_geom/draw

	$(INSTALL_SH) -m 755 -d $(MATLABBASE)/algorithms/plot_geom/stl
	$(INSTALL_SH) -m 644 $(srcdir)/../../matlab/algorithms/plot_geom/stl/*.stl $(MATLABBASE)/algorithms/plot_geom/stl

	$(INSTALL_SH) -m 755 -d $(MATLABBASE)/algorithms/plot_geom/util
	$(INSTALL_SH) -m 644 $(srcdir)/../../matlab/algorithms/plot_geom/util/*.m $(MATLABBASE)/algorithms/plot_geom/util

	$(INSTALL_SH) -m 755 -d $(MATLABBASE)/algorithms/plot_geom/util/parseargs
	$(INSTALL_SH) -m 644 $(srcdir)/../../matlab/algorithms/plot_geom/util/parseargs/* $(MATLABBASE)/algorithms/plot_geom/util/parseargs

	$(INSTALL_SH) -m 755 -d $(MATLABBASE)/algorithms/plot_geom/util/stlTools
	$(INSTALL_SH) -m 644 $(srcdir)/../../matlab/algorithms/plot_geom/util/stlTools/* $(MATLABBASE)/algorithms/plot_geom/util/stlTools

# TODO: docs
else
install-matlab:
endif


ifeq ($(octave),yes)
install-octave: $(OCTAVE_MEX) install-octave-so
	$(INSTALL_SH) -m 755 -d $(OCTAVEBASE)
	$(INSTALL_SH) -m 755 -d $(OCTAVEBASE)/mex
	$(INSTALL_SH) -m 755 -d $(OCTAVEBASE)/tools
	$(INSTALL_SH) -m 755 $(OCTAVE_MEX) $(OCTAVEBASE)/mex
	$(INSTALL_SH) -m 644 $(srcdir)/../../matlab/tools/*.m $(OCTAVEBASE)/tools
# TODO: docs
else
install-octave:
endif

ifeq ($(install_type),module)

install-dev:
	@echo "install-dev is not compatible with the 'module' install type."
	@echo "Please use 'prefix' or 'dir' instead."

install-headers:
	@echo "install-headers is not compatible with the 'module' install type."
	@echo "Please use 'prefix' or 'dir' instead."

else

install-headers:
	$(INSTALL_SH) -m 755 -d $(includedir)
	$(INSTALL_SH) -m 755 -d $(includedir)/astra
	$(INSTALL_SH) -m 755 -d $(includedir)/astra/cuda
	$(INSTALL_SH) -m 755 -d $(includedir)/astra/cuda/2d
	$(INSTALL_SH) -m 755 -d $(includedir)/astra/cuda/3d
	$(INSTALL_SH) -m 644 $(srcdir)/../../include/astra/*.h $(includedir)/astra
	$(INSTALL_SH) -m 644 $(srcdir)/../../include/astra/*.inl $(includedir)/astra
	$(INSTALL_SH) -m 644 $(srcdir)/../../include/astra/cuda/2d/*.h $(includedir)/astra/cuda/2d
	$(INSTALL_SH) -m 644 $(srcdir)/../../include/astra/cuda/3d/*.h $(includedir)/astra/cuda/3d

install-dev: install-libraries install-headers libastra.pc
	$(INSTALL_SH) -m 755 -d $(libdir)
	$(INSTALL_SH) -m 755 -d $(libdir)/pkgconfig/
	$(INSTALL_SH) -m 644 libastra.pc $(libdir)/pkgconfig/
endif


Makefile libastra.pc: %: $(srcdir)/%.in config.status
	CONFIG_HEADERS= CONFIG_LINKS= CONFIG_FILES=$@ $(SHELL) ./config.status

config.status: $(srcdir)/configure
	@echo "configure script has changed. Re-running it with last parameters"
	$(SHELL) ./config.status --recheck

$(srcdir)/configure: $(srcdir)/configure.ac
	@echo "configure.ac has been changed. Regenerating configure script"
	cd $(srcdir) && $(SHELL) ./autogen.sh

.PHONY: all mex test clean distclean install install-libraries py install-python-site-packages install-python install-octave install-matlab-so install-octave-so install-headers install-dev

# don't remove intermediate files:
.SECONDARY:

# disable all implicit built-in rules
.SUFFIXES: