#####################################################################
#                                                                   #
# PARKBENCH Version 2.0                                             #
#                                                                   #
# November 10, 1995                                                 #
#                                                                   #
# University of Tennesee, Knoxville                                 #
# University of Southampton, United Kingdom                         #
#                                                                   #
#####################################################################

# Shell used to interpret @ commands
SHELL 	= /bin/sh

# Name of the recent NPB Suite included
NPBdir	= NPB2.1

lLIBs =		PBLAS SCALAPACK TOOLS BLACS BLAS \
		BLACS.pvm \
		BLACS.mpi \
		MPI2PVM

lLow_Level = 	poly1  poly2  rinf1  tick1 tick2 \
		comms1 comms2 comms3 poly3 synch1

lKernels.LA =	LU_solver MATMUL QR TRANS TRD
lKernels.NPB =	FT MG
lKernels =	$(lKernels.LA) $(lKernels.NPB)

lComp_Apps.NPB =	BT LU SP
lComp_Apps.oth =	PSTSWM
lComp_Apps =	$(lComp_Apps.NPB) $(lComp_Apps.oth)

lNPB =		$(lKernels.NPB) $(lComp_Apps.NPB)

# As default for NPBs
CLASS=S
NPROCS=1

# default target is always first
help:
	@ echo '  The following targets are available:'
	@ echo ' '
	@ echo '  make makeconf'
	@ echo '  make conf'
	@ echo ' '
	@ echo '  make doc'
	@ echo ' '
	@ echo '  make all'
	@ echo '  make all.pvm'
	@ echo '  make all.mpi'
	@ echo ' '
	@ echo '  make Low_Level'
	@ echo '  make Low_Level.seq'
	@ echo '  make Low_Level.mpi'
	@ echo '  make Low_Level.pvm'
	@ echo ' '
	@ echo '  make Kernels'
	@ echo '  make Kernels.mpi'
	@ echo '  make Kernels.pvm'
	@ echo ' '
	@ echo '  make Comp_Apps'
	@ echo '  make Comp_Apps.mpi'
	@ echo '  make Comp_Apps.pvm'
	@ echo ' '
	@ echo '  make NPB'
	@ echo '  make NPB.mpi'
	@ echo '  make NPB.pvm'
	@ echo ' '
	@ echo '  make clean'
	@ echo '  make clobber'
	@ echo ' '
	@ echo '  For more info on building individual benchmarks'
	@ echo '  please look at ParkBench/README.'

all:		Low_Level Kernels Comp_Apps
all.pvm:	Low_Level.pvm  Kernels.pvm  Comp_Apps.pvm
all.mpi:	Low_Level.mpi  Kernels.mpi  Comp_Apps.mpi
Low_Level:	Low_Level.all
Kernels:	Kernels.all
Comp_Apps:	Comp_Apps.all
NPB npb:	NPB.all
LIB lib:	LIB.all

doc:
	@ echo "   building in doc"
	cd doc; $(MAKE)
	@ echo "   done building in doc"

## prepares environment for the make              ##
## -> target makeconf forces a new building !! <- ##

null:

makeconf: null
	cd conf; makeconf; $(MAKE) conf

conf: null
	cd conf; $(MAKE)

##            Libraries           ##
## compiles libraries for linking ##
LIB.all: conf
	@ echo "   building in lib all"
	- cd lib; $(MAKE)
	@ echo "   done building in lib all"

LIB_Low_Level: conf
	@ echo "   building in lib Low_Level"
	- cd lib; $(MAKE) Low_Level
	@ echo "   done building in lib Low_Level"

LIB_Low_Level.seq: conf
	@ echo "   building in lib Low_Level seq"
	- cd lib; $(MAKE) Low_Level.seq
	@ echo "   done building in lib Low_Level seq"

LIB_Low_Level.pvm: conf
	@ echo "   building in lib Low_Level pvm"
	- cd lib; $(MAKE) Low_Level.pvm
	@ echo "   done building in lib Low_Level pvm"

LIB_Low_Level.mpi: conf
	@ echo "   building in lib Low_Level mpi"
	- cd lib; $(MAKE) Low_Level.mpi
	@ echo "   done building in lib Low_Level mpi"

LIB_Kernels: conf
	@ echo "   building in lib Kernels"
	- cd lib; $(MAKE) Kernels
	@ echo "   done building in lib Kernels"

LIB_Kernels.pvm: conf
	@ echo "   building in lib Kernels pvm"
	- cd lib; $(MAKE) Kernels.pvm
	@ echo "   done building in lib Kernels pvm"

LIB_Kernels.mpi: conf
	@ echo "   building in lib Kernels mpi"
	- cd lib; $(MAKE) Kernels.mpi
	@ echo "   done building in lib Kernels mpi"

$(lLIBs): conf
	@ echo "   building in lib $@"
	- cd lib; $(MAKE) $@
	@ echo "   done building in lib $@"


##            Low_Level              ##
## here are the rules for the codes  ##
Low_Level.all:	 LIB_Low_Level
	@ echo "   building in Low_Level all"
	- cd Low_Level; $(MAKE)
	@ echo "   done building in Low_Level all"

Low_Level.seq:	 LIB_Low_Level.seq
	@ echo "   building in Low_Level sequential"
	- cd Low_Level; $(MAKE) seq
	@ echo "   done building in Low_Level sequential"

