# Compiler to use
CC = gcc -std=c99
# -g for debug, -O2 for optimise and -Wall additional messages -lm for including the Math library
OPTIONS = -O2 -g -Wall -lm
# Directory for header file
INCLUDES = -I .
# Defines for compilation
debug: DEFINES += -DDEBUG
parallel: OPTIONS += -fopenmp
mic: CC = icc -mmic -Wall -std:c99
mic: OPTIONS = -O2 -openmp
# Name of target binary
TARGET = integral
# List of objects to be build
OBJS = \
	integral.o \
	random.o \
	analysis.o \
	array.o

# To declare all, clean are not files
.PHONY: all clean
 
# The main targets
all: target
 
%.o: %.c  # % pattern wildcard matching
	${CC} ${OPTIONS} ${DEFINES} -c $*.c ${INCLUDES}

# To print output of command 'ls'
list: 
	@echo $(shell ls)

# To clean this mess
clean:
	@echo "Cleaning up ..."
	-rm -rf *.o
	-rm ${TARGET}

# To link the program
mic: ${OBJS}
	@echo "Building MIC version ..."
	${CC} ${INCLUDES} ${OBJS} ${OPTIONS} -o ${TARGET}

parallel: ${OBJS}
	@echo "Building OMP version ..."
	${CC} ${INCLUDES} ${OBJS} ${OPTIONS} -o ${TARGET}

target: ${OBJS}
	@echo "Building ..."
	${CC} ${INCLUDES} ${OBJS} ${OPTIONS} -o ${TARGET}

debug: ${OBJS}
	@echo "Building debug version ..."
	${CC} ${INCLUDES} ${OBJS} ${OPTIONS} -o ${TARGET}
