BUILD_DIR := ./build/${CONFIG}
PKG_ROOT := ./${PKG_VER}
OBJS := $(addprefix ${BUILD_DIR}/, $(subst .cpp,.o,$(SRCS)))

.PHONY: ${PKG_VER}.patch	
all: ${PKG_ROOT}
prepare: ${PKG_ROOT}
patch: ${PKG_VER}.patch

${PKG_VER}.patch:
	@rm -rf temp
	@unzip ${PKG_VER}.zip -d temp >/dev/null
	@diff -ruN temp/${PKG_VER}/ ${PKG_ROOT} > ${PKG_VER}.patch; [ $$? -eq 1 ]
	@rm -rf temp
	@echo "Created" ${PKG_VER}.patch

CXXFLAGS += -std=c++11
CXXFLAGS_debug := ${CXXFLAGS} -O0 -g
CXXFLAGS_release := ${CXXFLAGS} -O2
	
INCLUDES += -I./ -I/usr/include/freetype2
DEFINES += -D${TARGET}

${OBJS}: $(BUILD_DIR)/%.o : ${PKG_ROOT}/%.cpp
	mkdir -p $(dir $@)
	g++ ${CXXFLAGS_${CONFIG}} ${DEFINES} ${INCLUDES} -o $@ -c $<

${PKG_ROOT}:
	unzip ${PKG_VER}.zip
	if [ -e ${PKG_VER}.patch ]; then \
	   patch -p0 < ${PKG_VER}.patch;\
	fi

clean:
	rm -rf ${BUILD_DIR}/*

distclean:
	rm -rf ${BUILD_DIR}
	rm -rf ${PKG_ROOT}

