##
## Copyright 2016 Intel Corporation.
##
##
## This software and the related documents are Intel copyrighted materials, and your use of them is governed by
## the express license under which they were provided to you ('License'). Unless the License provides otherwise,
## you may not use, modify, copy, publish, distribute, disclose or transmit this software or the related
## documents without Intel's prior written permission.
## This software and the related documents are provided as is, with no express or implied warranties, other than
## those that are expressly stated in the License.
##

ifeq ($(G_SYSTEM),)
	exit 0
endif

CFLAGS   ?= $(G_CFLAGS)
CXXFLAGS ?= $(G_CXXFLAGS)

#
# Set binary architecture
#
ifeq ($(G_ARCH),intel64)
	CXXFLAGS    += -m64
endif

#
# Set build name and paths
#
PROJ_NAME := iw_resize
ifeq ($(OUT_NAME),)
	OUT_NAME := $(PROJ_NAME)
endif

CONF_LOC        := $(G_CONF_TBB)
BUILD_PATH      := $(G_BUILD_ROOT)/$(G_ARCH)/$(CONF_LOC)
BUILD_PATH2     := $(G_BUILD_ROOT)/$(G_ARCH)/$(G_CONF)
OBJ_PATH        := $(BUILD_PATH)/obj/$(PROJ_NAME)
OUT_FULL        := $(BUILD_PATH)/$(OUT_NAME)
INCLUDES        := -I$(IPPROOT)/include -I../../../../common/include -I./include

IPP_LIBS_PATH   := $(IPPROOT)/$(G_IPP_PATH_SUFFIX)
TBB_LIBS_PATH   := $(TBBROOT)/$(G_TBB_PATH_SUFFIX)
TBB_LIBS_PATH_2 := $(TBBROOT)/$(G_TBB_PATH_SUFFIX_2)

LIBS += -L$(BUILD_PATH) -L$(BUILD_PATH2) -lcommon $(IPP_LIBS_PATH)/libippi.a $(IPP_LIBS_PATH)/libipps.a $(IPP_LIBS_PATH)/libippvm.a $(IPP_LIBS_PATH)/libippcore.a
ifeq ($(PREBUILT),1)
	LIBS     := $(IPP_LIBS_PATH)/libipp_iw.a $(LIBS)
else
	INCLUDES := -I../../iw/include $(INCLUDES)
	LIBS     := $(BUILD_PATH2)/libipp_iw.a $(LIBS)
endif

ifeq ($(G_USERENDERER),1)
	CXXFLAGS += -DENABLE_RENDERING
	LIBS     += -lGL -lX11
endif
LIBS += -lpthread
LIBS += -ldl

ifeq ($(G_OMP_SUPPORTED),1)
	CXXFLAGS += $(G_CXX_OPENMP)
endif

ifeq ($(G_USETBB),1)
	INCLUDES   += -I$(TBBROOT)/include
	CXXFLAGS   += -DUSE_TBB
	LIBS       += -L$(TBB_LIBS_PATH) -L$(TBB_LIBS_PATH_2)
	ifeq ($(G_CONF),release)
		LIBS += -ltbb -ltbbmalloc
	else
		LIBS += -ltbb_debug -ltbbmalloc_debug
	endif
	LIBS += -Wl,-rpath,$(TBBROOT)/lib/$(G_ARCH)
endif

OBJS := $(patsubst src/%.cpp,$(OBJ_PATH)/%.o,$(wildcard src/*.cpp))

#
# Set variable targets
#
BUILD_TARGET := build

CLEAN_TARGET :=

all: out_path $(BUILD_TARGET)

build: obj_path out

out_path:
	mkdir -p $(BUILD_PATH)

obj_path:
	mkdir -p $(OBJ_PATH)

$(OBJ_PATH)/%.o : src/%.cpp
	$(CXX) -c $(G_EXE_CFLAGS) $(CXXFLAGS) $(INCLUDES) -o $@ $<

out: $(OBJS)
	$(CXX) $(G_EXE_LDFLAGS) $(CXXFLAGS) -o $(OUT_FULL) $? $(LIBS)

clean: $(CLEAN_TARGET)
	$(RM) $(OUT_FULL)
	$(RM) $(OBJS)
