##########################################################
#
# This file
MAKEFILE = Makefile

# The general compiler
CC = gcc

# General macros to use
DEFINES =

# Linking flags
LDFLAGS = -lm

# If MPI on then activate macro and switch compiler
ifeq (${MPI},ON)
CC = mpicc
MPIDEFINE = -DMPICOMM 
else
MPIDEFINE = 
endif

# Optimizations
OPT = -O3 -Wall

# The header directory
INCLUDEDIR = include

# All project directories
FIELDDIR = field
GENERICDIR = generic
NODEDIR = node

# All header files
HEADERS = 							\
	${INCLUDEDIR}/comm.h			\
	${INCLUDEDIR}/constants.h		\
	${INCLUDEDIR}/global.h 			\
	${INCLUDEDIR}/input.h 			\
	${INCLUDEDIR}/inputData.h 		\
	${INCLUDEDIR}/lattice.h			\
	${INCLUDEDIR}/lattice_io.h 		\
	${INCLUDEDIR}/main.h 			\
	${INCLUDEDIR}/node.h 			\
	${INCLUDEDIR}/setsublattice.h 	\
	${INCLUDEDIR}/site.h 			\
	${INCLUDEDIR}/statistic.h 		\
	${INCLUDEDIR}/statisticEntry.h	\
	${INCLUDEDIR}/update.h			\
	${INCLUDEDIR}/utils.h			\
	${INCLUDEDIR}/vector.h
	
# All source files
SOURCES = 							\
	${GENERICDIR}/utils.c           \
	${NODEDIR}/comm.c         		\
	${NODEDIR}/vector.c				\
	${GENERICDIR}/lattice_io.c      \
	${GENERICDIR}/input.c			\
	${FIELDDIR}/setsublattice.c		\
	${FIELDDIR}/statistic.c 		\
	${FIELDDIR}/update.c            \
	${NODEDIR}/main.c

# Objects that are created
OBJECTS = ${SOURCES:.cpp=.o}

# Compiler flags
CFLAGS = ${OPT} -I. ${DEFINES} ${MPIDEFINE}

# Final make build
EXECUTE = ${MAKE} -f ${MAKEFILE} target "MYTARGET= $@"

# Default rule for C compilation
.c.o : $$@.c $$@.h
	${CC} -c ${CFLAGS} $<

# Dependencies of your objects
${OBJECTS} : ${HEADERS}

####        ####
# Our projects #
####        ####

hpsc_single : ${OBJECTS}
	${EXECUTE} \
	"DEFINES = ${DEFINES}"
	
hpsc_single_debug : ${OBJECTS}
	${EXECUTE} \
	"DEFINES = ${DEFINES} -DDEBUGPRINT"
	
hpsc_windows : ${OBJECTS}
	${EXECUTE} \
	"DEFINES = ${DEFINES}" \
	
hpsc_mpi : ${OBJECTS}
	${EXECUTE} \
	"DEFINES = ${DEFINES}" \
	"MPI = ON"
	
hpsc_mpi_debug : ${OBJECTS}
	${EXECUTE} \
	"DEFINES = ${DEFINES} -DDEBUGPRINT" \
	"MPI = ON"
	
hpsc_sgi : ${OBJECTS}
	${EXECUTE} \
	"DEFINES = ${DEFINES} -DBLADE_SPLIT" \
	"MPI = ON"
	
hpsc_sgi_debug : ${OBJECTS}
	${EXECUTE} \
	"DEFINES = ${DEFINES} -DBLADE_SPLIT -DDEBUGPRINT" \
	"MPI = ON"

# Cleaning it up
clean :
	rm -f *.o core

# Tricky trick
target : ${OBJECTS}
	${CC} ${CFLAGS} -o ${MYTARGET} ${LDFLAGS} \
	${OBJECTS}
	touch localmake
	
####       ####    /copyright____________________________
# The ~~END~~ #   < christoph.preis and~~~~~~~~~~~~~~~~~~|
####       ####    \florian.rappl - boulder colorado 2011|
##########################################################