##############################################################################
#
# Blitz++ benchmarks makefile
#

srcdir = @srcdir@
VPATH = @srcdir@

BZDIR = $(srcdir)/..

CXX = @CXX@
CXXFLAGS = @CXXFLAGS@ @CXX_OPTIMIZE_FLAGS@ @CXXFFLAGS@ -I$(BZDIR)
F77 = @F77@
F77FLAGS = @F77_OPTIMIZE_FLAGS@
F90 = @F90@
F90FLAGS = @F90_OPTIMIZE_FLAGS@

LIBS = -L$(BZDIR)/lib -lblitz -lm @BLASLIB@ @FORTLIBS@

.SUFFIXES: .o .cpp .f

.cpp.o:
	$(CXX) $(CXXFLAGS) -c $*.cpp

.f.o:
	$(F77) $(F77FLAGS) -c $*.f

############################################################################

LOOP_KERNELS = loop1 loop2 loop3 loop5 loop6 loop8 loop9 \
        loop10 loop11 loop12 loop13 loop14 loop15 loop16 loop17 loop18 \
	loop19 loop21 loop22 loop23 loop24 loop25 loop36

BENCHMARKS = daxpy haney qcd stencil tinydaxpy acoustic acou3d hao-he \
	$(LOOP_KERNELS)

all:	$(BENCHMARKS) 

run:	all
	@for benchmark in $(BENCHMARKS) ; do \
	  ./$$benchmark; \
	done

run-loops:	$(LOOP_KERNELS)
	@for benchmark in $(LOOP_KERNELS) ; do \
	  ./$$benchmark; \
	done

############################################################################

looptest:	looptest.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o looptest looptest.o $(LIBS)

haney:  haney.o haneyf.o
	${CXX} $(CXXFLAGS) $(LDFLAGS) -o haney haney.o haneyf.o $(LIBS)

daxpyf90.o:	daxpyf90.f
	$(F90) $(F90FLAGS) -c daxpyf90.f

daxpy:	daxpy.o fdaxpy.o fidaxpy.o daxpyf90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o daxpy daxpy.o fdaxpy.o \
           fidaxpy.o daxpyf90.o $(LIBS)

qcd:	qcd.o qcdf.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o qcd qcd.o qcdf.o $(LIBS)

STENCIL_OBJS = stencil.o stencilf.o stencilf2.o stencilf90.o

stencilf90.o:	stencilf90.f
	$(F90) $(F90FLAGS) -c stencilf90.f

stencil:	$(STENCIL_OBJS)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o stencil $(STENCIL_OBJS) $(LIBS)

ACOUSTIC_OBJS = acoustic.o acousticf.o acousticf2.o acousticf90.o acousticf902.o

acousticf90.o:	acousticf90.f
	$(F90) $(F90FLAGS) -c acousticf90.f

acousticf902.o:	acousticf902.f
	$(F90) $(F90FLAGS) -c acousticf902.f

acoustic:	$(ACOUSTIC_OBJS)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o acoustic $(ACOUSTIC_OBJS) $(LIBS)

ACOU3D_OBJS = acou3db1.o acou3db2.o acou3db3.o acou3db4.o acou3d.o acou3df90.o \
	acou3df.o acou3df2.o acou3df902.o

acou3df90.o:	acou3df90.f
	$(F90) $(F90FLAGS) -c acou3df90.f

acou3df902.o:	acou3df902.f
	$(F90) $(F90FLAGS) -c acou3df902.f

acou3d:	$(ACOU3D_OBJS)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o acou3d $(ACOU3D_OBJS) $(LIBS)

tinydaxpy:	tinydaxpy.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o tinydaxpy tinydaxpy.o $(LIBS)

hao-he:	hao-he.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o hao-he hao-he.o $(LIBS)

stenciln:	stenciln.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o stenciln stenciln.o $(LIBS)

############################################################################
# Loop kernel tests
#
# Note: The loop numbers skip around because they represent
# selected loops from a suite used by IBM researchers to test
# the RS/6000.  Missing loops are ones which were too complicated
# to generate automatically.
#
# This section generated by makeloops.cpp

loop1f90.o:	loop1f90.f
	$(F90) $(F90FLAGS) -c loop1f90.f

loop1:	loop1.o loop1f.o loop1f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop1 loop1.o loop1f.o loop1f90.o $(LIBS)

loop2f90.o:	loop2f90.f
	$(F90) $(F90FLAGS) -c loop2f90.f

loop2:	loop2.o loop2f.o loop2f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop2 loop2.o loop2f.o loop2f90.o $(LIBS)

loop3f90.o:	loop3f90.f
	$(F90) $(F90FLAGS) -c loop3f90.f

loop3:	loop3.o loop3f.o loop3f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop3 loop3.o loop3f.o loop3f90.o $(LIBS)

