include Makefile.defs
include ../Makefile.mk

LDFLAGS+= -L../targetDP -ltarget -lm
CFLAGS += -I. -I./include -I ../targetDP

#defines
TARGETDIR=.
DEBUG=0

ifeq ($(DEBUG),1) 
DEFINES+= -DDEBUG -g
endif

default: bench

#GENERIC
VPATH= libraries/ arch_mpi/ include/
ARCHDIR=arch_mpi/
#CC		= mpicc
#LD		= mpicc


# ifeq ($(MYHOSTNAME),archer)
# #CFLAGS = $(DEFINES) -O2 -DARCH=0 -DAoS -I./include  -I../targetDP
# CFLAGS = $(DEFINES) -O2 -DARCH=0  -I./include  -I../targetDP #-opt-report=3
# LDFLAGS = -lm 
# TARGETCC=CC
# #TARGETCFLAGS=-x c -fopenmp
# TARGETCFLAGS=-x c -openmp
# endif

# ifeq ($(MYHOSTNAME),eddie3)
# CC=mpiicc
# CFLAGS = $(DEFINES) -O2 -DARCH=0  -I./include  -I../targetDP #-opt-report=3
# LDFLAGS = -lm 
# TARGETCC=mpiicc
# TARGETCFLAGS=-x c -openmp
# endif

# ifeq ($(MYHOSTNAME),mbpag3)
# #CFLAGS = $(DEFINES) -O2 -DARCH=0 -DAoS -I./include  -I../targetDP
# CFLAGS = $(DEFINES) -O2 -DARCH=0 -I./include  -I../targetDP
# LDFLAGS = -lm -L../targetDP -ltargetDP_C  -L/usr/local/Cellar/gcc49/4.9.0/lib/gcc/x86_64-apple-darwin13.1.0/4.9.0/  -lgomp
# CC=mpicc
# TARGETCC=mpicc
# TARGETCFLAGS=-x c -fopenmp
# endif


# ifeq ($(HOSTNAME),hydra.hydra)
# CC		= mpiicc
# LD		= mpiicc
# CFLAGS = $(DEFINES) -O2 -DARCH=0 -mmic -I./include  -I../targetDP #-opt-streaming-cache-evict=0 -opt-streaming-stores always
# TARGETCC=mpiicc
# TARGETCFLAGS=-x c -openmp
# endif

# ifeq ($(HOSTNAME),gpulab2.hydra)
# CFLAGS = $(DEFINES) -O2 -DARCH=0 -I./include -I../targetDP -I/usr/local/packages/mpich2-1.5/include 


# #CFLAGS = $(DEFINES) -O2 -DARCH=0 -I./include  -I../targetDP -I/opt/intel/impi/5.0.3.048/intel64/include
# #CFLAGS = $(DEFINES) -DARCH=0 -I./include  -I../targetDP -I/usr/local/packages/mpich2-1.5/include  
# LDFLAGS = -lm 
# TARGETCC=nvcc
# TARGETCFLAGS=-x cu -arch=sm_35 -I. -DCUDA -dc -c #-g -G
# endif



# ifeq ($(MYHOSTNAME),titan)

# ifeq ($(TARGETDP),HOST)
# #OMPFLAG=-fopenmp
# OMPFLAG=-openmp
# #OMPFLAG=-mp
# CC=cc
# CFLAGS= $(DEFINES) -O2 $(OMPFLAG) -DARCH=0 -I./include -I../targetDP
# LDFLAGS = -lm
# TARGETCC=cc
# TARGETCFLAGS=-x c

# else
# CC=cc
# CFLAGS = $(DEFINES) -O2 -DARCH=0 -I./include -I../targetDP #-I/usr/local/packages/mpich2-1.5/include 
# LDFLAGS = -lm 
# TARGETCC=nvcc
# TARGETCFLAGS=-x cu -arch=sm_35 -I. -DCUDA -dc -c -I/opt/cray/mpt/default/gni/mpich2-CRAY64/8.3/include #-g -G
# endif

# endif



.c.o:
	$(CC) $(CFLAGS) $< -c -o $(patsubst %.c,%.o,$<)






.C.o:
	$(TARGETCC) $(TARGETCFLAGS)  $< -c -o $(patsubst %.C,%.o,$<)



#top level headers
HEADER =		\
	config.h 	\
	complex.h 	\
	su3.h 		\
	macros.h 	\
	machine.h 	\
	comdefs.h 	\
	generic.h 	\
	generic_wilson.h \
	io_lat.h 	\
	includes.h 	\
	lattice.h




#top level sources
SOURCE:=	     	\
	control.c       \
	d_plaq4.c       \
	setup.c         \
	io_helpers.c    \
	check_unitarity.c \
	make_lattice.c  \
	fermion_stuff.c \
	mt19937-64.c	\
	random.c	




TARGETSOURCE=   congrad.C 	mult_fmat.C	


#subdir sources and headers
include libraries/module.mk
include $(ARCHDIR)/module.mk


OBJECT:=                        \
	$(patsubst %.c,%.o,$(filter %.c,$(SOURCE)))     \
	$(patsubst %.asm,%.o,$(filter %.asm,$(SOURCE))) \
	$(patsubst %.f,%.o,$(filter %.f,$(SOURCE)))

OBJECT2:=                        \
	$(patsubst %.C,%.o,$(filter %.C,$(TARGETSOURCE)))     \

$(OBJECT): $(HEADER) Makefile
$(OBJECT2): $(HEADER) Makefile


#targets
bench: $(OBJECT) $(OBJECT2)
	$(TARGETCC) -o $(TARGETDIR)/$@ $(OBJECT) $(OBJECT2) $(ARPACK) $(LDFLAGS) 

clean:
	rm -f ./*.o ./*.a ./*/*.o ./*~ ./*/*~ bench ../kernel_E.a
