#  Kogut-Susskind fermions with improved actions
#  MIMD version 6
#  "ks_imp3", started 1/22/99, streamline ks_imp2
#
#  Generic make-include file for ks_imp3 codes
#  This template file defines rules and macros common to all architectures
#  It is intended to be an include file for other Makefiles.
#  Don't use it by itself!
#
#	"make su3_rmd" used the refreshed molecular dynamics algorithm
#		for the Symanzik 1 loop gauge action and Asqtad quark action
#	"make su3_spectrum" uses the refreshed molecular dynamics
#	        algorithm with the su3_rmd action and does spectrum
#	        measurements
#	"make su3_hybrids" uses the refreshed molecular dynamics
#	        algorithm with the su3_rmd action and does spectrum
#	        measurements, including the hybrid spectrum
#       See examples below for naming and building targets for
#               other actions

MYINCLUDEDIR = .
INCLUDEDIR = ../include
#Where the complex and su3 libraries are
LIBDIR = ../libraries

GLOBAL_HEADERS = \
  ${INCLUDEDIR}/config.h \
  ${INCLUDEDIR}/complex.h \
  ${INCLUDEDIR}/su3.h \
  ${INCLUDEDIR}/comdefs.h \
  ${INCLUDEDIR}/macros.h \
  ${INCLUDEDIR}/generic.h \
  ${INCLUDEDIR}/generic_ks.h \
  ${INCLUDEDIR}/io_lat.h

MY_HEADERS = \
  lattice.h \
  params.h \
  defines.h \
  ks_imp_includes.h

HEADERS = ${GLOBAL_HEADERS} ${MY_HEADERS}

# Choose one of the lattice layout algorithms:
LAYOUT = layout_qdp

MY_OBJECTS= \
  control_qdp.o \
  f_meas.o \
  gauge_info.o \
  setup_qdp.o \
  update.o \
  update_h.o \
  update_u.o

G_OBJECTS = \
  ${LAYOUT}.o \
  check_unitarity.o \
  d_plaq4.o \
  gaugefix2.o \
  gauge_stuff.o \
  io_helpers.o \
  io_lat4.o \
  make_lattice.o \
  path_product.o \
  ploop3.o \
  ranmom.o \
  ranstuff.o \
  reunitarize2.o \
  stuff_qdp.o

G_KS_OBJECTS = \
  grsource_imp.o \
  mat_invert.o \
  quark_stuff.o \
  rephase.o

SPECTRUM_OBJECTS = \
  flavor_ops.o \
  fpi_2.o \
  hvy_pot.o \
  nl_spectrum.o \
  spectrum2.o \
  spectrum_mom.o \
  spectrum_multimom.o \
  spectrum_nd.o \
  spectrum_nlpi2.o

OBJECTS = ${MY_OBJECTS} ${G_OBJECTS} ${G_KS_OBJECTS} \
  ${EXTRA_OBJECTS} ${MACHINE_DEP}

#Libraries for complex numbers and su3 functions
QCDLIB = ${LIBDIR}/su3.a ${LIBDIR}/complex.a 

.c.o: ; ${CC} -c ${CFLAGS}  $*.c 

# To force a full remake when changing targets
LASTMAKE = .lastmake.${MAKEFILE}.${MYTARGET}

${LASTMAKE}:
	-/bin/rm -f .lastmake.*
	/bin/rm -f .lastmake.* quark_action.h gauge_action.h
	${MAKE} -f ${MAKEFILE} clean
	touch ${LASTMAKE}

ALL_MAKES = Make_template_qdp ../generic/Make_template \
	../generic_ks/Make_template ${MAKEFILE} ../include/Make_template

# To force a remake when changing any make file, header, or target
${OBJECTS} : ${HEADERS} ${LASTMAKE} ${ALL_MAKES}

quark_stuff.o: quark_action.h 
gauge_stuff.o: gauge_action.h 
gauge_info.o:  quark_action.h

# Directories where we store the improved action headers
QUARKIMP = ../generic_ks/imp_actions
GAUGEIMP = ../generic/imp_actions

quark_action.h: ${QUARKIMP}/${QUARK}
	/bin/cp ${QUARKIMP}/${QUARK} quark_action.h

gauge_action.h: ${GAUGEIMP}/${GAUGE}
	/bin/cp ${GAUGEIMP}/${GAUGE} gauge_action.h


########################################################
# Optional DEFINES for timing:
# -DCGTIME for cg timing and iterations
# -DGFTIME for gauge force timing

