#  Kogut-Susskind fermions with improved actions
#  MIMD version 7
#
#  Generic make-include file for ks_imp_rhmc 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_rhmc" used the rational function hybrid MC algorithm
#		for the Symanzik 1 loop gauge action and Asqtad quark action
#
#       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} ../libraries/include

INLINE_HEADERS = \
  ../sse/include/ \
  ../sse2/include/ \
  ../libraries/include/

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

HEADERS = ${GLOBAL_HEADERS} ${MY_HEADERS} ${INLINE_HEADERS} ${SCIDAC_HEADERS}

MY_OBJECTS = \
  d_action_rhmc.o \
  eo_fermion_force_rhmc.o \
  gauge_info.o \
  grsource_rhmc.o \
  load_rhmc_params.o \
  setup.o \
  update_h_rhmc.o \
  update_rhmc.o \
  update_u.o \

G_OBJECTS = \
  check_unitarity.o \
  d_plaq4.o \
  gaugefix2.o \
  gauge_stuff.o \
  grsource_imp.o \
  io_detect.o \
  io_helpers.o \
  io_lat4.o \
  io_lat_utils.o \
  ks_ratinv.o  \
  make_lattice.o \
  nersc_cksum.o \
  path_product.o \
  project_su3_hit.o \
  ranmom.o \
  ranstuff.o \
  remap_stdio_from_args.o \
  reunitarize2.o \
  show_generic_opts.o \
  stout_smear.o

ifeq ($(strip ${QCDOC}),true)
  G_OBJECTS += ploop2.o
else
  G_OBJECTS += ploop3.o
endif

ifeq ($(strip ${HAVEQIO}),true)
  G_OBJECTS += io_scidac.o io_scidac_types.o
endif

G_KS_OBJECTS = \
  f_meas.o \
  mat_invert.o \
  path_transport.o \
  rephase.o \
  show_generic_ks_opts.o

ifeq ($(strip ${HAVEQIO}),true)
  G_KS_OBJECTS += io_scidac_ks.o
endif

G_W_OBJECTS = \

ifeq ($(strip ${HAVEQIO}),true)
  G_W_OBJECTS += io_scidac_w.o
endif

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

# Objects depending on architecture and software package 

# Selection of layout
ifeq ($(strip ${QCDOC}),true)
  ifeq ($(strip ${HAVEQDP}),true)
    LAYOUT = layout_qdp.o # Required
  else
    LAYOUT = layout_qcdoc.o # Required
  endif
else
  ifeq ($(strip ${HAVEQDP}),true)
    LAYOUT = layout_qdp.o # Required
  else
    LAYOUT = layout_hyper_prime.o # Choices possible here
  endif
endif

# Selection of a non-QDP FN Dslash 
# Choices are dslash_fn.o dslash_fn2.o dslash_fn_dblstore.o
DSLASH_FN = dslash_fn_dblstore.o

# Selection of the fermion links algorithm for HISQ actions
ifeq ($(strip ${HAVEQOP}),true)
# Interface to access QOP
  FLINKS_HISQ = ${FLINKS_HISQ_QOP}
else
  ifeq ($(strip ${HAVEQDP}),true)
    FLINKS_HISQ = fermion_links_hisq_qdp.o fermion_links_hisq_helpers.o
  else
    FLINKS_HISQ = fermion_links_hisq.o fermion_links_hisq_helpers.o
  endif
endif

# Selection of the fermion links algorithm for imp actions
ifeq ($(strip ${HAVEQOP}),true)
# Interface to access QOP
  FLINKS_FN = ${FLINKS_FNQOP}
else
  ifeq ($(strip ${HAVEQDP}),true)
    FLINKS_FN = fermion_links_asqtad_qdp.o fermion_links_helpers.o
  else
    FLINKS_FN = fermion_links_fn.o fermion_links_helpers.o
  endif
endif

