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

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

PROG            = jacobi_serial_not_opt_$(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 $(SOURCES) -o $@ $(LIBS)
	@echo ' '
	@echo 'Program' $(PROG) 'compiled for' $(SYSTYPE) 'machine'
	@echo ' '

$(PROG_DEBUG): $(DEPENDENCIES)
	$(CC) $(CFLAGS) -Og -ggdb3 -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 -I./include $(SOURCES) -o $@ $(LIBS)
	@echo ' '
	@echo 'Program' $(PROG_MEMCHECK) 'compiled for' $(SYSTYPE) 'machine'
	@echo ' '

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

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