#=======================================================================
# Copyright (C) 2017 Intel Corporation. All Rights Reserved.
 
 # The source code, information and material ("Material") 
 # contained herein is owned by Intel Corporation or its 
 # suppliers or licensors, and title to such Material remains 
 # with Intel Corporation or its suppliers or licensors.
 # The Material contains proprietary information of Intel or 
 # its suppliers and licensors. The Material is protected by 
 # worldwide copyright laws and treaty provisions.
 # No part of the Material may be used, copied, reproduced, 
 # modified, published, uploaded, posted, transmitted, distributed 
 # or disclosed in any way without Intel's prior express written 
 # permission. No license under any patent, copyright or other
 # intellectual property rights in the Material is granted to or 
 # conferred upon you, either expressly, by implication, inducement, 
 # estoppel or otherwise. Any license under such intellectual 
 # property rights must be express and approved by Intel in writing.
 # Third Party trademarks are the property of their respective owners.
 # Unless otherwise agreed by Intel in writing, you may not remove 
 # or alter this notice or any other notice embedded in Materials 
 # by Intel or Intel's suppliers or licensors in any way.
# ======================================================================


NAME:=mmult_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_mmult_serial 2_mmult_annotated 3_mmult_omp
build_debug: 1_mmult_serial_debug 2_mmult_annotated_debug 3_mmult_omp_debug

#ADVISOR COMMENT: If you add annotations to the serial version, you should uncomment the $(ANNOTATE_FLAGS) addition
# at the end of the 2 build lines below. Also, ensure the ADVISOR_2018_DIR environment variable is defined.
1_mmult_serial: mmult_serial.f90
	$(FC) $(FCFLAGS) mmult_serial.f90 -o 1_mmult_serial -O2 -g #$(ANNOTATE_FLAGS)
1_mmult_serial_debug: mmult_serial.f90
	$(FC) $(FCFLAGS) mmult_serial.f90 -o 1_mmult_serial_debug -O0 -g -D_DEBUG #$(ANNOTATE_FLAGS)
2_mmult_annotated: mmult_annotated.f90
ifeq ($(ADV_DIR),)
	@echo ADVISOR_2018_DIR environment variable not defined. Required to build annotated sample.
else
	$(FC) $(FCFLAGS) mmult_annotated.f90 $(ANNOTATE_FLAGS) -o 2_mmult_annotated -O2 -g
endif
2_mmult_annotated_debug: mmult_annotated.f90
ifeq ($(ADV_DIR),)
	@echo ADVISOR_2018_DIR environment variable not defined. Required to build annotated sample.
else
	$(FC) $(FCFLAGS) mmult_annotated.f90 $(ANNOTATE_FLAGS) -o 2_mmult_annotated_debug -O0 -g -D_DEBUG
endif
3_mmult_omp: mmult_omp.f90
	$(FC) -qopenmp $(FCFLAGS) mmult_omp.f90 -o 3_mmult_omp -O2 -g
3_mmult_omp_debug: mmult_omp.f90
	$(FC) -qopenmp $(FCFLAGS) mmult_omp.f90 -o 3_mmult_omp_debug -O0 -g -D_DEBUG 

EXECUTABLES =  1_mmult_serial 2_mmult_annotated 3_mmult_omp 1_mmult_serial_debug 2_mmult_annotated_debug 3_mmult_omp_debug

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