# @configure_input@

# Package-related substitution variables
package	= @PACKAGE_NAME@
version	= @PACKAGE_VERSION@
tarname	= @PACKAGE_TARNAME@
distdir	= $(tarname)-$(version)

# Prefix-related substitution variables
prefix	 = @prefix@
exec_prefix    = @exec_prefix@
bindir	 = @bindir@
libdir	 = @libdir@

# Tool-related substitution variables
CXX		         = @CXX@
CXXFLAGS       = @CXXFLAGS@
LIBS	         = @LIBS@
DEFS           = @DEFS@
INSTALL	       = @INSTALL@
INSTALL_DATA   = @INSTALL_DATA@
INSTALL_PROGRAM= @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
CUDA_CFLAGS    = @CUDA_CFLAGS@
CUDA_LIBS      = @CUDA_LIBS@
CUDA_LDFLAGS   = @CUDA_LDFLAGS@
NVCC       	   = @NVCC@
MPI_INC        = @MPI_INC@
MPI_LIBDIR     = @MPI_LIBDIR@
MPI_LIBS       = @MPI_LIBS@

# VPATH-related substitution variables
srcdir	 = @srcdir@
VPATH	  = @srcdir@

LIBOBJS=sparseCpuKernels.o io.o denseCpuKernels.o mapDistanceFunctions.o training.o uMatrix.o trainOneEpoch.o

ifdef CUDA_LIBS
	LIBOBJS+=denseGpuKernels.cu.co
endif

OBJS=$(LIBOBJS) somoclu.o

all: somoclu

lib: $(LIBOBJS)
	$(CXX) $(DEFS) $(CXXFLAGS) $(CUDA_LDFLAGS) ${MPI_LIBDIR} -shared -o libsomoclu.so $^ $(LIBS) $(CUDA_LIBS) ${MPI_LIBS}
	
somoclu: $(OBJS)
	$(CXX) $(DEFS) $(CXXFLAGS) $(CUDA_LDFLAGS) ${MPI_LIBDIR} -o $@ $^ $(LIBS) $(CUDA_LIBS) ${MPI_LIBS}

%.o: %.cpp
		$(CXX) $(DEFS) $(CXXFLAGS) ${MPI_INC} -I$(srcdir) -I.. -o $@ -c $(srcdir)/$<

%.cu.co: %.cu
		$(NVCC) $(DEFS) $(CUDA_CFLAGS) ${MPI_INC} -I$(srcdir) -I.. -o $@ -c $(srcdir)/$<

clean:
	-rm -f somoclu libsomoclu.so $(OBJS) 1>/dev/null

install:
	$(INSTALL) -d $(DESTDIR)$(bindir)
	$(INSTALL_PROGRAM) -m 0755 somoclu \
	 $(DESTDIR)$(bindir)
	 
uninstall:
	-rm $(DESTDIR)$(bindir)/somoclu &>/dev/null

Makefile: Makefile.in ../config.status
	cd .. && ./config.status $@

../config.status: ../configure
	cd .. && ./config.status --recheck

.PHONY: all clean install uninstall
