#***************************************************************************
#                               Makefile
#                          -------------------
#                           W. Michael Brown
#
#  _________________________________________________________________________
#    Build for the LAMMPS GPU Force Library
#
#  _________________________________________________________________________
#
#    begin                : Tue June 23 2009
#    copyright            : (C) 2009 by W. Michael Brown
#    email                : wmbrown@sandia.gov
# ***************************************************************************/

BIN_DIR = .
OBJ_DIR = .
AR = ar
CUDA_CPP  = nvcc -I/usr/local/cuda/include -DUNIX -O3 -DDEBUG -Xptxas -v --use_fast_math
CUDA_ARCH = -maxrregcount 128 #-arch=sm_13
CUDA_PREC = -D_SINGLE_SINGLE
CUDA_LINK = -L/usr/local/cuda/lib64 -lcudart $(CUDA_LIB)

CUDA = $(CUDA_CPP) $(CUDA_ARCH) $(CUDA_PREC)

CUDA_LIB = $(OBJ_DIR)/libgpu.a

# Headers for CUDA Stuff
NVC_H  = nvc_macros.h nvc_device.h nvc_timer.h nvc_memory.h nvc_traits.h
# Headers for Pair Stuff
PAIR_H  = pair_gpu_texture.h pair_gpu_atom.h pair_gpu_nbor.h
# Dependencies for the Texture Tar
TAR_H = $(NVC_H) $(PAIR_H) pair_gpu_atom.cu lj_gpu_memory.h lj_gpu_memory.cu \
        lj_gpu_kernel.h lj_gpu.cu gb_gpu_memory.h gb_gpu_memory.cu \
        gb_gpu_extra.h gb_gpu_kernel.h gb_gpu.cu

ALL_H = $(NVC_H) $(PAIR_H)

EXECS = $(BIN_DIR)/nvc_get_devices
OBJS = $(OBJ_DIR)/nvc_device.o $(OBJ_DIR)/pair_gpu_nbor.cu_o \
       $(OBJ_DIR)/pair_tex_tar.cu_o

all: $(CUDA_LIB) $(EXECS)

$(OBJ_DIR)/nvc_device.o: nvc_device.cu $(NVC_H)
	$(CUDA) -o $@ -c nvc_device.cu

$(OBJ_DIR)/pair_gpu_nbor.cu_o: pair_gpu_nbor.cu pair_gpu_texture.h pair_gpu_nbor.h $(NVC_H)
	$(CUDA) -o $@ -c pair_gpu_nbor.cu

$(OBJ_DIR)/pair_tex_tar.cu_o: $(TAR_H)
	$(CUDA) -o $@ -c pair_tex_tar.cu

$(BIN_DIR)/nvc_get_devices: nvc_get_devices.cu $(NVC_H) $(OBJ_DIR)/nvc_device.o
	$(CUDA) -o $@ nvc_get_devices.cu $(CUDALNK) $(OBJ_DIR)/nvc_device.o 

$(CUDA_LIB): $(OBJS)
	$(AR) -crusv $(CUDA_LIB) $(OBJS)

clean:
	rm -rf $(EXECS) $(CUDA_LIB) $(OBJS) *.linkinfo

veryclean: clean
	rm -rf *~ *.linkinfo

