#===============================================================================
#
# BQCD -- Berlin Quantum ChromoDynamics programme
#
# Author: Hinnerk Stueben <stueben@zib.de>
#
# Copyright (C) 1998-2006, Hinnerk Stueben, Zuse-Institut Berlin
#
#-------------------------------------------------------------------------------
#
# Makefile
#
#===============================================================================

include Makefile.defs

MODULES_DIR = modules

.SUFFIXES:
.SUFFIXES: .o .F90 .c


.F90.f90:
	$(FPP) $(FPPFLAGS) $< > $@

.F90.o:
	$(FPP) $(FPPFLAGS) $< > $*.f90
	$(F90) -c $(FFLAGS) -I$(MODULES_DIR) $*.f90


MODULES = $(MODULES_DIR)/*.o

OBJS = \
	action.o \
	cg.o \
	checks.o \
	$(CKSUM_O) \
	conf.o \
	conf_info.o \
	cooling.o \
	dsd.o \
	dsg.o \
	dsf.o \
	dsf1.o \
	dsf2.o \
	files.o \
	flip_bc.o \
	hmc.o \
	hmc_init_p.o \
	hmc_init_phi.o \
	hmc_integrator.o \
	hmc_forces.o \
	hmc_leap_frog.o \
	hmc_test.o \
	hmc_u.o \
	h_mult.o \
	index.o \
	index2.o \
	init_common.o \
	init_modules.o \
	iteration_count.o \
	mc.o \
	misc.o \
	mre.o \
	mtdagmt.o \
	m_tilde.o \
	polyakov_loop.o \
	$(RANDOM_O) \
	sc.o \
	service.o \
	staple.o \
	su3.o \
	swap.o \
	timing.o \
	traces.o \
	$(UUU_O) \
	w_mult.o \
	xyzt2i.o

LIBS = d/$(LIBD) comm/$(LIBCOMM) clover/$(LIBCLOVER)

kernel: 
	cd modules && $(MAKE)
	cd d && $(MAKE) fast 
	cd comm && $(MAKE) fast
	cd clover && $(MAKE) fast
	$(MAKE) ../kernel_A.a

../kernel_A.a: bqcd.o $(MODULES) $(OBJS) $(LIBS)
	$(AR) $(ARFLAGS) ../kernel_A.a *.o d/*.o modules/*.o comm/*.o clover/*.o

bqcd: bqcd.o $(MODULES) $(OBJS) $(LIBS)
	$(F90) -o $@ $(LDFLAGS) bqcd.o $(MODULES) $(OBJS) $(LIBS) $(SYSLIBS) 

 
fast:
	cd modules && $(MAKE)
	cd d && $(MAKE) fast 
	cd comm && $(MAKE) fast
	cd clover && $(MAKE) fast
	$(FAST_MAKE) bqcd

clean:
	rm -f bqcd.[0-9][0-9][0-9].* diag.[0-9][0-9] core app.rif
	rm -f random_test random_test.dump random_test.out
	rm -f test_echo
	rm -f a.out out out1 out2
	rm -f ../kernel-bqcd.a

tidy: clean
	rm -f *.[Toid] *.f90 *.mod work.pc work.pcl

clobber: tidy
	rm -f bqcd
	$(MAKE) clobber_libs
	cd modules && $(MAKE) clean

Modules:
	cd modules && $(MAKE)

libd:
	cd d && $(MAKE)

libclover: $(MODULES)
	cd clover && $(MAKE)

libs:
	cd d && $(MAKE)
	cd comm && $(MAKE)
	cd clover && $(MAKE)

clean_libs:
	cd d && $(MAKE) clean
	cd comm && $(MAKE) clean
	cd clover && $(MAKE) clean

clobber_libs:
	cd d && $(MAKE) clobber
	cd comm && $(MAKE) clobber
	cd clover && $(MAKE) clobber

the_ranf_test: ranf.o
	$(FPP) $(FPPFLAGS) ranf_test.F90 ranf_test.f90
	$(F90) ranf_test.f90 ranf.o
	./a.out | diff - ranf_test.reference

test_echo: test_echo.o service.o
	$(F90) -o $@ $(LDFLAGS) test_echo.o service.o

prep:
	rm -f Makefile.var service.F90
	ln -s platform/Makefile-$(PLATFORM).var Makefile.var
	ln -s platform/service-$(PLATFORM).F90 service.F90

prep-altix:
	$(MAKE) prep PLATFORM=altix

prep-bgl:
	$(MAKE) prep PLATFORM=bgl

prep-cray:
	$(MAKE) prep PLATFORM=cray

prep-hitachi:
	$(MAKE) prep PLATFORM=hitachi

prep-hitachi-omp:
	$(MAKE) prep PLATFORM=hitachi-omp

prep-ibm:
	$(MAKE) prep PLATFORM=ibm

prep-hp:
	$(MAKE) prep PLATFORM=hp

prep-intel:
	$(MAKE) prep PLATFORM=intel

prep-nec:
	$(MAKE) prep PLATFORM=nec

prep-sun:
	$(MAKE) prep PLATFORM=sun

#===============================================================================