# Selection of the gauge force algorithm
ifeq ($(strip ${HAVEQOP}),true)
# Interface to access QOP
#  SYMZK1FORCE = gauge_force_symzk1_qop.o
#  SYMZK1FORCE += ${SYMZK1FORCEQOP}
    SYMZK1FORCE = gauge_force_imp.o
else
  ifeq ($(strip ${HAVEQDP}),true)
    SYMZK1FORCE = gauge_force_symzk1_qdp.o
  else
    SYMZK1FORCE = gauge_force_imp.o
  endif
endif

# Selection of the conjugate gradient algorithm
ifeq ($(strip ${HAVEQOP}),true)
# Interface to access QOP
  CONGRAD_FN = d_congrad5_fn_qop_two_src.o d_congrad5_fn_qop.o \
     d_congrad5_fn_qop_D.o d_congrad5_fn_qop_F.o d_congrad_opt.o
#  CONGRAD_FN = d_congrad5_two_src.o d_congrad5_fn.o d_congrad_opt.o
  CONGRAD_FN += ${ASQINVERTQOP}
else
  ifeq ($(strip ${HAVEQDP}),true)
#    Here you may use the fn_qdp set or the fn_1sum_qdp set
#    CONGRAD_FN = d_congrad5_two_src.o d_congrad5_fn_qdp.o \
#       d_congrad5_fn_qdp_D.o d_congrad5_fn_qdp_F.o d_congrad_opt.o
    CONGRAD_FN = d_congrad5_two_src.o d_congrad5_fn_qdp.o \
       d_congrad5_fn_qdp_D.o d_congrad5_fn_qdp_F.o d_congrad_opt.o
  else
    # Choose a non_QDP FN conjugate gradient algorithm
    CONGRAD_FN = d_congrad5_two_src.o d_congrad5_fn.o d_congrad_opt.o
  endif
endif

# Selection of the fermion force algorithm for HISQ actions
ifeq ($(strip ${HAVEQOP}),true)
# Interface to access QOP
  HISQFORCE = fermion_force_hisq_qop.o fermion_force_hisq_qop_F.o \
     fermion_force_hisq_qop_D.o
# The implementation of the interface (if not packaged)
  HISQFORCE += ${HISQFORCEQOP}
else
  ifeq ($(strip ${HAVEQDP}),true)
    HISQFORCE = fermion_force_hisq_qdp.o fermion_force_hisq_qdp_D.o \
	fermion_force_hisq_qdp_F.o fermion_force_hisq_multi_qdp.o
  else
    # For more general FN actions, try fermion_force_general.o +
    #	fermion_force_fn_multi.o + fermion_force_multi.o
    HISQFORCE = fermion_force_hisq_multi.o ff_opt.o
  endif
endif

# Selection of the fermion force algorithm for imp actions
ifeq ($(strip ${HAVEQOP}),true)
# Interface to access QOP
  ASQFORCE = fermion_force_asqtad_qop.o fermion_force_asqtad_qop_F.o \
     fermion_force_asqtad_qop_D.o
# The implementation of the interface (if not packaged)
  ASQFORCE += ${ASQFORCEQOP}
else
  ifeq ($(strip ${HAVEQDP}),true)
    ASQFORCE = fermion_force_asqtad_qdp.o fermion_force_asqtad_qdp_D.o \
	fermion_force_asqtad_qdp_F.o fermion_force_fn_multi_qdp.o
  else
    # For more general FN actions, try fermion_force_general.o +
    #	fermion_force_fn_multi.o + fermion_force_multi.o
    ASQFORCE = fermion_force_asqtad.o fermion_force_multi.o \
	fermion_force_fn_multi.o ff_opt.o
  endif
endif

# Selection of the multimass inverter
ifeq ($(strip ${HAVEQOP}),true)
# Interface to access QOP
  INV_FN_OBJECTS = ${CONGRAD_FN} ${DSLASH_FN}
  MULTI_INV_FN = ks_multicg.o ks_multicg_offset_qop.o \
    ks_multicg_offset_qop_D.o  ks_multicg_offset_qop_F.o