Low_Level.pvm:	 LIB_Low_Level.pvm
	@ echo "   building in Low_Level PVM"
	- cd Low_Level; $(MAKE) pvm
	@ echo "   done building in Low_Level PVM"

Low_Level.mpi:	 LIB_Low_Level.mpi
	@ echo "   building in Low_Level MPI"
	- cd Low_Level; $(MAKE) mpi
	@ echo "   done building in Low_Level MPI"

$(lLow_Level): 	 LIB_Low_Level
	@ echo "   building in Low_Level $@"
	-  cd Low_Level; $(MAKE) $@
	@ echo "   done building in Low_Level $@"

##            Kernels                ##
## here are the rules for the codes  ##
Kernels.all:	 LIB_Kernels MPI2PVM
	@ echo "building in Kernels"
	- cd Kernels; $(MAKE) NPROCS=$(NPROCS) CLASS=$(CLASS)
	@ echo "done building in Kernels"

Kernels.seq:	 LIB_Kernels
	@ echo "building in Kernels sequential"
	- cd Kernels; $(MAKE) seq NPROCS=$(NPROCS) CLASS=$(CLASS)
	@ echo "done building in Kernels sequential"

Kernels.pvm:	 LIB_Kernels.pvm MPI2PVM
	@ echo "building in Kernels PVM"
	- cd Kernels; $(MAKE) pvm
	@ echo "done building in Kernels PVM"

Kernels.mpi:	 LIB_Kernels.mpi
	@ echo "building in Kernels MPI"
	- cd Kernels; $(MAKE) mpi NPROCS=$(NPROCS) CLASS=$(CLASS)
	@ echo "done building in Kernels MPI"

$(lKernels.LA): 	 LIB_Kernels
	@ echo "building in Kernels $@"
	-  cd Kernels; $(MAKE) $@
	@ echo "done building in Kernel $@"

##            Comp_Apps              ##
## here are the rules for the codes  ##
Comp_Apps.all:	 conf MPI2PVM
	@ echo "building in Comp_Apps"
	- cd Comp_Apps; $(MAKE) NPROCS=$(NPROCS) CLASS=$(CLASS)
	@ echo "done building in Comp_Apps"

Comp_Apps.seq:	 conf
	@ echo "building in Comp_Apps sequential"
	- cd Comp_Apps; $(MAKE) seq NPROCS=$(NPROCS) CLASS=$(CLASS)
	@ echo "done building in Comp_Apps sequential"

Comp_Apps.pvm:	 conf MPI2PVM
	@ echo "building in Comp_Apps PVM"
	- cd Comp_Apps; $(MAKE) pvm NPROCS=$(NPROCS) CLASS=$(CLASS)
	@ echo "done building in Comp_Apps PVM"

Comp_Apps.mpi:	 conf
	@ echo "building in Comp_Apps MPI"
	- cd Comp_Apps; $(MAKE) mpi NPROCS=$(NPROCS) CLASS=$(CLASS)
	@ echo "done building in Comp_Apps MPI"

$(lComp_Apps.oth): 	 conf
	@ echo "building in Comp_Apps $@"
	-  cd Comp_Apps; $(MAKE) $@
	@ echo "done building in Comp_Apps $@"

##            NPB                 ##
## here are the rules for the codes  ##
NPB.all:	NPB.mpi NPB.pvm

NPB.seq:	 conf
	@ echo "building in NPB sequential"
	@- cd $(NPBdir)/conifg ; cp suite.def suite.def.saved ; cp suite.def.seq suite.def
	- cd $(NPBdir); $(MAKE) suite
	- cd $(NPBdir)/config ; cp suite.def.saved suite.def
	@ echo "done building in NPB sequential"

NPB.mpi:	 conf
	@ echo "building in NPB"
	- cd $(NPBdir); $(MAKE) suite
	@ echo "done building in NPB"

NPB.pvm:	 conf MPI2PVM
	@ echo "building for PVM in NPB"
	- cd $(NPBdir); $(MAKE) suite.pvm
	@ echo "done building for PVM in NPB"

$(lNPB): 	 conf MPI2PVM
	@ echo "building in NPB $@"
	-  cd $(NPBdir); $(MAKE) $@ NPROCS=$(NPROCS) CLASS=$(CLASS)
	-  cd $(NPBdir); $(MAKE) $@_pvm NPROCS=$(NPROCS) CLASS=$(CLASS)
	@ echo "done building in NPB $@"

###  Cleanup  ###

# This target should remove object files, and stuff generated by the build.

clean: 
	- cd Low_Level; $(MAKE) clean
	- cd Kernels; $(MAKE) clean
	- cd Comp_Apps; $(MAKE) clean
	- cd $(NPBdir); $(MAKE) clean
	- cd lib; $(MAKE) clean
	- cd include; $(MAKE) clean
	- cd conf; $(MAKE) clean

# This target should clean, remove libraries and everything, including
# configuration information. A clobber should produce the original
# distribution!

clobber: 
	- cd Low_Level; $(MAKE) clobber
	- cd Kernels; $(MAKE) clobber
	- cd Comp_Apps; $(MAKE) clobber
	- cd $(NPBdir); $(MAKE) clobber
	- cd lib; $(MAKE) clobber
	- cd include; $(MAKE) clobber
	- cd conf; $(MAKE) clobber
	- rm -fr bin/* *~
