##
## 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

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

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

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

CONF_LOC        := $(G_CONF_DIR)
BUILD_PATH      := $(G_BUILD_ROOT)/$(ARCH)/$(CONF_LOC)
BUILD_PATH2     := $(G_BUILD_ROOT)/$(ARCH)/$(CONF_LOC)
OBJ_PATH        := $(BUILD_PATH)/obj/$(PROJ_NAME)
INCLUDES        := -I$(IPPROOT)/include -I../../../../common/include -I../../iw/include -I../iw_common/include -I./include

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

LIBS += -L$(BUILD_PATH)/.. -lcommon $(IPP_LIBS_PATH)/libippi.a $(IPP_LIBS_PATH)/libipps.a $(IPP_LIBS_PATH)/libippvm.a $(IPP_LIBS_PATH)/libippcore.a
ifeq ($(G_USERENDERER),1)
	CXXFLAGS += -DENABLE_RENDERING
	LIBS     += -lGL -lX11
endif

LIBS += -lrt
LIBS := $(BUILD_PATH2)/libippi_tl$(G_LIB_SFX).a $(BUILD_PATH2)/libippcore_tl$(G_LIB_SFX).a $(LIBS)

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

#
# Set variable targets
#
BUILD_TARGET := build

CLEAN_TARGET :=

ifneq ($(TBBROOT),)
	GIMME_TBB := -lpthread -ltbb
endif


all: out_path $(BUILD_TARGET)

build: obj_path out

out_path:
	mkdir -p $(BUILD_PATH)

obj_path:
	mkdir -p $(OBJ_PATH)

out: $(PROGS)

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

$(BUILD_PATH)/% : $(OBJ_PATH)/%.o
	$(CXX) $(G_EXE_LDFLAGS) $(CXXFLAGS) -o $@ $< $(LIBS) $(GIMME_TBB) 

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