else
  ifeq ($(strip ${HAVEQDP}),true)
    QDP_OBJECTS = map_milc_to_qdp_D.o map_milc_to_qdp_F.o
    INV_FN_OBJECTS = ${CONGRAD_FN} ${DSLASH_FN} dslash_fn_qdp_D.o \
      dslash_fn_qdp_F.o 
    MULTI_INV_FN = ks_multicg.o ks_multicg_offset_qdp.o \
      ks_multicg_offset_qdp_D.o ks_multicg_offset_qdp_F.o
  else
    INV_FN_OBJECTS = ${CONGRAD_FN} ${DSLASH_FN}
    MULTI_INV_FN = ks_multicg.o ks_multicg_offset.o
  endif
endif

# The only choice for inverters and Dslash for EO actions
INV_EO_OBJECTS = d_congrad5_eo.o d_congrad_opt.o dslash_eo.o
MULTI_INV_EO = ks_multicg.o ks_multicg_offset.o

# For EO actions we don't precompute the fat links for Dslash at the moment
HISQ_OBJECTS = ${FLINKS_HISQ} ${INV_FN_OBJECTS}
FN_OBJECTS   = ${FLINKS_FN} ${INV_FN_OBJECTS}
EO_OBJECTS   = ${INV_EO_OBJECTS}

# EDRAM allocation for QCDOC
ifeq ($(strip ${QCDOC}),true)
  QCDOC_OBJECTS = qcdoc_alloc.o
endif

ADD_OBJECTS = ${MACHINE_DEP_IO} ${COMMPKG} ${QCDOC_OBJECTS} ${QDP_OBJECTS} \
   ${SCIDAC_OBJECTS}

# Generic QOP objects
ifeq ($(strip ${HAVEQOP}),true)
  ADD_OBJECTS += ${GENERICQOP}
endif

OBJECTS = ${MY_OBJECTS} ${G_OBJECTS} ${G_KS_OBJECTS} ${G_W_OBJECTS} ${LAYOUT} \
  ${ADD_OBJECTS} ${EXTRA_OBJECTS}

#Libraries for complex numbers and su3 functions
P = $(strip ${PRECISION})
QCDLIB = ${LIBDIR}/su3.${P}.a ${LIBDIR}/complex.${P}.a 

LIBRARIES = ${QCDLIB} ${SCIDAC_LIBRARIES}

# Default rule for C compilation
.c.o: ; ${CC} -c ${CFLAGS}  $*.c 

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

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

ALL_MAKES = \
   Make_template \
   ${MAKEFILE} \
   ../Make_template_qop \
   ../Make_template_scidac \
   ../generic/Make_template \
   ../generic_ks/Make_template \
   ../generic_wilson/Make_template

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

fermion_links_fn.o: quark_action.h 
fermion_links_hisq.o: quark_action.h 
gauge_info.o:  quark_action.h
gauge_stuff.o: gauge_action.h 
quark_stuff.o: quark_action.h 
quark_stuff_hisq.o: quark_action.h 
setup.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


ifeq ($(strip ${QCDOC}),true)
  DQCDOC = -DQCDOC
endif

ifeq ($(strip ${HAVEQMP}),true)
  DHAVE_QMP = -DHAVE_QMP
endif

ifeq ($(strip ${HAVEQIO}),true)
  DHAVE_QIO = -DHAVE_QIO
endif

ifeq ($(strip ${HAVEQDP}),true)
  DHAVE_QDP = -DHAVE_QDP
endif

ifeq ($(strip ${HAVEQOP}),true)
  DHAVE_QOP = -DHAVE_QOP
endif

DARCH = ${DQCDOC} ${DHAVE_QMP} ${DHAVE_QIO} ${DHAVE_QDP} ${DHAVE_QOP}

########################################################
# Optional DEFINES for targets

