#
# This is the global makefile for the DFT++ system.
# This particular makefile defines all the executables and objects
# files needed, who they depend on, and the compilation defaults.
#
# The file makefile.local is included below.
# That file defines the actual commands to use to run the C++
# compiler, library options and directories, etc., all of which are
# machine specific and depend on the local installation.  Hence the name.
#

#
# The final executables we want to produce.  For now, just the main
# executable.
#
EXEC_TARGETS = dft

all:  ${EXEC_TARGETS}

#
# Key header files
#
HEADERS = lin3.h complex.h parallel.h header.h commands/command.h

#
# Objects that define the commands
#
CMND_OBJS = commands/cmd_basis.o \
	commands/cmd_cntrl_algorithm.o commands/cmd_cntrl_dump_n.o \
	commands/cmd_cntrl_elec_stepsize.o commands/cmd_cntrl_energy_convergence.o \
	commands/cmd_cntrl_max_elec_steps.o \
	commands/cmd_cntrl_max_ionic_steps.o commands/cmd_cntrl_nel_fermi_tol.o	\
	commands/cmd_cntrl_stepsize_min.o commands/cmd_cntrl_subspace_rotation.o \
	commands/cmd_cntrl_update_stepsize.o commands/command.o \
	commands/cmd_elec_ex_corr.o	\
	commands/cmd_elec_fermi_fillings.o commands/cmd_elec_initial_fillings.o	\
	commands/cmd_elec_n_bands.o commands/cmd_electronic_minimization.o  \
	commands/cmd_ewald.o commands/cmd_ion.o \
	commands/cmd_ion_relax_param.o \
	commands/cmd_kpoint.o \
	commands/cmd_kpoint_folding.o commands/cmd_latt_scale.o \
	commands/cmd_relax_ions.o commands/cmd_spintype.o commands/cmd_symmetries.o	\
	commands/cmd_symmetry_matrix.o commands/cmd_wavefunction.o \
	commands/cmd_band_structure.o commands/cmd_cntrl_read_density.o \
	commands/cmd_coords_type.o \
	commands/cmd_cntrl_force_diff_check.o commands/cmd_spinorbit.o \
	commands/cmd_cntrl_linmin_method.o \
	commands/cmd_finite_diff_test.o commands/cmd_cntrl_read_vloc.o \
	commands/cmd_cntrl_read_vscloc.o commands/cmd_lattice.o	\
	commands/cmd_calculate_forces.o
#	commands/ion_dynamics_param.o commands/ionic_dynamics.o


DFT_OBJS = dft-two.o ColumnBundle.o IJLO.o \
	Control.o timer.o Ioninfo.o Elecinfo.o\
	Lattice.o Elecvars.o dist_multiply.o\
	RealArray.o ComplexArray.o System.o Output.o\
	mem.o dft_text_FILE.o dft_io.o parser.o diag_matrix.o \
	Speciesinfo.o ewald.o ComplexMatrix.o matrix_mult.o \
	rnd.o Symmetries.o symm.o dft_thread.o diaginnerouter.o \
	calcUVCn.o exc.o poisson.o calcener.o  PH.o calcelecgrad.o  \
	minimize.o fermifill.o dump.o finitediff.o \
	${CMND_OBJS}

# 
# Objects needed for planewave compilation.
#
PW_CMND_OBJS = commands/cmd_fftbox.o commands/cmd_elec_cutoff.o \
	commands/cmd_cntrl_force_convergence.o \
	commands/cmd_cntrl_force_diff_convergence.o commands/cmd_ion_species.o

PW_OBJS = PW_Basis.o PW_Column.o PW_IJ.o PW_LO.o PW_IonicPotential.o \
	  ft.o PW_ener.o PW_nlpot.o PW_precond.o PW_Vlocpot.o \
	  PW_symm.o PW_ionicforces.o ${PW_CMND_OBJS}

#
# Objects needed for wavelet compilation.
#
WL_CMND_OBJS = commands/cmd_WL_ion_species.o commands/cmd_gridspec.o \
	       commands/cmd_WL_embedding.o commands/cmd_WL_use_L_orthorhombic.o

WL_OBJS = WL_Basis.o WL_Column.o WL_IJ.o WL_LO.o \
	  grid.o transforms.o operators.o evaluators.o convsets.o conv3d.o \
	  WL_ener.o WL_nlpot.o WL_precond.o WL_Vlocpot.o \
          WL_symm.o WL_ionicforces.o coeff_d.o ${WL_CMND_OBJS}


DFT-PW_OBJS = ${DFT_OBJS} ${PW_OBJS}

DFT-WL_OBJS = ${DFT_OBJS} ${WL_OBJS}



#
# Decide, based on BASIS, which basis to use.
#
# For plane waves...
#BASISOPT = -DPLANEWAVES
#BASIS_OBJS = ${PW_OBJS}
#
# For wavelets...
BASISOPT = -DWAVELETS -Dnewgridtype
BASIS_OBJS = ${WL_OBJS}

#
# Include the machine dependent (local) makefile defining compilers,
# Linking options, etc. etc.
#
include makefile.local-wl

#
# Object files used to interface to lapack routines (in plain C and F77)
#
MATDIAGOBJS =  ${MATDIAG_OBJ}

#
# Objects depend on the headers
#
${MATDIAGOBJS}: ${HEADERS}
${DFT_OBJS}: ${HEADERS}

#
# Wavelet operator verification tests
#
WL_PRIM_OBJS = operators.o evaluators.o transforms.o convsets.o conv3d.o grid.o 
WLtests: gradtest transtest optest
gradtest: gradtest.c ${WL_PRIM_OBJS}
	${CC} ${CCOPTS} $< -o $@ ${WL_PRIM_OBJS} ${LIBS}
transtest: transtest.c ${WL_PRIM_OBJS}
	${CC} ${CCOPTS} $< -o $@ ${WL_PRIM_OBJS} ${LIBS}
optest: optest.c ${WL_PRIM_OBJS}
	${CC} ${CCOPTS} $< -o $@ ${WL_PRIM_OBJS} ${LIBS}

#
# Default compilation with C++ compiler or F77 compiler
#
.cpp.o: makefile
	${CPLUSPLUS} ${CPLUSPLUSOPTS} ${BASISOPT} -c $< -o $@

#
# Making the dft executables
#
dft: ${DFT_OBJS} ${BASIS_OBJS} ${HEADERS} ${MATDIAGOBJS}  
	 ${LINKER} ${BASISOPT} ${LINKOPTS} ${DFT_OBJS} $(BASIS_OBJS) ${MATDIAGOBJS} ${LIBS} -o dft


dft-pw: ${DFT-PW_OBJS}  ${HEADERS} ${MATDIAGOBJS} 
	 ${LINKER} ${LINKOPTS} ${DFT-PW_OBJS} ${MATDIAGOBJS} ${LIBS} -o dft-pw

dft-wl: ${DFT-WL_OBJS}  ${HEADERS} ${MATDIAGOBJS}  
	 ${LINKER} ${LINKOPTS} ${DFT-WL_OBJS} ${MATDIAGOBJS} ${LIBS} -o dft-wl


#
# Administrative options
#
clean:
	$(RM) *.o commands/*.o dft core


syntax highlighted by Code2HTML, v. 0.9.1