CC     = gcc
CFLAGS = -Wall -Wextra -march=native
OMP    = -fopenmp
LIBS   = -lm

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

PROG            = jacobi_serial_not_opt_$(SYSTYPE)
PROG_OMP        = jacobi_omp_not_opt_$(SYSTYPE)
PROG_DEBUG      = $(PROG_OMP)_DEBUG
PROG_MEMCHECK   = $(PROG_OMP)_MEMCHECK
PROG_CALLGRIND  = $(PROG_OMP)_CALLGRIND
PROG_CACHEGRIND = $(PROG_OMP)_CACHEGRIND

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

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

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

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

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

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

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