# -DFN          identifies fat-Naik-like actions with only next and 3rd
#               next neighbor linkage

# -DNPBP_REPS   adds an extra line to parameter input for specifying
#               the number of random sources in f_meas.c

# -DDM_DU0      (for EOS) calculate quantities involving the deriv of
#               action wrto u0

# -DCHEM_POT    compute quantities needed for quark number susceptibility

# -DD_CHEM_POT  compute quantities needed for nonzero chemical potential

##### Targets:
######################################################################
# Named RHMD targets -- sample files provided

su3_leapfrog::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DINT_ALG=INT_LEAPFROG" \
	"GAUGE = symanzik_1loop_action.h" \
	"QUARK = asqtad_action.h" \
	"EXTRA_OBJECTS= ${FN_OBJECTS} ${MULTI_INV_FN} ${ASQFORCE} \
	${SYMZK1FORCE} quark_stuff.o control.o"

su3_omelyan_rhmc::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHMC -DINT_ALG=INT_OMELYAN" \
	"GAUGE = symanzik_1loop_action.h" \
	"QUARK = asqtad_action.h" \
	"EXTRA_OBJECTS= ${FN_OBJECTS} ${MULTI_INV_FN} ${ASQFORCE} \
	${SYMZK1FORCE} quark_stuff.o control.o"

######################################################################
# Generic RHMD targets -- set further options in Makefile

su3_rhmd::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN" \
	"GAUGE = symanzik_1loop_action.h" \
	"QUARK = asqtad_action.h" \
	"EXTRA_OBJECTS= ${FN_OBJECTS} ${MULTI_INV_FN} ${ASQFORCE} \
	${SYMZK1FORCE} quark_stuff.o control.o"

# Generic RHMC target -- set options in Makefile
su3_rhmc::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHMC" \
	"GAUGE = symanzik_1loop_action.h" \
	"QUARK = asqtad_action.h" \
	"EXTRA_OBJECTS= ${FN_OBJECTS} ${MULTI_INV_FN} ${ASQFORCE} \
	${SYMZK1FORCE} quark_stuff.o control.o"

# Generic RHMC target -- set options in Makefile
su3_rhmc_Nf::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHMC" \
	"GAUGE = symanzik_1loop_nf_action.h" \
	"QUARK = asqtad_action.h" \
	"EXTRA_OBJECTS= ${FN_OBJECTS} ${MULTI_INV_FN} ${ASQFORCE} \
	${SYMZK1FORCE} quark_stuff.o control.o"

# Generic RHMC EOS target -- set options in Makefile
su3_rhmc_eos::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHMC -DDM_DU0 -DNPBP_REPS" \
	"GAUGE = symanzik_1loop_action.h" \
	"QUARK = asqtad_action.h" \
	"EXTRA_OBJECTS= ${FN_OBJECTS} ${MULTI_INV_FN} ${ASQFORCE} \
	${SYMZK1FORCE} quark_stuff.o control.o"

# Generic RHMC EOS target -- set options in Makefile
su3_rhmd_eos::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DDM_DU0 -DNPBP_REPS" \
	"GAUGE = symanzik_1loop_action.h" \
	"QUARK = asqtad_action.h" \
	"EXTRA_OBJECTS= ${FN_OBJECTS} ${MULTI_INV_FN} ${ASQFORCE} \
	${SYMZK1FORCE} quark_stuff.o control.o"

# Generic RHMC susceptibility target -- set options in Makefile
su3_rhmc_susc::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHMC -DCHEM_POT -DNPBP_REPS" \
	"GAUGE = symanzik_1loop_action.h" \
	"QUARK = asqtad_action.h" \
	"EXTRA_OBJECTS= ${FN_OBJECTS} ${MULTI_INV_FN} ${ASQFORCE} \
	${SYMZK1FORCE} quark_stuff.o control.o"