# Optional DEFINES for data layout:
# -DDSLASH_TMP_LINKS puts fatlinks and longlinks in temp
# -DCONGRAD_TMP_VECTORS puts congrad vectors in temp

# Optional DEFINES for pbp estimates
# -DNPBP_REPS Number of repeated evaluations of stochastic 
#       psi-bar-psi

# Optional DEFINES for EOS
# -DDM_DU0 for calculating deriv of action wrto u0

# Optional DEFINES for quark number susceptibility
# -DCHEM_POT

##### Targets:
#		("FN" = "fat+Naik")

su3_rmd::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DCONGRAD_TMP_VECTORS -DDSLASH_TMP_LINKS" \
	"GAUGE = symanzik_1loop_action.h" \
	"QUARK = asqtad_action.h" \
	"EXTRA_OBJECTS= dslash_fn.o dslash_fn_qdp.o d_congrad5_fn_qdp.o"

su3_hmc::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DDSLASH_TMP_LINKS -DCONGRAD_TMP_VECTORS -DPHI_ALGORITHM -DHMC_ALGORITHM" \
	"GAUGE = symanzik_1loop_action.h" \
	"QUARK = asqtad_action.h" \
	"EXTRA_OBJECTS= dslash_fn.o d_congrad5_fn.o d_action.o"

# The following target is a superset of su3_spectrum

su3_hybrids::
	make -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DDSLASH_TMP_LINKS -DCONGRAD_TMP_VECTORS -DSPECTRUM -DHYBRIDS" \
	"GAUGE = symanzik_1loop_action.h" \
	"QUARK = asqtad_action.h" \
	"EXTRA_OBJECTS= dslash_fn_qdp.o d_congrad5_fn_qdp.o ks_multicg_qdp.o ape_smear.o project_su3_hit.o field_strength.o spectrum_hybrids5.o ${SPECTRUM_OBJECTS}"

# The following target will not do hybrids

su3_spectrum::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DDSLASH_TMP_LINKS -DCONGRAD_TMP_VECTORS -DSPECTRUM" \
	"GAUGE = symanzik_1loop_action.h" \
	"QUARK = asqtad_action.h" \
	"EXTRA_OBJECTS= dslash_fn.o dslash_fn_qdp.o d_congrad5_fn_qdp.o ks_multicg_qdp.o ${SPECTRUM_OBJECTS}"


# The following stanzas illustrate how to create targets for alternative
# choices of quark and gauge actions

su3_rmd_eo_symzk1_fat7tad::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DEO -DDSLASH_TMP_LINKS -DCONGRAD_TMP_VECTORS" \
	"GAUGE = symanzik_1loop_action.h" \
	"QUARK = fat7tad_action.h" \
	"EXTRA_OBJECTS= d_congrad5_eo.o"

su3_rmd_plaq_fat7naik::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DDSLASH_TMP_LINKS -DCONGRAD_TMP_VECTORS" \
	"GAUGE = plaquette_action.h" \
	"QUARK = fat7naik_action.h" \
	"EXTRA_OBJECTS= dslash_fn.o d_congrad5_fn.o"

su3_rmd_symzk1_naik::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DDSLASH_TMP_LINKS -DCONGRAD_TMP_VECTORS" \
	"GAUGE = symanzik_1loop_action.h" \
	"QUARK = naik_action.h" \
	"EXTRA_OBJECTS= dslash_fn.o d_congrad5_fn.o"

su3_rmd_eo_symzk1_p4::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DEO -DDSLASH_TMP_LINKS -DCONGRAD_TMP_VECTORS" \
	"GAUGE = symanzik_1loop_action.h" \
	"QUARK = p4_action.h" \
	"EXTRA_OBJECTS= d_congrad5_eo.o"

clean:
	-/bin/rm -f *.o

# Rules for generic routines
include ../generic/Make_template_qdp

# Rules for generic_ks routines
include ../generic_ks/Make_template_qdp

# Rules for header files
include ../include/Make_template_qdp

libmake:
	@echo Building libraries with ${MAKELIBRARIES}
	cd ${LIBDIR} ;\
	${MAKE} -f ${MAKELIBRARIES} "APP_CC=${CC}" all

localmake: ${OBJECTS} ${QCDLIB}
	${LD} ${LDFLAGS} -o ${MYTARGET} \
	${OBJECTS} ${QCDLIB} ${ILIB} -lm
	touch localmake

target: libmake localmake 

