# This is not a standalone Makefile
# It is intended to be included in other Makefiles

# It defines macros for QOP (SciDAC Level 3)
# HAVEQOP          What we are compiling with
# LIBQOP INCQOP    The -L and -I compiler and linker lists
# INCDEPQOP LIBDEPQOP  Lists for make dependencies
# ASQFORCEQOP

# Requires input macros
# WANTQOP                 User requests (true or otherwise)

# Nothing needs to be defined here if we don't want QOP

@echo WANTQOP = ${WANTQOP}
ifneq ($(strip ${WANTQOP}),)
  HAVEQOP = true

  # Fermion links support for all QOP implementations
  FLINKS_FNQOP = load_qop_asqtad_coeffs_D.o load_qop_asqtad_coeffs_F.o \
     fermion_links_asqtad_qop.o fermion_links_asqtad_qop_D.o \
     fermion_links_asqtad_qop_F.o

  ifeq ($(strip ${WANTQOP}),QCDOC)

    #-------------------------------------
    # QCDOC package
    #-------------------------------------

    # Temporary paths for QCDOC.
    QCDOCQOP=/qcdoc/sfw/SciDAC/Asqtad_L3/v1.1

    # For qop.h 
    QOPINCDIR = $(strip ${QCDOCQOP})/include

    # The QCDOC and MILC raw formats are thus far identical

    GENERICQOP =  map_milc_to_qopmilc.o milc_to_qop_utilities.o

    # Gauge force (not in QCDOC: use standard MILC version)
    SYMZK1FORCEQOP = gauge_force_imp.o

    # Fermion links (not in QCDOC: use standard MILC version)
    FLINKS_FNQOP += fermion_links_helpers.o

    # For the QCDOC fermion force and inverter we need the lib path
    QOPLIBDIR = ${QCDOCQOP}/build

    # Compiler include path and linker lib path for QOP package
    IQOP = -I${QOPINCDIR}
    LQOP = -L${QOPLIBDIR} -lasqd

    # The QCDOC L3 package can't create L from G and doesn't support
    # the Dirac fermion types
    CQOP = -DHAVE_NO_CREATE_L_FROM_G -DHAVE_NO_QOP_D

    # For "make" dependencies
    LIBDEPQOP = ${QOPLIBDIR}
    INCDEPQOP = ${QOPINCDIR}

  else

    #-------------------------------------
    # QOPQDP package
    #-------------------------------------

    ifeq ($(strip ${WANTQOP}),QDP)
      # Requires QDP whether or not the user requested it
      WANTQDP = true

      # MILC raw format differs from QOPQDP raw format
      GENERICQOP =  map_milc_to_qopqdp.o milc_to_qop_utilities.o

      FLINKS_FNQOP += fermion_links_helpers.o

      # We always need the qop.h header
      QOPINCDIR = $(strip ${QOPQDP})/include
      # Path to the qopqdp library
      QOPLIBDIR = $(strip ${QOPQDP})/lib

      IQOP = -I${QOPINCDIR}
      INCDEPQOP = ${QOPINCDIR}
      LQOP = -L${QOPLIBDIR} -lqopqdp

    else

    #-------------------------------------------------------------
    # Default: MILC nonoptimized routines.  They are non-packaged.
    #------------------------------------------------------------

      # We always need the qop.h header
      QOPINCDIR = $(strip ${QOP})/include
    
      IQOP = -I${QOPINCDIR}
      INCDEPQOP = ${QOPINCDIR}

      # MILC raw format differs from QOPQDP raw format
      GENERICQOP =  map_milc_to_qopmilc.o milc_to_qop_utilities.o

      # General requirement
      GENERICQOP += qop_milc.o qop_milc_D.o qop_milc_F.o qop_milc_utilities.o

      # Gauge force
      SYMZK1FORCEQOP = gauge_force_symzk1_qop_milc.o

      # Asqtad fermion links
      FLINKS_FNQOP += fermion_links_fn_qop_milc_D.o \
        fermion_links_fn_qop_milc_F.o fermion_links_helpers.o

      # Wilson fermion links (clover)
      FLINKS_WILSONQOP = fermion_links_wilson_qop_milc_D.o \
        fermion_links_wilson_qop_milc_F.o

      # Asqtad conjugate gradient
      ASQINVERTQOP = d_congrad5_fn_qop_milc_D.o d_congrad5_fn_qop_milc_F.o \
         dslash_fn_qop_milc_D.o dslash_fn_qop_milc_F.o
      ASQINVERTQOP += ks_multicg_qop_milc_D.o ks_multicg_qop_milc_F.o

      # Asqtad fermion force
      ASQFORCEQOP = fermion_force_asqtad_qop_milc.o \
	fermion_force_asqtad_qop_milc_D.o \
	fermion_force_asqtad_qop_milc_F.o ff_opt.o

      # Wilson fermion force
      WILSONINVERTQOP = d_bicgilu_cl_qop_milc_D.o d_bicgilu_cl_qop_milc_F.o 
    endif
  endif
  
  ifneq ($(strip ${WANTQOP}),)
    LIBQOP = ${LQOP}
    INCQOP = ${IQOP}
  endif

else

  HAVEQOP = 

endif  # if WANTQOP