# Generic RHMC EOS and susceptibility target -- set options in Makefile
#	-DZ2RSOURCE
su3_rhmc_susc_eos::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHMC -DCHEM_POT -DDM_DU0 -DNPBP_REPS" \
	"GAUGE = symanzik_1loop_action.h" \
	"QUARK = asqtad_action.h" \
	"EXTRA_OBJECTS= ${FN_OBJECTS} ${MULTI_INV_FN} ${ASQFORCE} \
	${SYMZK1FORCE} quark_stuff.o control.o"

######################################################################
# HISQ targets

# NOTE: Neither QDP nor QOP are yet supported for any HISQ targets!

su3_rhmd_hisq::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHISQ -DINT_ALG=INT_OMELYAN" \
	"GAUGE = symanzik_1loop_nf_action.h" \
	"QUARK = hisq/hisq_su3_action.h" \
	"EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
	${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o control.o"

su3_rhmd_hisq_su3::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHISQ -DINT_ALG=INT_3G1F" \
	"GAUGE = symanzik_1loop_nf_action.h" \
	"QUARK = hisq/hisq_su3_action.h" \
	"EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
	${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o control.o"

# Generic RHMC target -- set options in Makefile
su3_rhmc_hisq::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHISQ -DHMC -DINT_ALG=INT_3G1F -DHISQ_REUNIT_ALLOW_SVDDDD" \
	"GAUGE = symanzik_1loop_hisq_action.h" \
	"QUARK = hisq/hisq_u3_action.h" \
	"EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
	${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o control.o"

su3_rhmc_hisq_plaq::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHISQ -DHMC -DINT_ALG=INT_3G1F -DHISQ_REUNIT_ALLOW_SVD -DHISQ_REUNIT_SVD_ONLYYYYY" \
	"GAUGE = symanzik_1loop_nf0_action.h" \
	"QUARK = hisq/hisq_u3_action.h" \
	"EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
	${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o control.o"

su3_rhmc_hisq_su3::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHISQ -DHMC -DINT_ALG=INT_3G1F" \
	"GAUGE = symanzik_1loop_hisq_action.h" \
	"QUARK = hisq/hisq_su3_action.h" \
	"EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
	${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o control.o"

# HISQ spectrum 
su3_spectrum_hisq::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHISQ -DSPECTRUM -DHISQ_REUNIT_ALLOW_SVD \
	-DINT_ALG=INT_3G1F" \
	"GAUGE = symanzik_1loop_hisq_action.h" \
 	"QUARK = hisq/hisq_u3_action.h" \
	"EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
	${SPECTRUM_OBJECTS} ${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o \
        control.o"

# HISQ spectrum with SU(3) reunitarization
su3_spectrum_hisq_su3::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHISQ -DSPECTRUM" \
	"GAUGE = symanzik_1loop_hisq_action.h" \
	"QUARK = hisq/hisq_su3_action.h" \
	"EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
	${SPECTRUM_OBJECTS} ${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o \
        control.o"

######################################################################
# The su3_rhmc_hisq_eos target HAS NOT BEEN DEVELOPED.  DON'T USE IT!
######################################################################
# Generic RHMC EOS target -- set options in Makefile
su3_rhmc_hisq_eos::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHISQ -DHMC -DDM_DU0 -DNPBP_REPS" \
	"GAUGE = symanzik_1loop_nf_action.h" \
	"QUARK = hisq/hisq_action.h" \
	"EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
	${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o"

######################################################################
# The su3_rhmd_hisq_eos target HAS NOT BEEN DEVELOPED.  DON'T USE IT!
######################################################################
# Generic RHMC EOS target -- set options in Makefile
# The HISQ DM_DU0 option is not supported, yet
su3_rhmd_hisq_eos::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHISQ -DDM_DU0 -DNPBP_REPS" \
	"GAUGE = symanzik_1loop_nf_action.h" \
	"QUARK = hisq/hisq_action.h" \
	"EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
	${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o control.o"

######################################################################
# The su3_rhmd_hisq_susc target HAS NOT BEEN DEVELOPED.  DON'T USE IT!
######################################################################
# Generic RHMC susceptibility target -- set options in Makefile
su3_rhmc_hisq_susc::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHISQ -DHMC -DCHEM_POT -DNPBP_REPS" \
	"GAUGE = symanzik_1loop_nf_action.h" \
	"QUARK = hisq/hisq_action.h" \
	"EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
	${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o control.o"

######################################################################
# The su3_rhmd_hisq_susc_eos target HAS NOT BEEN DEVELOPED.  DON'T USE IT!
######################################################################
# Generic RHMC EOS and susceptibility target -- set options in Makefile
# The HISQ DM_DU0 option is not supported, yet
su3_rhmc_hisq_susc_eos::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHISQ -DHMC -DCHEM_POT -DDM_DU0 -DNPBP_REPS" \
	"GAUGE = symanzik_1loop_nf_action.h" \
	"QUARK = hisq/hisq_action.h" \
	"EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
	${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o control.o"

###################################################
# DEBUGGING targets
###################################################
su3_mat_op.o: ${HEADERS} ${LASTMAKE} ${ALL_MAKES}
control_test_su3_mat_op.o: ${HEADERS} ${LASTMAKE} ${ALL_MAKES}

# ASQ related ####################################

su3_rhmc_asq_debug::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHMC -DINT_ALG=INT_3G1F -DMILC_GLOBAL_DEBUG" \
	"GAUGE = symanzik_1loop_action.h" \
	"QUARK = asq_action.h" \
	"EXTRA_OBJECTS= ${FN_OBJECTS} ${MULTI_INV_FN} ${ASQFORCE} \
	${SYMZK1FORCE} quark_stuff.o control.o debug.o"

su3_spectrum_asq::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN 	-DSPECTRUM -DKS_MULTICG=HYBRID" \
	"GAUGE = symanzik_1loop_action.h" \
	"QUARK = asq_action.h" \
	"EXTRA_OBJECTS= ${FN_OBJECTS} ${ASQFORCE} ${SYMZK1FORCE} \
	${MULTI_INV_FN} ${SPECTRUM_OBJECTS} quark_stuff.o control.o"


# HISQ related ####################################

# Generic RHMC target -- set options in Makefile
su3_rhmc_hisq_debug::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHISQ -DHMC -DINT_ALG=INT_3G1F \
	-DMILC_GLOBAL_DEBUG -DHISQ_REUNITARIZATION_DEBUG \
	-DHISQ_FF_MULTI_WRAPPERRR -DHISQ_FF_DEBUGGG" \
	"GAUGE = symanzik_1loop_hisq_action.h" \
	"QUARK = hisq/hisq_u3_action.h" \
	"EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
	${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o control.o debug.o"

su3_rhmc_hisq_su3_debug::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHISQ -DHMC -DINT_ALG=INT_3G1F \
	-DMILC_GLOBAL_DEBUG -DHISQ_REUNITARIZATION_DEBUG \
	-DHISQ_FF_MULTI_WRAPPER -DHISQ_FF_DEBUG" \
	"GAUGE = symanzik_1loop_hisq_action.h" \
	"QUARK = hisq/hisq_su3_action.h" \
	"EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
	${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o control.o debug.o"

# test Asqtad action through HISQ machinery with "wrapper" force
su3_rhmc_hisq_wrap_asq::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHISQ -DHMC -DINT_ALG=INT_3G1F \
	-DMILC_GLOBAL_DEBUG -DHISQ_FF_MULTI_WRAPPER" \
	"GAUGE = symanzik_1loop_action.h" \
	"QUARK = hisq/1Xasqtad_action.h" \
	"EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
	${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o control.o debug.o"

# test Asqtad spectrum through HISQ machinery
su3_spectrum_hisq_asq::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHISQ -DSPECTRUM" \
	"GAUGE = symanzik_1loop_nf_action.h" \
	"QUARK = hisq/1Xasqtad_action.h" \
	"EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
	${SPECTRUM_OBJECTS} ${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o control.o"

# for tuning smearing level 1
su3_rhmc_hisq_tune::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHISQ -DHMC \
	-DMILC_GLOBAL_DEBUG -DMEASURE_AND_TUNE_HISQ" \
	"GAUGE = symanzik_1loop_nf_action.h" \
	"QUARK = hisq/hisq_u3_action.h" \
	"EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
	${SYMZK1FORCE} control.o quark_stuff_hisq.o su3_mat_op.o debug.o"

# testing inversion
test_su3_mat_op_inverse::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"GAUGE = symanzik_1loop_nf_action.h" \
	"QUARK = hisq/hisq_action.h" \
        "DEFINES= -DFN -DHISQ -DTEST_SU3_INVERSION" \
        "EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
        ${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o \
        control_test_su3_mat_op.o"

# testing reunitarization
test_su3_mat_op_unit::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"GAUGE = symanzik_1loop_nf_action.h" \
	"QUARK = hisq/hisq_u3_action.h" \
        "DEFINES= -DFN -DHISQ -DHISQ_REUNIT_ALLOW_SVD -DHISQ_REUNIT_SVD_ONLY -DTEST_SU3_UNITARIZATION" \
        "EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
        ${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o \
        control_test_su3_mat_op.o"

# testing reunitarization (derivative)
test_su3_mat_op_unit_der::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"GAUGE = symanzik_1loop_nf_action.h" \
	"QUARK = hisq/hisq_u3_action.h" \
        "DEFINES= -DFN -DHISQ -DTEST_SU3_UNITARIZATION_DERIVATIVE" \
        "EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
        ${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o \
        control_test_su3_mat_op.o"

# paranoid test reunitarization
test_su3_paranoid::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"GAUGE = symanzik_1loop_nf_action.h" \
	"QUARK = hisq/hisq_u3_action.h" \
        "DEFINES= -DFN -DHISQ -DHISQ_REUNIT_ALLOW_SVDDD -DTEST_SU3_UNITARIZATION" \
        "EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
        ${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o \
        control_test_su3_paranoid.o"

# paranoid test reunitarization derivative
test_su3_paranoid_der::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"GAUGE = symanzik_1loop_nf_action.h" \
	"QUARK = hisq/hisq_u3_action.h" \
        "DEFINES= -DFN -DHISQ -DHISQ_REUNIT_ALLOW_SVDDD -DTEST_SU3_UNITARIZATION_DERIVATIVE" \
        "EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
        ${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o \
        control_test_su3_paranoid.o"

su3_spectrum_hisq_stout::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DFN -DHISQ -DSPECTRUM -DMILC_GLOBAL_DEBUG" \
	"GAUGE = symanzik_1loop_hisq_action.h" \
	"QUARK = hisq/hisq_stout_action.h" \
	"EXTRA_OBJECTS= ${HISQ_OBJECTS} ${MULTI_INV_FN} ${HISQFORCE} \
	${SPECTRUM_OBJECTS} ${SYMZK1FORCE} quark_stuff_hisq.o su3_mat_op.o \
        control.o debug.o"


# Hacks to allow more than one test case
su3_rhmc_hisq.f211: su3_rhmc_hisq
		    mv su3_rhmc_hisq su3_rhmc_hisq.f211

su3_rhmc_hisq.f2111: su3_rhmc_hisq
		     mv su3_rhmc_hisq su3_rhmc_hisq.f2111


su3_rhmc_hisq_su3.f2111: su3_rhmc_hisq_su3
		     mv su3_rhmc_hisq_su3 su3_rhmc_hisq_su3.f2111


clean:
	-/bin/rm -f *.o quark_action.h gauge_action.h

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

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

# Rules for generic_wilson routines
include ../generic_wilson/Make_template

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

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

target: libmake localmake 

