CC     = mpicc
CFLAGS = -Wall -Wextra -march=native
LIBS   = -lm -lmpi

SYSTYPE = $(strip $(shell uname -n))

PROG            = jacobi_mpi_Send_Recv_nonblocking_$(SYSTYPE)
PROG_DEBUG      = $(PROG)_DEBUG
PROG_MEMCHECK   = $(PROG)_MEMCHECK
PROG_CALLGRIND  = $(PROG)_CALLGRIND
PROG_CACHEGRIND = $(PROG)_CACHEGRIND

HEADERS       = $(wildcard ./include/*.h)
SOURCES       = $(wildcard ./src/*.c)
DEPENDENCIES  = $(SOURCES) $(HEADERS) Makefile

$(PROG): $(DEPENDENCIES)
	$(CC) $(CFLAGS) -O3 -I./include -I$(MPI_INC) $(SOURCES) -o $@ -L$(MPI_LIB) $(LIBS)
	@echo ' '
	@echo 'Program' $(PROG) 'compiled for' $(SYSTYPE) 'machine'
	@echo ' '

$(PROG_DEBUG): $(DEPENDENCIES)
	$(CC) $(CFLAGS) -Og -ggdb3 -DDEBUG -fno-omit-frame-pointer -I./include -I$(MPI_INC) $(SOURCES) -o $@ -L$(MPI_LIB) $(LIBS)
	@echo ' '
	@echo 'Program' $(PROG_DEBUG) 'compiled for' $(SYSTYPE) 'machine'
	@echo ' '

$(PROG_MEMCHECK): $(DEPENDENCIES)
	$(CC) $(CFLAGS) -Og -I./include -I$(MPI_INC) $(SOURCES) -o $@ -L$(MPI_LIB) $(LIBS)
	@echo ' '
	@echo 'Program' $(PROG_MEMCHECK) 'compiled for' $(SYSTYPE) 'machine'
	@echo ' '

$(PROG_CALLGRIND): $(DEPENDENCIES)
	$(CC) $(CFLAGS) -g -O3 -I./include -I$(MPI_INC) $(SOURCES) -o $@ -L$(MPI_LIB) $(LIBS)
	@echo ' '
	@echo 'Program' $(PROG_CALLGRIND) 'compiled for' $(SYSTYPE) 'machine'
	@echo ' '

$(PROG_CACHEGRIND): $(DEPENDENCIES)
	$(CC) $(CFLAGS) -g -O3 -I./include -I$(MPI_INC) $(SOURCES) -o $@ -L$(MPI_LIB) $(LIBS)
	@echo ' '
	@echo 'Program' $(PROG_CACHEGRIND) 'compiled for' $(SYSTYPE) 'machine'
	@echo ' '
