#  SU{3} Instanton smoothing
#  MIMD version 6
#
#  Generic make-include file for smooth_inst 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_smooth"
#

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 \
  defines.h \
  smooth_inst_includes.h

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

MY_OBJECTS= \
 char_num.o \
 control.o \
 gauge_info.o \
 make_loop_table.o \
 path.o \
 project_su3_hit.o \
 save_topo.o \
 setup.o

# Basic set from generic directory
G_OBJECTS = \
 check_unitarity.o \
 d_plaq4.o \
 io_helpers.o \
 io_lat4.o \
 io_lat_utils.o \
 make_lattice.o \
 nersc_cksum.o \
 remap_stdio_from_args.o \
 reunitarize2.o

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

# Objects depending on architecture and software package 

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

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

OBJECTS = ${MY_OBJECTS} ${G_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.*
	${MAKE} -f ${MAKEFILE} clean
	touch ${LASTMAKE}

# To force a remake when changing make files
ALL_MAKES = Make_template ../generic/Make_template \
  ${MAKEFILE} ../include

${OBJECTS} : ${HEADERS} ${LASTMAKE} ${ALL_MAKES}

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}

##### Targets:

su3_hyp::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DHYP" \
	"EXTRA_OBJECTS= hyp_block.o gaugefix2.o instanton_density.o"

# Also calculates topological charge on time slices
su3_hyp2::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= -DHYP" \
	"EXTRA_OBJECTS= hyp_block.o gaugefix2.o instanton_density2.o"

# (target su3_ape was formerly called su3_smooth)
su3_ape::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= " \
	"EXTRA_OBJECTS= smooth.o ape_smear.o  gaugefix2.o instanton_density.o"

su3_fat::
	${MAKE} -f ${MAKEFILE} target "MYTARGET= $@" \
	"DEFINES= " \
	"EXTRA_OBJECTS= fat.o ape_smear.o gaugefix2.o instanton_density.o"

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


# Rules for generic routines
include ../generic/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 
