#=======================================================================
#
# SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF END-USER LICENSE AGREEMENT FOR
# INTEL(R) ADVISOR XE.
#
# Copyright (C) 2014 Intel Corporation. All rights reserved
#
# THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT
# NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS.
#
# ========================================================================


NAME:=nqueens_advisor

ifeq ($(shell uname -m),x86_64)
Arch=intel64
libdir=lib64
FCFLAGS+= -m64
else
Arch=ia32
libdir=lib32
FCFLAGS+= -m32
endif #

FC = ifort
ADV_DIR = $(ADVISOR_2018_DIR)

ANNOTATE_FLAGS = -I $(ADV_DIR)/include/$(Arch) -L$(ADV_DIR)/$(libdir) -ladvisor -ldl

all: build
release: build
debug: build_debug

build: 1_nqueens_serial 3_nqueens_omp
build_debug: 1_nqueens_serial_debug 3_nqueens_omp_debug

#ADVISOR COMMENT: ensure the ADVISOR_2018_DIR environment variable is defined.
1_nqueens_serial: nqueens_serial.f90
ifeq ($(ADV_DIR),)
	@echo ADVISOR_2018_DIR environment variable not defined. Required to build annotated sample.
else
	$(FC) $(FCFLAGS) nqueens_serial.f90 $(ANNOTATE_FLAGS) -o 1_nqueens_serial -O2 -g
endif
1_nqueens_serial_debug: nqueens_serial.f90
ifeq ($(ADV_DIR),)
	@echo ADVISOR_2018_DIR environment variable not defined. Required to build annotated sample.
else
	$(FC) $(FCFLAGS) nqueens_serial.f90 $(ANNOTATE_FLAGS) -o 1_nqueens_serial_debug -O0 -g -D_DEBUG
endif
3_nqueens_omp: nqueens_omp.f90
	$(FC) -openmp $(FCFLAGS) nqueens_omp.f90 -o 3_nqueens_omp -O2 -g
3_nqueens_omp_debug: nqueens_omp.f90
	$(FC) -openmp $(FCFLAGS) nqueens_omp.f90 -o 3_nqueens_omp_debug -O0 -g -D_DEBUG 

EXECUTABLES =  1_nqueens_serial 2_nqueens_annotated 3_nqueens_omp 1_nqueens_serial_debug 2_nqueens_annotated_debug 3_nqueens_omp_debug

clean::
	rm -f $(EXECUTABLES) *.o
	