loop5f90.o:	loop5f90.f
	$(F90) $(F90FLAGS) -c loop5f90.f

loop5:	loop5.o loop5f.o loop5f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop5 loop5.o loop5f.o loop5f90.o $(LIBS)

loop6f90.o:	loop6f90.f
	$(F90) $(F90FLAGS) -c loop6f90.f

loop6:	loop6.o loop6f.o loop6f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop6 loop6.o loop6f.o loop6f90.o $(LIBS)

loop8f90.o:	loop8f90.f
	$(F90) $(F90FLAGS) -c loop8f90.f

loop8:	loop8.o loop8f.o loop8f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop8 loop8.o loop8f.o loop8f90.o $(LIBS)

loop9f90.o:	loop9f90.f
	$(F90) $(F90FLAGS) -c loop9f90.f

loop9:	loop9.o loop9f.o loop9f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop9 loop9.o loop9f.o loop9f90.o $(LIBS)

loop10f90.o:	loop10f90.f
	$(F90) $(F90FLAGS) -c loop10f90.f

loop10:	loop10.o loop10f.o loop10f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop10 loop10.o loop10f.o loop10f90.o $(LIBS)

loop11f90.o:	loop11f90.f
	$(F90) $(F90FLAGS) -c loop11f90.f

loop11:	loop11.o loop11f.o loop11f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop11 loop11.o loop11f.o loop11f90.o $(LIBS)

loop12f90.o:	loop12f90.f
	$(F90) $(F90FLAGS) -c loop12f90.f

loop12:	loop12.o loop12f.o loop12f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop12 loop12.o loop12f.o loop12f90.o $(LIBS)

loop13f90.o:	loop13f90.f
	$(F90) $(F90FLAGS) -c loop13f90.f

loop13:	loop13.o loop13f.o loop13f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop13 loop13.o loop13f.o loop13f90.o $(LIBS)

loop14f90.o:	loop14f90.f
	$(F90) $(F90FLAGS) -c loop14f90.f

loop14:	loop14.o loop14f.o loop14f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop14 loop14.o loop14f.o loop14f90.o $(LIBS)

loop15f90.o:	loop15f90.f
	$(F90) $(F90FLAGS) -c loop15f90.f

loop15:	loop15.o loop15f.o loop15f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop15 loop15.o loop15f.o loop15f90.o $(LIBS)

loop16f90.o:	loop16f90.f
	$(F90) $(F90FLAGS) -c loop16f90.f

loop16:	loop16.o loop16f.o loop16f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop16 loop16.o loop16f.o loop16f90.o $(LIBS)

loop17f90.o:	loop17f90.f
	$(F90) $(F90FLAGS) -c loop17f90.f

loop17:	loop17.o loop17f.o loop17f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop17 loop17.o loop17f.o loop17f90.o $(LIBS)

loop18f90.o:	loop18f90.f
	$(F90) $(F90FLAGS) -c loop18f90.f

loop18:	loop18.o loop18f.o loop18f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop18 loop18.o loop18f.o loop18f90.o $(LIBS)

loop19f90.o:	loop19f90.f
	$(F90) $(F90FLAGS) -c loop19f90.f

loop19:	loop19.o loop19f.o loop19f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop19 loop19.o loop19f.o loop19f90.o $(LIBS)

loop21f90.o:	loop21f90.f
	$(F90) $(F90FLAGS) -c loop21f90.f

loop21:	loop21.o loop21f.o loop21f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop21 loop21.o loop21f.o loop21f90.o $(LIBS)

loop22f90.o:	loop22f90.f
	$(F90) $(F90FLAGS) -c loop22f90.f

loop22:	loop22.o loop22f.o loop22f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop22 loop22.o loop22f.o loop22f90.o $(LIBS)

loop23f90.o:	loop23f90.f
	$(F90) $(F90FLAGS) -c loop23f90.f

loop23:	loop23.o loop23f.o loop23f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop23 loop23.o loop23f.o loop23f90.o $(LIBS)

loop24f90.o:	loop24f90.f
	$(F90) $(F90FLAGS) -c loop24f90.f

loop24:	loop24.o loop24f.o loop24f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop24 loop24.o loop24f.o loop24f90.o $(LIBS)

loop25f90.o:	loop25f90.f
	$(F90) $(F90FLAGS) -c loop25f90.f

loop25:	loop25.o loop25f.o loop25f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop25 loop25.o loop25f.o loop25f90.o $(LIBS)

loop36f90.o:	loop36f90.f
	$(F90) $(F90FLAGS) -c loop36f90.f

loop36:	loop36.o loop36f.o loop36f90.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o loop36 loop36.o loop36f.o loop36f90.o $(LIBS)

###########################################################################

clean:
	rm -f *.o *.ii *.int.c *.s ${BENCHMARKS}

