INCDIR = /opt/local/include
INCADD = -I$(INCDIR) -I$(INCDIR)/mpich2

OPT = -O3 -DMPICH_IGNORE_CXX_SEEK #-DNDEBUG (disables important assertions)
DEB = -g -O0 -fno-inline -DMPICH_IGNORE_CXX_SEEK -DCOMBBLAS_DEBUG
COMPILER = mpicxx -std=c++14 -DTHREADED -fopenmp
FLAGS = $(DEB)
COMBBLAS = ..

#
# build Graph500 generator
#
$(COMBBLAS)/graph500-1.2/generator/libgraph_generator_seq.a:
	$(MAKE) -C $(COMBBLAS)/graph500-1.2/generator

CommGrid.o:	../CommGrid.cpp ../CommGrid.h
	$(COMPILER) $(FLAGS) $(INCADD) -c -o CommGrid.o ../CommGrid.cpp

mmio.o:	../mmio.c ../mmio.h
	mpicc $(FLAGS) $(INCADD) -c -o mmio.o ../mmio.c

MPIType.o:	../MPIType.cpp ../MPIType.h
	$(COMPILER) $(FLAGS) $(INCADD) -c -o MPIType.o ../MPIType.cpp

hash.o:	../hash.cpp ../hash.hpp
	$(COMPILER) $(FLAGS) $(INCADD) -c -o hash.o ../hash.cpp

MemoryPool.o:	../MemoryPool.cpp ../SpDefs.h
	$(COMPILER) $(FLAGS) $(INCADD) -c -o MemoryPool.o ../MemoryPool.cpp

TransposeTest.o: TransposeTest.cpp ../SpDCCols.cpp ../dcsc.cpp ../SpHelper.h ../SpParHelper.h ../SpParMat.cpp ../Friends.h ../ParFriends.h 
	$(COMPILER) $(INCADD) $(FLAGS) -c -o TransposeTest.o TransposeTest.cpp

IteratorTest.o: IteratorTest.cpp ../SpDCCols.cpp ../dcsc.cpp ../SpHelper.h ../SpParHelper.h ../SpParMat.cpp ../Friends.h ../ParFriends.h 
	$(COMPILER) $(INCADD) $(FLAGS) -c -o IteratorTest.o IteratorTest.cpp

MultTest.o: MultTest.cpp ../SpDCCols.cpp ../dcsc.cpp ../SpHelper.h ../SpParHelper.h ../SpParMat.cpp ../Friends.h ../ParFriends.h 
	$(COMPILER) $(INCADD) $(FLAGS) -c -o MultTest.o MultTest.cpp

MultTiming.o: MultTiming.cpp ../SpDCCols.cpp ../dcsc.cpp ../SpHelper.h ../SpParHelper.h ../SpParMat.cpp ../Friends.h ../ParFriends.h 
	$(COMPILER) $(INCADD) $(FLAGS) -c -o MultTiming.o MultTiming.cpp

ReduceTest.o: ReduceTest.cpp ../SpDCCols.cpp ../dcsc.cpp ../SpHelper.h ../SpParHelper.h ../SpParMat.cpp ../Friends.h ../ParFriends.h 
	$(COMPILER) $(INCADD) $(FLAGS) -c -o ReduceTest.o ReduceTest.cpp

VectorIndexing.o: VectorIndexing.cpp ../FullyDistSpVec.cpp ../FullyDistVec.cpp ../FullyDistSpVec.h ../FullyDistVec.h 
	$(COMPILER) $(INCADD) $(FLAGS) -c -o VectorIndexing.o VectorIndexing.cpp

VectorIO.o: VectorIOPermute.cpp ../FullyDistSpVec.cpp ../FullyDistVec.cpp ../FullyDistSpVec.h ../FullyDistVec.h 
	$(COMPILER) $(INCADD) $(FLAGS) -c -o VectorIO.o VectorIO.cpp


SplitMergeTest.o: SplitMergeTest.cpp ../FullyDistSpVec.cpp ../FullyDistVec.cpp ../FullyDistSpVec.h ../FullyDistVec.h 
	$(COMPILER) $(INCADD) $(FLAGS) -c -o SplitMergeTest.o SplitMergeTest.cpp

ParIOTest.o: ParIOTest.cpp ../SpDCCols.cpp ../dcsc.cpp ../SpHelper.h ../SpParHelper.h ../SpParMat.cpp ../Friends.h ../ParFriends.h  ../SpParHelper.cpp
	$(COMPILER) $(INCADD) $(FLAGS) -c -o ParIOTest.o ParIOTest.cpp

TransposeTest: MemoryPool.o CommGrid.o MPIType.o TransposeTest.o mmio.o
	$(COMPILER) $(FLAGS) $(INCADD) -o TransposeTest TransposeTest.o MemoryPool.o CommGrid.o MPIType.o mmio.o

MultTest: MemoryPool.o CommGrid.o MPIType.o MultTest.o mmio.o
	$(COMPILER) $(FLAGS) $(INCADD) -o MultTest MultTest.o MemoryPool.o CommGrid.o MPIType.o mmio.o

MultTime: MemoryPool.o CommGrid.o MPIType.o MultTiming.o mmio.o
	$(COMPILER) $(FLAGS) $(INCADD) -o MultTime MultTiming.o MemoryPool.o CommGrid.o MPIType.o mmio.o

IteratorTest: MemoryPool.o CommGrid.o MPIType.o IteratorTest.o mmio.o
	$(COMPILER) $(FLAGS) $(INCADD) -o IteratorTest IteratorTest.o MemoryPool.o CommGrid.o MPIType.o mmio.o

SplitMergeTest: MemoryPool.o CommGrid.o MPIType.o SplitMergeTest.o mmio.o $(COMBBLAS)/graph500-1.2/generator/libgraph_generator_seq.a
	$(COMPILER) $(FLAGS) $(INCADD) -o SplitMergeTest SplitMergeTest.o MemoryPool.o CommGrid.o MPIType.o mmio.o -L$(COMBBLAS)/graph500-1.2/generator -lgraph_generator_seq 

ReduceTest: MemoryPool.o CommGrid.o MPIType.o ReduceTest.o mmio.o
	$(COMPILER) $(FLAGS) $(INCADD) -o ReduceTest ReduceTest.o MemoryPool.o CommGrid.o MPIType.o mmio.o

VectorInd: MemoryPool.o CommGrid.o MPIType.o VectorIndexing.o mmio.o
	$(COMPILER) $(FLAGS) $(INCADD) -o VectorInd VectorIndexing.o MemoryPool.o CommGrid.o MPIType.o mmio.o

VectorIO: MemoryPool.o CommGrid.o MPIType.o VectorIO.o mmio.o
	$(COMPILER) $(FLAGS) $(INCADD) -o VectorIO VectorIO.o MemoryPool.o CommGrid.o MPIType.o mmio.o

ParIOMM: MemoryPool.o CommGrid.o MPIType.o ParIOTest.o mmio.o hash.o
	$(COMPILER) $(FLAGS) $(INCADD) -o ParIOMM ParIOTest.o MemoryPool.o CommGrid.o MPIType.o mmio.o hash.o

clean: 
	rm -f TransposeTest
	rm -f SplitMergeTest
	rm -f MultTest
	rm -f ReduceTest
	rm -f VectorInd
	rm -f VectorIOPerm
	rm -f IteratorTest
	rm -f ParIOMM
	rm -f MultTime
	rm -f *.o

cleanout:
	rm out.*
	rm err.*
