Radix cross Linux

Radix Linux distribution for embedded systems.

637 Commits   4 Branches   3 Tags
author: Andrey V.Kosteltsev <kx@radix.pro> 2016-10-14 15:15:23 +0000 committer: Andrey V.Kosteltsev <kx@radix.pro> 2016-10-14 15:15:23 +0000 commit: 06edf95a4b548ff0d09d7302a27c15e36489a6b5 parent: f10724fe29db79f52f36eae07acd07aef0e2110d
Commit Summary:
Open Source x265 HEVC Encoder
Diffstat:
15 files changed, 1291 insertions, 0 deletions
diff --git a/libs/x265/2.1-x86_32/Makefile b/libs/x265/2.1-x86_32/Makefile
new file mode 100644
index 000000000..f96d41c47
--- /dev/null
+++ b/libs/x265/2.1-x86_32/Makefile
@@ -0,0 +1,195 @@
+
+COMPONENT_TARGETS  = $(HARDWARE_PC64)
+
+NEED_ABS_PATH      = true
+COMPONENT_IS_3PP   = true
+
+CREATE_X86_32_PACKAGE = true
+
+
+include ../../../build-system/constants.mk
+
+
+SOURCE_REQUIRES    = sources/packages/m/x265
+
+REQUIRES           = libs/x265/2.1
+REQUIRES          += libs/glibc/2.23-x86_32
+
+# ======= __END_OF_REQUIRES__ =======
+
+
+version            = 2.1
+tar_gz_archive     = $(SRC_PACKAGE_PATH)/packages/m/x265/x265-$(version).tar.gz
+SRC_ARCHIVE        = $(tar_gz_archive)
+SRC_DIR            = $(TARGET_BUILD_DIR)/x265-$(version)
+src_dir_name       = x265-$(version)
+doc_dir_name       = x265-$(version)
+src_done           = $(TARGET_BUILD_DIR)/.source_done
+
+PATCHES = PATCHES
+
+build_dir          = $(TARGET_BUILD_DIR)/build
+build_target       = $(TARGET_BUILD_DIR)/.build_done
+install_target     = $(TARGET_BUILD_DIR)/.install_done
+
+
+####### Targets
+
+PKG_GROUP = libs
+
+#
+# *PKG_NAME & *PKG_VERSION shouldn't be a reference to value.
+#
+X265_32_PKG_NAME                = x265-x32
+X265_32_PKG_VERSION             = 2.1
+X265_32_PKG_ARCH                = $(TOOLCHAIN)
+X265_32_PKG_DISTRO_NAME         = $(DISTRO_NAME)
+X265_32_PKG_DISTRO_VERSION      = $(DISTRO_VERSION)
+X265_32_PKG_GROUP               = $(PKG_GROUP)
+###                              |---handy-ruler-------------------------------|
+X265_32_PKG_SHORT_DESCRIPTION   = Open Source H265/HEVC video encoder
+X265_32_PKG_URL                 = $(BUG_URL)
+X265_32_PKG_LICENSE             = GPLv2
+X265_32_PKG_DESCRIPTION_FILE    = $(TARGET_BUILD_DIR)/$(X265_32_PKG_NAME)-pkg-description
+X265_32_PKG_DESCRIPTION_FILE_IN = $(X265_32_PKG_NAME)-pkg-description.in
+X265_32_PKG_INSTALL_SCRIPT      = $(X265_32_PKG_NAME)-pkg-install.sh
+
+X265_32_PKG      = $(CURDIR)/$(TARGET_BUILD_DIR)/$(X265_32_PKG_NAME)-package
+
+pkg_basename     = $(X265_32_PKG_NAME)-$(X265_32_PKG_VERSION)-$(X265_32_PKG_ARCH)-$(X265_32_PKG_DISTRO_NAME)-$(X265_32_PKG_DISTRO_VERSION)
+
+pkg_archive      = $(TARGET_BUILD_DIR)/$(PKG_GROUP)/$(pkg_basename).$(pkg_arch_suffix)
+pkg_signature    = $(call sign-name,$(pkg_archive))
+pkg_description  = $(call desc-name,$(pkg_archive))
+products         = $(call pkg-files,$(pkg_archive))
+
+
+BUILD_TARGETS    = $(build_target)
+BUILD_TARGETS   += $(install_target)
+
+PRODUCT_TARGETS  = $(products)
+
+ROOTFS_TARGETS   = $(pkg_archive)
+
+
+include ../../../build-system/core.mk
+
+
+env_sysroot = DESTDIR=$(X265_32_PKG)
+
+
+ARCH_ALIAS = x86
+
+
+TARGET_BIN_RPATH = /lib$(MULTILIB_X86_32_SUFFIX):/usr/lib$(MULTILIB_X86_32_SUFFIX)
+TARGET_LIB_RPATH = /lib$(MULTILIB_X86_32_SUFFIX):/usr/lib$(MULTILIB_X86_32_SUFFIX):/usr/lib/../lib$(MULTILIB_X86_32_SUFFIX)
+
+configure_switches  = -DCMAKE_BUILD_TYPE='Release'
+
+configure_switches += -DCMAKE_C_COMPILER='$(CROSS_PREFIX)gcc'
+configure_switches += -DCMAKE_CXX_COMPILER='$(CROSS_PREFIX)g++'
+configure_switches += -DCMAKE_LINKER='$(CROSS_PREFIX)ld'
+configure_switches += -DCMAKE_AR='$(CROSS_PREFIX)ar'
+configure_switches += -DCMAKE_NM='$(CROSS_PREFIX)nm'
+configure_switches += -DCMAKE_RANLIB='$(CROSS_PREFIX)ranlib'
+configure_switches += -DCMAKE_OBJCOPY='$(CROSS_PREFIX)objcopy'
+configure_switches += -DCMAKE_OBJDUMP='$(CROSS_PREFIX)objdump'
+configure_switches += -DCMAKE_STRIP='$(CROSS_PREFIX)strip'
+
+configure_switches += -DCMAKE_C_FLAGS:STRING='--sysroot=$(TARGET_DEST_DIR) -m32 $(CFLAGS) $(ARCH_FLAGS) $(ARCH_DEFS) $(HW_FLAGS) -fPIC'
+configure_switches += -DCMAKE_CXX_FLAGS:STRING='--sysroot=$(TARGET_DEST_DIR) -m32 $(CFLAGS) $(ARCH_FLAGS) $(ARCH_DEFS) $(HW_FLAGS) -fPIC'
+
+configure_switches += -DCMAKE_EXE_LINKER_FLAGS='--sysroot=$(TARGET_DEST_DIR) -m32 -Wl,-rpath,$(TARGET_BIN_RPATH) -L$(TARGET_DEST_DIR)/lib$(MULTILIB_X86_32_SUFFIX) -L$(TARGET_DEST_DIR)/usr/lib$(MULTILIB_X86_32_SUFFIX)'
+configure_switches += -DCMAKE_MODULE_LINKER_FLAGS='--sysroot=$(TARGET_DEST_DIR) -m32 -Wl,-rpath,$(TARGET_LIB_RPATH) -L$(TARGET_DEST_DIR)/lib$(MULTILIB_X86_32_SUFFIX) -L$(TARGET_DEST_DIR)/usr/lib$(MULTILIB_X86_32_SUFFIX)'
+configure_switches += -DCMAKE_SHARED_LINKER_FLAGS='--sysroot=$(TARGET_DEST_DIR) -m32 -Wl,-rpath,$(TARGET_LIB_RPATH) -L$(TARGET_DEST_DIR)/lib$(MULTILIB_X86_32_SUFFIX) -L$(TARGET_DEST_DIR)/usr/lib$(MULTILIB_X86_32_SUFFIX)'
+
+configure_switches += -DCMAKE_INSTALL_PREFIX=/usr
+
+configure_switches += -DBIN_INSTALL_DIR='bin/32'
+configure_switches += -DLIB_INSTALL_DIR='lib$(MULTILIB_X86_32_SUFFIX)'
+
+configure_switches += -DCMAKE_CROSSCOMPILING=True
+
+configure_switches += -DCMAKE_SYSTEM_NAME='Linux'
+configure_switches += -DCMAKE_SYSTEM_PROCESSOR=$(ARCH_ALIAS)
+configure_switches += -DDISABLE_X86_YASM=True
+
+configure_shared_switch  += -DENABLE_SHARED='TRUE'
+
+
+####### Dependencies
+
+$(src_done): $(SRC_ARCHIVE) $(PATCHES_DEP)
+	$(UNPACK_SRC_ARCHIVE)
+	$(APPLY_PATCHES)
+	@touch $@
+
+$(build_target): $(src_done)
+	@mkdir -p $(build_dir)
+	@( cd $(build_dir) ; \
+	   $(BUILD_ENVIRONMENT) cmake $(configure_switches)        \
+	                              $(configure_shared_switch)   \
+	                              ../$(src_dir_name)/source  ; \
+	   $(BUILD_ENVIRONMENT) $(MAKE) ; \
+	 )
+	@touch $@
+
+$(install_target): $(build_target)
+	@mkdir -p $(X265_32_PKG)
+	@cd $(build_dir) && $(BUILD_ENVIRONMENT) $(MAKE) -j1 install $(env_sysroot)
+	@rm -rf $(X265_32_PKG)/usr/include
+	@rm -rf $(X265_32_PKG)/usr/share
+	# ======= Install the same to $(TARGET_DEST_DIR) =======
+	$(call install-into-devenv, $(X265_32_PKG))
+	# ======= tune pkg-config *.pc search path to the target destination for development =======
+	@( cd $(TARGET_DEST_DIR)/usr/lib$(MULTILIB_X86_32_SUFFIX)/pkgconfig ; \
+	   sed -i "s,/usr,$(TARGET_DEST_DIR)/usr,g" x265.pc \
+	 )
+	# ======= Strip binaries =======
+	@( cd $(X265_32_PKG) ; \
+	   find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs $(STRIP) --strip-unneeded 2> /dev/null ; \
+	   find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs $(STRIP) --strip-unneeded 2> /dev/null ; \
+	   find . | xargs file | grep "current ar archive" | cut -f 1 -d : | xargs $(STRIP) -g 2> /dev/null \
+	 )
+ifneq ($(CHRPATH),)
+	# ======= Set RPATH/RUNPATH for target binaries =======
+	@( cd $(X265_32_PKG)/usr/bin/32 ; \
+	   for file in `find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs echo` ; do \
+	     rpath=`$(CHRPATH) -l $$file 2> /dev/null | grep "R*PATH"` ; \
+	     if echo "$$rpath" | grep -q "$(TARGET_DEST_DIR)" ; then \
+	       $(CHRPATH) -r $(TARGET_BIN_RPATH) $$file 1> /dev/null 2> /dev/null ; \
+	     fi ; \
+	   done ; \
+	 )
+	# ======= Set RPATH/RUNPATH for target shared objects =======
+	@( cd $(X265_32_PKG)/usr/lib$(MULTILIB_X86_32_SUFFIX) ; \
+	   for file in `find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs echo` ; do \
+	     rpath=`$(CHRPATH) -l $$file 2> /dev/null | grep "R*PATH"` ; \
+	     if echo "$$rpath" | grep -q "$(TARGET_DEST_DIR)" ; then \
+	       $(CHRPATH) -r $(TARGET_LIB_RPATH) $$file 1> /dev/null 2> /dev/null ; \
+	     fi ; \
+	   done ; \
+	 )
+endif
+	@touch $@
+
+$(X265_32_PKG_DESCRIPTION_FILE): $(X265_32_PKG_DESCRIPTION_FILE_IN)
+	@cat $< | $(SED) -e "s/@VERSION@/$(version)/g" > $@
+
+$(pkg_signature)   : $(pkg_archive) ;
+$(pkg_description) : $(pkg_archive) ;
+
+$(pkg_archive): $(install_target) $(X265_32_PKG_DESCRIPTION_FILE) $(X265_32_PKG_INSTALL_SCRIPT)
+	@cp $(X265_32_PKG_DESCRIPTION_FILE) $(X265_32_PKG)/.DESCRIPTION
+	@cp $(X265_32_PKG_INSTALL_SCRIPT) $(X265_32_PKG)/.INSTALL
+	@$(BUILD_PKG_REQUIRES) $(X265_32_PKG)/.REQUIRES
+	@echo "pkgname=$(X265_32_PKG_NAME)"                            >  $(X265_32_PKG)/.PKGINFO ; \
+	 echo "pkgver=$(X265_32_PKG_VERSION)"                          >> $(X265_32_PKG)/.PKGINFO ; \
+	 echo "arch=$(X265_32_PKG_ARCH)"                               >> $(X265_32_PKG)/.PKGINFO ; \
+	 echo "distroname=$(X265_32_PKG_DISTRO_NAME)"                  >> $(X265_32_PKG)/.PKGINFO ; \
+	 echo "distrover=$(X265_32_PKG_DISTRO_VERSION)"                >> $(X265_32_PKG)/.PKGINFO ; \
+	 echo "group=$(X265_32_PKG_GROUP)"                             >> $(X265_32_PKG)/.PKGINFO ; \
+	 echo "short_description=\"$(X265_32_PKG_SHORT_DESCRIPTION)\"" >> $(X265_32_PKG)/.PKGINFO ; \
+	 echo "url=$(X265_32_PKG_URL)"                                 >> $(X265_32_PKG)/.PKGINFO ; \
+	 echo "license=$(X265_32_PKG_LICENSE)"                         >> $(X265_32_PKG)/.PKGINFO
+	@$(FAKEROOT) sh -c "cd $(X265_32_PKG) && chown -R root:root . && $(MAKE_PACKAGE) --linkadd yes .."
diff --git a/libs/x265/2.1-x86_32/PATCHES b/libs/x265/2.1-x86_32/PATCHES
new file mode 100644
index 000000000..b03675d97
--- /dev/null
+++ b/libs/x265/2.1-x86_32/PATCHES
@@ -0,0 +1,3 @@
+
+../../../sources/packages/m/x265/patches/x265-2.1-cross.patch   -p0
+../../../sources/packages/m/x265/patches/x265-2.1-version.patch -p0
diff --git a/libs/x265/2.1-x86_32/x265-x32-pkg-description.in b/libs/x265/2.1-x86_32/x265-x32-pkg-description.in
new file mode 100644
index 000000000..3310764bb
--- /dev/null
+++ b/libs/x265/2.1-x86_32/x265-x32-pkg-description.in
@@ -0,0 +1,19 @@
+# HOW TO EDIT THIS FILE:
+# The "handy ruler" below makes it easier to edit a package description.  Line
+# up the first '|' above the ':' following the base package name, and the '|'
+# on the right side marks the last column you can put a character in.  You must
+# make exactly 11 lines for the formatting to be correct.  It's also
+# customary to leave one space after the ':'.
+
+        |-----handy-ruler------------------------------------------------------|
+x265-x32: x265-x32 @VERSION@ (x86_32 Open Source H265/HEVC video encoder)
+x265-x32:
+x265-x32: The High Efficiency Video Coding (HEVC) was developed by the ISO/IEC
+x265-x32: Moving Picture Experts Group (MPEG) and ITU-T Video Coding Experts
+x265-x32: Group (VCEG). HEVC is also known as ISO/IEC 23008-2 MPEG-H Part 2
+x265-x32: and ITU-T H.265. HEVC provides up to twice the data compression as
+x265-x32: the previous standard (H.264/MPEG-4 AVC). HEVC can support 8K Ultra
+x265-x32: High Definition video, with a picture size up to 8192x4320 pixels.
+x265-x32:
+x265-x32: Homepage: https://bitbucket.org/multicoreware/x265/wiki/Home
+x265-x32:
diff --git a/libs/x265/2.1-x86_32/x265-x32-pkg-install.sh b/libs/x265/2.1-x86_32/x265-x32-pkg-install.sh
new file mode 100755
index 000000000..8e8683cd6
--- /dev/null
+++ b/libs/x265/2.1-x86_32/x265-x32-pkg-install.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+# arg 1:  the new package version
+pre_install() {
+  /bin/true
+}
+
+# arg 1:  the new package version
+post_install() {
+  /bin/true
+}
+
+# arg 1:  the new package version
+# arg 2:  the old package version
+pre_update() {
+  /bin/true
+}
+
+# arg 1:  the new package version
+# arg 2:  the old package version
+post_update() {
+  post_install
+}
+
+# arg 1:  the old package version
+pre_remove() {
+  /bin/true
+}
+
+# arg 1:  the old package version
+post_remove() {
+  /bin/true
+}
+
+
+operation=$1
+shift
+
+$operation $*
diff --git a/libs/x265/2.1/Makefile b/libs/x265/2.1/Makefile
new file mode 100644
index 000000000..764c5055e
--- /dev/null
+++ b/libs/x265/2.1/Makefile
@@ -0,0 +1,329 @@
+
+COMPONENT_TARGETS  = $(HARDWARE_PC32)
+COMPONENT_TARGETS += $(HARDWARE_PC64)
+COMPONENT_TARGETS += $(HARDWARE_CB1X)
+COMPONENT_TARGETS += $(HARDWARE_CB2X)
+COMPONENT_TARGETS += $(HARDWARE_CB3X)
+COMPONENT_TARGETS += $(HARDWARE_FFRK3288)
+COMPONENT_TARGETS += $(HARDWARE_M201)
+COMPONENT_TARGETS += $(HARDWARE_MXQ)
+COMPONENT_TARGETS += $(HARDWARE_NIT6Q)
+COMPONENT_TARGETS += $(HARDWARE_OMAP5UEVM)
+COMPONENT_TARGETS += $(HARDWARE_DRA7XXEVM)
+COMPONENT_TARGETS += $(HARDWARE_CI20)
+COMPONENT_TARGETS += $(HARDWARE_BT1)
+
+
+NEED_ABS_PATH      = true
+COMPONENT_IS_3PP   = true
+
+
+include ../../../build-system/constants.mk
+
+
+SOURCE_REQUIRES    = sources/packages/m/x265
+
+ifeq ($(__USE_BUILT_GCC_LIBS__),yes)
+REQUIRES           = dev/gcc/5.3.0
+else
+REQUIRES          += libs/glibc/2.23
+endif
+
+# ======= __END_OF_REQUIRES__ =======
+
+
+version            = 2.1
+tar_gz_archive     = $(SRC_PACKAGE_PATH)/packages/m/x265/x265-$(version).tar.gz
+SRC_ARCHIVE        = $(tar_gz_archive)
+SRC_DIR            = $(TARGET_BUILD_DIR)/x265-$(version)
+src_dir_name       = x265-$(version)
+doc_dir_name       = x265-$(version)
+src_done           = $(TARGET_BUILD_DIR)/.source_done
+
+PATCHES = PATCHES
+
+build_12bit        = $(TARGET_BUILD_DIR)/build-12
+build_10bit        = $(TARGET_BUILD_DIR)/build-10
+
+build_dir          = $(TARGET_BUILD_DIR)/build
+build_target       = $(TARGET_BUILD_DIR)/.build_done
+install_target     = $(TARGET_BUILD_DIR)/.install_done
+
+
+####### Targets
+
+PKG_GROUP = libs
+
+#
+# *PKG_NAME & *PKG_VERSION shouldn't be a reference to value.
+#
+X265_PKG_NAME                = x265
+X265_PKG_VERSION             = 2.1
+X265_PKG_ARCH                = $(TOOLCHAIN)
+X265_PKG_DISTRO_NAME         = $(DISTRO_NAME)
+X265_PKG_DISTRO_VERSION      = $(DISTRO_VERSION)
+X265_PKG_GROUP               = $(PKG_GROUP)
+###                           |---handy-ruler-------------------------------|
+X265_PKG_SHORT_DESCRIPTION   = Open Source H265/HEVC video encoder
+X265_PKG_URL                 = $(BUG_URL)
+X265_PKG_LICENSE             = GPLv2
+X265_PKG_DESCRIPTION_FILE    = $(TARGET_BUILD_DIR)/$(X265_PKG_NAME)-pkg-description
+X265_PKG_DESCRIPTION_FILE_IN = $(X265_PKG_NAME)-pkg-description.in
+X265_PKG_INSTALL_SCRIPT      = $(X265_PKG_NAME)-pkg-install.sh
+
+X265_PKG         = $(CURDIR)/$(TARGET_BUILD_DIR)/$(X265_PKG_NAME)-package
+
+pkg_basename     = $(X265_PKG_NAME)-$(X265_PKG_VERSION)-$(X265_PKG_ARCH)-$(X265_PKG_DISTRO_NAME)-$(X265_PKG_DISTRO_VERSION)
+
+pkg_archive      = $(TARGET_BUILD_DIR)/$(PKG_GROUP)/$(pkg_basename).$(pkg_arch_suffix)
+pkg_signature    = $(call sign-name,$(pkg_archive))
+pkg_description  = $(call desc-name,$(pkg_archive))
+products         = $(call pkg-files,$(pkg_archive))
+
+BUILD_TARGETS    = $(build_target)
+BUILD_TARGETS   += $(install_target)
+
+PRODUCT_TARGETS  = $(products)
+
+ROOTFS_TARGETS   = $(pkg_archive)
+
+
+include ../../../build-system/core.mk
+
+
+env_sysroot = DESTDIR=$(X265_PKG)
+
+
+ifneq ($(filter $(HARDWARE),$(HARDWARE_CB1X)      \
+                            $(HARDWARE_CB2X)      \
+                            $(HARDWARE_CB3X)      \
+                            $(HARDWARE_FFRK3288)  \
+                            $(HARDWARE_M201)      \
+                            $(HARDWARE_MXQ)       \
+                            $(HARDWARE_NIT6Q)     \
+                            $(HARDWARE_OMAP5UEVM) \
+                            $(HARDWARE_DRA7XXEVM)),)
+ARCH_ALIAS = armv7l
+endif
+ifneq ($(filter $(HARDWARE),$(HARDWARE_PC32)),)
+ARCH_ALIAS = x86
+endif
+ifneq ($(filter $(HARDWARE),$(HARDWARE_PC64)),)
+ARCH_ALIAS = x86_64
+endif
+ifneq ($(filter $(HARDWARE),$(HARDWARE_CI20) $(HARDWARE_BT1)),)
+ARCH_ALIAS = mipsel
+endif
+
+
+TARGET_BIN_RPATH = /lib$(LIBSUFFIX):/usr/lib$(LIBSUFFIX)
+TARGET_LIB_RPATH = /lib$(LIBSUFFIX):/usr/lib$(LIBSUFFIX):/usr/lib/../lib$(LIBSUFFIX)
+
+
+configure_switches  = -DCMAKE_BUILD_TYPE='Release'
+
+configure_switches += -DCMAKE_C_COMPILER='$(CROSS_PREFIX)gcc'
+configure_switches += -DCMAKE_CXX_COMPILER='$(CROSS_PREFIX)g++'
+
+ifeq ($(filter $(HARDWARE),$(HARDWARE_PC32) \
+                           $(HARDWARE_PC64) \
+                           $(HARDWARE_CI20) \
+                           $(HARDWARE_BT1)),)
+configure_switches += -DCMAKE_ASM_COMPILER='$(CROSS_PREFIX)gcc'
+endif
+
+configure_switches += -DCMAKE_LINKER='$(CROSS_PREFIX)ld'
+configure_switches += -DCMAKE_AR='$(CROSS_PREFIX)ar'
+configure_switches += -DCMAKE_NM='$(CROSS_PREFIX)nm'
+configure_switches += -DCMAKE_RANLIB='$(CROSS_PREFIX)ranlib'
+configure_switches += -DCMAKE_OBJCOPY='$(CROSS_PREFIX)objcopy'
+configure_switches += -DCMAKE_OBJDUMP='$(CROSS_PREFIX)objdump'
+configure_switches += -DCMAKE_STRIP='$(CROSS_PREFIX)strip'
+
+configure_switches += -DCMAKE_C_FLAGS:STRING='--sysroot=$(TARGET_DEST_DIR) $(CFLAGS) $(ARCH_FLAGS) $(ARCH_DEFS) $(HW_FLAGS) -fPIC'
+configure_switches += -DCMAKE_CXX_FLAGS:STRING='--sysroot=$(TARGET_DEST_DIR) $(CFLAGS) $(ARCH_FLAGS) $(ARCH_DEFS) $(HW_FLAGS) -fPIC'
+
+
+ifeq ($(filter $(HARDWARE),$(HARDWARE_PC32) \
+                           $(HARDWARE_PC64) \
+                           $(HARDWARE_CI20) \
+                           $(HARDWARE_BT1)),)
+configure_switches += -DCMAKE_ASM_FLAGS:STRING='--sysroot=$(TARGET_DEST_DIR) $(CFLAGS) $(ARCH_FLAGS) $(ARCH_DEFS) $(HW_FLAGS) -fPIC'
+endif
+
+configure_switches += -DCMAKE_EXE_LINKER_FLAGS='--sysroot=$(TARGET_DEST_DIR) -Wl,-rpath,$(TARGET_BIN_RPATH) -L$(TARGET_DEST_DIR)/lib$(LIBSUFFIX) -L$(TARGET_DEST_DIR)/usr/lib$(LIBSUFFIX)'
+configure_switches += -DCMAKE_MODULE_LINKER_FLAGS='--sysroot=$(TARGET_DEST_DIR) -Wl,-rpath,$(TARGET_LIB_RPATH) -L$(TARGET_DEST_DIR)/lib$(LIBSUFFIX) -L$(TARGET_DEST_DIR)/usr/lib$(LIBSUFFIX)'
+configure_switches += -DCMAKE_SHARED_LINKER_FLAGS='--sysroot=$(TARGET_DEST_DIR) -Wl,-rpath,$(TARGET_LIB_RPATH) -L$(TARGET_DEST_DIR)/lib$(LIBSUFFIX) -L$(TARGET_DEST_DIR)/usr/lib$(LIBSUFFIX)'
+
+
+ifeq ($(TOOLCHAIN),$(TOOLCHAIN_JZ47XX_GLIBC))
+configure_switches += -DCMAKE_C_FLAGS_RELEASE='-O2 -DNDEBUG'
+configure_switches += -DCMAKE_CXX_FLAGS_RELEASE='-O2 -DNDEBUG'
+endif
+
+configure_switches += -DCMAKE_INSTALL_PREFIX=/usr
+
+configure_switches += -DBIN_INSTALL_DIR='bin'
+configure_switches += -DLIB_INSTALL_DIR='lib$(LIBSUFFIX)'
+
+configure_switches += -DCMAKE_CROSSCOMPILING=True
+
+configure_switches += -DCMAKE_SYSTEM_NAME='Linux'
+configure_switches += -DCMAKE_SYSTEM_PROCESSOR=$(ARCH_ALIAS)
+ifneq ($(filter $(HARDWARE),$(HARDWARE_PC32) $(HARDWARE_PC64)),)
+configure_switches += -DDISABLE_X86_YASM=True
+endif
+
+configure_switches += -DENABLE_LIBNUMA='FALSE'
+
+
+configure_12bit_switches += -DHIGH_BIT_DEPTH='TRUE'
+configure_12bit_switches += -DMAIN12='TRUE'
+configure_12bit_switches += -DEXPORT_C_API='FALSE'
+configure_12bit_switches += -DENABLE_CLI='FALSE'
+configure_12bit_switches += -DENABLE_SHARED='FALSE'
+
+configure_10bit_switches += -DHIGH_BIT_DEPTH='TRUE'
+configure_10bit_switches += -DEXPORT_C_API='FALSE'
+configure_10bit_switches += -DENABLE_CLI='FALSE'
+configure_10bit_switches += -DENABLE_SHARED='FALSE'
+
+configure_08bit_switches += -DENABLE_SHARED='TRUE'
+configure_08bit_switches += -DEXTRA_LIB='x265_main10.a;x265_main12.a'
+configure_08bit_switches += -DEXTRA_LINK_FLAGS='-L.'
+configure_08bit_switches += -DLINKED_10BIT='TRUE'
+configure_08bit_switches += -DLINKED_12BIT='TRUE'
+
+
+configure_shared_switch  += -DENABLE_SHARED='TRUE'
+
+
+####### Dependencies
+
+$(src_done): $(SRC_ARCHIVE) $(PATCHES_DEP)
+	$(UNPACK_SRC_ARCHIVE)
+	$(APPLY_PATCHES)
+	@touch $@
+
+$(build_target): $(src_done)
+	@mkdir -p $(build_dir)
+ifneq ($(filter $(HARDWARE),$(HARDWARE_PC64)),)
+	@mkdir -p $(build_12bit)
+	@( cd $(build_12bit) ; \
+	   $(BUILD_ENVIRONMENT) cmake $(configure_switches)        \
+	                              $(configure_12bit_switches)  \
+	                              ../$(src_dir_name)/source  ; \
+	   $(BUILD_ENVIRONMENT) $(MAKE) ; \
+	 )
+	@mkdir -p $(build_10bit)
+	@( cd $(build_10bit) ; \
+	   $(BUILD_ENVIRONMENT) cmake $(configure_switches)        \
+	                              $(configure_10bit_switches)  \
+	                              ../$(src_dir_name)/source  ; \
+	   $(BUILD_ENVIRONMENT) $(MAKE) ; \
+	 )
+	@( cd $(build_dir) ; \
+	   ln -sf ../$(notdir $(build_12bit))/libx265.a libx265_main12.a ; \
+	   ln -sf ../$(notdir $(build_10bit))/libx265.a libx265_main10.a ; \
+	   $(BUILD_ENVIRONMENT) cmake $(configure_switches)        \
+	                              $(configure_08bit_switches)  \
+	                              $(configure_shared_switch)   \
+	                              ../$(src_dir_name)/source  ; \
+	   $(BUILD_ENVIRONMENT) $(MAKE) ; \
+	 )
+else
+	@( cd $(build_dir) ; \
+	   $(BUILD_ENVIRONMENT) cmake $(configure_switches)        \
+	                              $(configure_shared_switch)   \
+	                              ../$(src_dir_name)/source  ; \
+	   $(BUILD_ENVIRONMENT) $(MAKE) ; \
+	 )
+endif
+	@touch $@
+
+$(install_target): $(build_target)
+	@mkdir -p $(X265_PKG)
+	@cd $(build_dir) && $(BUILD_ENVIRONMENT) $(MAKE) -j1 install $(env_sysroot)
+	# ======= Install Documentation =======
+	@if [ -d $(X265_PKG)/usr/share/man ]; then \
+	  ( cd $(X265_PKG)/usr/share/man ; \
+	    for manpagedir in `find . -type d -name "man*"` ; do \
+	      ( cd $$manpagedir ; \
+	        for eachpage in `find . -type l -maxdepth 1` ; do \
+	          ln -s `readlink $$eachpage`.gz $$eachpage.gz ; \
+	          rm $$eachpage ; \
+	        done ; \
+	        gzip -9 *.?  ; \
+	      ) \
+	    done \
+	  ) \
+	 fi
+	@mkdir -p $(X265_PKG)/usr/doc/$(doc_dir_name)
+	@cp -a $(SRC_DIR)/COPYING \
+	       $(X265_PKG)/usr/doc/$(doc_dir_name)
+	@mkdir -p $(X265_PKG)/usr/share/doc/$(doc_dir_name)
+	@( cd $(SRC_DIR) ; \
+	   cp -a COPYING \
+	         $(X265_PKG)/usr/share/doc/$(doc_dir_name) \
+	 )
+	@( cd $(SRC_DIR) ; \
+	   if [ -r ChangeLog -a -s ChangeLog ]; then \
+	     DOCSDIR=`echo $(X265_PKG)/usr/share/doc/$(doc_dir_name)` ; \
+	     cat ChangeLog | head -n 1000 > $$DOCSDIR/ChangeLog ; \
+	     touch -r ChangeLog $$DOCSDIR/ChangeLog ; \
+	   fi \
+	 )
+	# ======= Install the same to $(TARGET_DEST_DIR) =======
+	$(call install-into-devenv, $(X265_PKG))
+	# ======= tune pkg-config *.pc search path to the target destination for development =======
+	@( cd $(TARGET_DEST_DIR)/usr/lib$(LIBSUFFIX)/pkgconfig ; \
+	   sed -i "s,/usr,$(TARGET_DEST_DIR)/usr,g" x265.pc \
+	 )
+	# ======= Strip binaries =======
+	@( cd $(X265_PKG) ; \
+	   find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs $(STRIP) --strip-unneeded 2> /dev/null ; \
+	   find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs $(STRIP) --strip-unneeded 2> /dev/null ; \
+	   find . | xargs file | grep "current ar archive" | cut -f 1 -d : | xargs $(STRIP) -g 2> /dev/null \
+	 )
+ifneq ($(CHRPATH),)
+	# ======= Set RPATH/RUNPATH for target binaries =======
+	@( cd $(X265_PKG)/usr/bin ; \
+	   for file in `find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs echo` ; do \
+	     rpath=`$(CHRPATH) -l $$file 2> /dev/null | grep "R*PATH"` ; \
+	     if echo "$$rpath" | grep -q "$(TARGET_DEST_DIR)" ; then \
+	       $(CHRPATH) -r $(TARGET_BIN_RPATH) $$file 1> /dev/null 2> /dev/null ; \
+	     fi ; \
+	   done ; \
+	 )
+	# ======= Set RPATH/RUNPATH for target shared objects =======
+	@( cd $(X265_PKG)/usr/lib$(LIBSUFFIX) ; \
+	   for file in `find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs echo` ; do \
+	     rpath=`$(CHRPATH) -l $$file 2> /dev/null | grep "R*PATH"` ; \
+	     if echo "$$rpath" | grep -q "$(TARGET_DEST_DIR)" ; then \
+	       $(CHRPATH) -r $(TARGET_LIB_RPATH) $$file 1> /dev/null 2> /dev/null ; \
+	     fi ; \
+	   done ; \
+	 )
+endif
+	@touch $@
+
+$(X265_PKG_DESCRIPTION_FILE): $(X265_PKG_DESCRIPTION_FILE_IN)
+	@cat $< | $(SED) -e "s/@VERSION@/$(version)/g" > $@
+
+$(pkg_signature)   : $(pkg_archive) ;
+$(pkg_description) : $(pkg_archive) ;
+
+$(pkg_archive): $(install_target) $(X265_PKG_DESCRIPTION_FILE) $(X265_PKG_INSTALL_SCRIPT)
+	@cp $(X265_PKG_DESCRIPTION_FILE) $(X265_PKG)/.DESCRIPTION
+	@cp $(X265_PKG_INSTALL_SCRIPT) $(X265_PKG)/.INSTALL
+	@$(BUILD_PKG_REQUIRES) $(X265_PKG)/.REQUIRES
+	@echo "pkgname=$(X265_PKG_NAME)"                            >  $(X265_PKG)/.PKGINFO ; \
+	 echo "pkgver=$(X265_PKG_VERSION)"                          >> $(X265_PKG)/.PKGINFO ; \
+	 echo "arch=$(X265_PKG_ARCH)"                               >> $(X265_PKG)/.PKGINFO ; \
+	 echo "distroname=$(X265_PKG_DISTRO_NAME)"                  >> $(X265_PKG)/.PKGINFO ; \
+	 echo "distrover=$(X265_PKG_DISTRO_VERSION)"                >> $(X265_PKG)/.PKGINFO ; \
+	 echo "group=$(X265_PKG_GROUP)"                             >> $(X265_PKG)/.PKGINFO ; \
+	 echo "short_description=\"$(X265_PKG_SHORT_DESCRIPTION)\"" >> $(X265_PKG)/.PKGINFO ; \
+	 echo "url=$(X265_PKG_URL)"                                 >> $(X265_PKG)/.PKGINFO ; \
+	 echo "license=$(X265_PKG_LICENSE)"                         >> $(X265_PKG)/.PKGINFO
+	@$(FAKEROOT) sh -c "cd $(X265_PKG) && chown -R root:root . && $(MAKE_PACKAGE) --linkadd yes .."
diff --git a/libs/x265/2.1/PATCHES b/libs/x265/2.1/PATCHES
new file mode 100644
index 000000000..b03675d97
--- /dev/null
+++ b/libs/x265/2.1/PATCHES
@@ -0,0 +1,3 @@
+
+../../../sources/packages/m/x265/patches/x265-2.1-cross.patch   -p0
+../../../sources/packages/m/x265/patches/x265-2.1-version.patch -p0
diff --git a/libs/x265/2.1/x265-pkg-description.in b/libs/x265/2.1/x265-pkg-description.in
new file mode 100644
index 000000000..5812c9fa4
--- /dev/null
+++ b/libs/x265/2.1/x265-pkg-description.in
@@ -0,0 +1,19 @@
+# HOW TO EDIT THIS FILE:
+# The "handy ruler" below makes it easier to edit a package description.  Line
+# up the first '|' above the ':' following the base package name, and the '|'
+# on the right side marks the last column you can put a character in.  You must
+# make exactly 11 lines for the formatting to be correct.  It's also
+# customary to leave one space after the ':'.
+
+    |-----handy-ruler------------------------------------------------------|
+x265: x265 @VERSION@ (Open Source H265/HEVC video encoder)
+x265:
+x265: The High Efficiency Video Coding (HEVC) was developed by the ISO/IEC
+x265: Moving Picture Experts Group (MPEG) and ITU-T Video Coding Experts
+x265: Group (VCEG). HEVC is also known as ISO/IEC 23008-2 MPEG-H Part 2
+x265: and ITU-T H.265. HEVC provides up to twice the data compression as
+x265: the previous standard (H.264/MPEG-4 AVC). HEVC can support 8K Ultra
+x265: High Definition video, with a picture size up to 8192x4320 pixels.
+x265:
+x265: Homepage: https://bitbucket.org/multicoreware/x265/wiki/Home
+x265:
diff --git a/libs/x265/2.1/x265-pkg-install.sh b/libs/x265/2.1/x265-pkg-install.sh
new file mode 100755
index 000000000..b44c4e648
--- /dev/null
+++ b/libs/x265/2.1/x265-pkg-install.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+# Preserve new files
+install_file() {
+  NEW="$1"
+  OLD="`dirname $NEW`/`basename $NEW .new`"
+  # If there's no file by that name, mv it over:
+  if [ ! -r $OLD ]; then
+    mv $NEW $OLD
+  elif [ "`cat $OLD | md5sum`" = "`cat $NEW | md5sum`" ]; then # toss the redundant copy
+    rm $NEW
+  fi
+  # Otherwise, we leave the .new copy for the admin to consider...
+}
+
+
+# arg 1:  the new package version
+pre_install() {
+  /bin/true
+}
+
+# arg 1:  the new package version
+post_install() {
+  /bin/true
+}
+
+# arg 1:  the new package version
+# arg 2:  the old package version
+pre_update() {
+  /bin/true
+}
+
+# arg 1:  the new package version
+# arg 2:  the old package version
+post_update() {
+  post_install
+}
+
+# arg 1:  the old package version
+pre_remove() {
+  /bin/true
+}
+
+# arg 1:  the old package version
+post_remove() {
+  /bin/true
+}
+
+
+operation=$1
+shift
+
+$operation $*
diff --git a/sources/packages/m/x265/Makefile b/sources/packages/m/x265/Makefile
new file mode 100644
index 000000000..c2deaa1c1
--- /dev/null
+++ b/sources/packages/m/x265/Makefile
@@ -0,0 +1,58 @@
+
+COMPONENT_TARGETS = $(HARDWARE_NOARCH)
+
+
+include ../../../../build-system/constants.mk
+
+
+url         = $(DOWNLOAD_SERVER)/sources/packages/m/x265
+
+versions    = 2.1
+pkgname     = x265
+suffix      = tar.gz
+
+tarballs    = $(addsuffix .$(suffix), $(addprefix $(pkgname)-, $(versions)))
+sha1s       = $(addsuffix .sha1sum, $(tarballs))
+
+patches     = $(CURDIR)/patches/x265-2.1-cross.patch
+patches    += $(CURDIR)/patches/x265-2.1-version.patch
+
+.NOTPARALLEL: $(patches)
+
+
+BUILD_TARGETS = $(tarballs) $(sha1s) $(patches)
+
+
+include ../../../../build-system/core.mk
+
+
+.PHONY: download_clean
+
+
+$(tarballs):
+	@echo -e "\n======= Downloading source tarballs =======" ; \
+	 for tarball in $(tarballs) ; do \
+	   echo "$(url)/$$tarball" | xargs -n 1 -P 100 wget $(WGET_OPTIONS) -i & \
+	 done ; wait
+
+$(sha1s): $(tarballs)
+	@for sha in $@ ; do \
+	   echo -e "\n======= Downloading '$$sha' signature =======\n" ; \
+	   echo "$(url)/$$sha" | xargs -n 1 -P 100 wget $(WGET_OPTIONS) -i & wait %1 ; \
+	   touch $$sha ; \
+	   echo -e "\n======= Check the '$$sha' sha1sum =======\n" ; \
+	   sha1sum --check $$sha ; ret="$$?" ; \
+	   if [ "$$ret" == "1" ]; then \
+	     echo -e "\n======= ERROR: Bad '$$sha' sha1sum =======\n" ; \
+	     exit 1 ; \
+	   fi ; \
+	 done
+
+$(patches): $(sha1s)
+	@echo -e "\n======= Create Patches =======\n" ; \
+	 ( cd create-2.1-cross-patch   ; ./create.patch.sh ) ; \
+	 ( cd create-2.1-version-patch ; ./create.patch.sh ) ; \
+	 echo -e "\n"
+
+download_clean:
+	@rm -f $(tarballs) $(sha1s) $(patches)
diff --git a/sources/packages/m/x265/create-2.1-cross-patch/create.patch.sh b/sources/packages/m/x265/create-2.1-cross-patch/create.patch.sh
new file mode 100755
index 000000000..05525cdd4
--- /dev/null
+++ b/sources/packages/m/x265/create-2.1-cross-patch/create.patch.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+VERSION=2.1
+
+tar --files-from=file.list -xzvf ../x265-$VERSION.tar.gz
+mv x265-$VERSION x265-$VERSION-orig
+
+cp -rf ./x265-$VERSION-new ./x265-$VERSION
+
+diff -b --unified -Nr  x265-$VERSION-orig  x265-$VERSION > x265-$VERSION-cross.patch
+
+mv x265-$VERSION-cross.patch ../patches
+
+rm -rf ./x265-$VERSION
+rm -rf ./x265-$VERSION-orig
diff --git a/sources/packages/m/x265/create-2.1-cross-patch/file.list b/sources/packages/m/x265/create-2.1-cross-patch/file.list
new file mode 100644
index 000000000..8027bc1c6
--- /dev/null
+++ b/sources/packages/m/x265/create-2.1-cross-patch/file.list
@@ -0,0 +1 @@
+x265-2.1/source/CMakeLists.txt
diff --git a/sources/packages/m/x265/create-2.1-cross-patch/x265-2.1-new/source/CMakeLists.txt b/sources/packages/m/x265/create-2.1-cross-patch/x265-2.1-new/source/CMakeLists.txt
new file mode 100644
index 000000000..bd2d17472
--- /dev/null
+++ b/sources/packages/m/x265/create-2.1-cross-patch/x265-2.1-new/source/CMakeLists.txt
@@ -0,0 +1,649 @@
+# vim: syntax=cmake
+if(NOT CMAKE_BUILD_TYPE)
+    # default to Release build for GCC builds
+    set(CMAKE_BUILD_TYPE Release CACHE STRING
+        "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel."
+        FORCE)
+endif()
+message(STATUS "cmake version ${CMAKE_VERSION}")
+if(POLICY CMP0025)
+    cmake_policy(SET CMP0025 OLD) # report Apple's Clang as just Clang
+endif()
+if(POLICY CMP0042)
+    cmake_policy(SET CMP0042 NEW) # MACOSX_RPATH
+endif()
+if(POLICY CMP0054)
+    cmake_policy(SET CMP0054 OLD) # Only interpret if() arguments as variables or keywords when unquoted
+endif()
+
+project (x265)
+cmake_minimum_required (VERSION 2.8.8) # OBJECT libraries require 2.8.8
+include(CheckIncludeFiles)
+include(CheckFunctionExists)
+include(CheckSymbolExists)
+include(CheckCXXCompilerFlag)
+
+option(FPROFILE_GENERATE "Compile executable to generate usage data" OFF)
+option(FPROFILE_USE "Compile executable using generated usage data" OFF)
+option(NATIVE_BUILD "Target the build CPU" OFF)
+option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)
+mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)
+
+# X265_BUILD must be incremented each time the public API is changed
+set(X265_BUILD 95)
+configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
+               "${PROJECT_BINARY_DIR}/x265.def")
+configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
+               "${PROJECT_BINARY_DIR}/x265_config.h")
+
+SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}")
+
+# System architecture detection
+string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" SYSPROC)
+set(X86_ALIASES x86 i386 i686 x86_64 amd64)
+set(ARM_ALIASES armv6l armv7l armv8l)
+list(FIND X86_ALIASES "${SYSPROC}" X86MATCH)
+list(FIND ARM_ALIASES "${SYSPROC}" ARMMATCH)
+set(MIPS_ALIASES mips mipsel)
+list(FIND MIPS_ALIASES "${SYSPROC}" MIPSMATCH)
+set(POWER_ALIASES ppc64 ppc64le)
+list(FIND POWER_ALIASES "${SYSPROC}" POWERMATCH)
+if("${SYSPROC}" STREQUAL "" OR X86MATCH GREATER "-1")
+    set(X86 1)
+    add_definitions(-DX265_ARCH_X86=1)
+    if("${CMAKE_SIZEOF_VOID_P}" MATCHES 8)
+        set(X64 1)
+        add_definitions(-DX86_64=1)
+        message(STATUS "Detected x86_64 target processor")
+    else()
+        message(STATUS "Detected x86 target processor")
+    endif()
+elseif(MIPSMATCH GREATER "-1")
+    message(STATUS "Detected MIPS target processor")
+    set(MIPS 1)
+    add_definitions(-DX265_ARCH_MIPS=1)
+elseif(POWERMATCH GREATER "-1")
+    message(STATUS "Detected POWER target processor")
+    set(POWER 1)
+    add_definitions(-DX265_ARCH_POWER=1)
+elseif(ARMMATCH GREATER "-1")
+    if(CROSS_COMPILE_ARM)
+        message(STATUS "Cross compiling for ARM arch")
+    else()
+        set(CROSS_COMPILE_ARM 0)
+    endif()
+    message(STATUS "Detected ARM target processor")
+    set(ARM 1)
+    add_definitions(-DX265_ARCH_ARM=1 -DHAVE_ARMV6=1)
+else()
+    message(STATUS "CMAKE_SYSTEM_PROCESSOR value `${CMAKE_SYSTEM_PROCESSOR}` is unknown")
+    message(STATUS "Please add this value near ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE}")
+endif()
+
+if(UNIX)
+    list(APPEND PLATFORM_LIBS pthread)
+    find_library(LIBRT rt)
+    if(LIBRT)
+        list(APPEND PLATFORM_LIBS rt)
+    endif()
+    mark_as_advanced(LIBRT)
+    find_library(LIBDL dl)
+    if(LIBDL)
+        list(APPEND PLATFORM_LIBS dl)
+    endif()
+    option(ENABLE_LIBNUMA "Enable libnuma usage (Linux only)" ON)
+    if(ENABLE_LIBNUMA)
+        find_package(Numa)
+        if(NUMA_FOUND)
+            link_directories(${NUMA_LIBRARY_DIR})
+            list(APPEND CMAKE_REQUIRED_LIBRARIES numa)
+            check_symbol_exists(numa_node_of_cpu numa.h NUMA_V2)
+            if(NUMA_V2)
+                add_definitions(-DHAVE_LIBNUMA)
+                message(STATUS "libnuma found, building with support for NUMA nodes")
+                list(APPEND PLATFORM_LIBS numa)
+                include_directories(${NUMA_INCLUDE_DIR})
+            endif()
+        endif()
+        mark_as_advanced(NUMA_FOUND)
+    endif(ENABLE_LIBNUMA)
+    option(NO_ATOMICS "Use a slow mutex to replace atomics" OFF)
+    if(NO_ATOMICS)
+        add_definitions(-DNO_ATOMICS=1)
+    endif(NO_ATOMICS)
+endif(UNIX)
+
+if(X64 AND NOT WIN32)
+    option(ENABLE_PIC "Enable Position Independent Code" ON)
+else()
+    option(ENABLE_PIC "Enable Position Independent Code" OFF)
+endif(X64 AND NOT WIN32)
+
+# Compiler detection
+if(CMAKE_GENERATOR STREQUAL "Xcode")
+  set(XCODE 1)
+endif()
+if(APPLE)
+  add_definitions(-DMACOS)
+endif()
+
+if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
+    set(CLANG 1)
+endif()
+if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel")
+    set(INTEL_CXX 1)
+endif()
+if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
+    set(GCC 1)
+endif()
+
+if(INTEL_CXX AND WIN32)
+    # treat icl roughly like MSVC
+    set(MSVC 1)
+endif()
+if(MSVC)
+    if(STATIC_LINK_CRT)
+        set(CompilerFlags CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE)
+        foreach(CompilerFlag ${CompilerFlags})
+            string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
+        endforeach()
+    endif(STATIC_LINK_CRT)
+    add_definitions(/W4)  # Full warnings
+    add_definitions(/Ob2) # always inline
+    add_definitions(/MP)  # multithreaded build
+
+    # disable Microsofts suggestions for proprietary secure APIs
+    add_definitions(/D_CRT_SECURE_NO_WARNINGS)
+
+    check_include_files(stdint.h HAVE_STDINT_H)
+    if(NOT HAVE_STDINT_H)
+        include_directories(compat/msvc)
+    endif()
+endif(MSVC)
+
+check_include_files(inttypes.h HAVE_INT_TYPES_H)
+if(HAVE_INT_TYPES_H)
+    add_definitions(-DHAVE_INT_TYPES_H=1)
+endif()
+
+if(INTEL_CXX AND UNIX)
+    set(GCC 1) # treat icpc roughly like gcc
+elseif(CLANG)
+    set(GCC 1) # treat clang roughly like gcc
+elseif(CMAKE_COMPILER_IS_GNUCXX)
+    set(GCC 1)
+endif()
+if(GCC)
+    add_definitions(-Wall -Wextra -Wshadow)
+    add_definitions(-D__STDC_LIMIT_MACROS=1)
+    add_definitions(-std=gnu++98)
+    if(ENABLE_PIC)
+         add_definitions(-fPIC)
+    endif(ENABLE_PIC)
+    if(NATIVE_BUILD)
+        if(INTEL_CXX)
+            add_definitions(-xhost)
+        else()
+            add_definitions(-march=native)
+        endif()
+    elseif(X86 AND NOT X64)
+        string(FIND "${CMAKE_CXX_FLAGS}" "-march" marchPos)
+        if(marchPos LESS "0")
+            add_definitions(-march=i686)
+            if(WIN32 AND NOT INTEL_CXX AND NOT CLANG AND
+               CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.0 AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0)
+                add_definitions(-mpreferred-stack-boundary=2)
+            endif()
+        endif()
+    endif()
+#
+# CFLAGS already done and here we have not to make any desisions:
+# ==============================================================
+#
+#    if(ARM AND CROSS_COMPILE_ARM)
+#        set(ARM_ARGS -march=armv6 -mfloat-abi=soft -mfpu=vfp -marm -fPIC)
+#    elseif(ARM)
+#        find_package(Neon)
+#        if(CPU_HAS_NEON)
+#            set(ARM_ARGS -mcpu=native -mfloat-abi=hard -mfpu=neon -marm -fPIC)
+#            add_definitions(-DHAVE_NEON)
+#        else()
+#            set(ARM_ARGS -mcpu=native -mfloat-abi=hard -mfpu=vfp -marm)
+#        endif()
+#    endif()
+    add_definitions(${ARM_ARGS})
+    if(FPROFILE_GENERATE)
+        if(INTEL_CXX)
+            add_definitions(-prof-gen -prof-dir="${CMAKE_CURRENT_BINARY_DIR}")
+            list(APPEND LINKER_OPTIONS "-prof-gen")
+        else()
+            check_cxx_compiler_flag(-fprofile-generate CC_HAS_PROFILE_GENERATE)
+            if(CC_HAS_PROFILE_GENERATE)
+                add_definitions(-fprofile-generate)
+                list(APPEND LINKER_OPTIONS "-fprofile-generate")
+            endif(CC_HAS_PROFILE_GENERATE)
+        endif(INTEL_CXX)
+    endif(FPROFILE_GENERATE)
+    if(FPROFILE_USE)
+        if(INTEL_CXX)
+            add_definitions(-prof-use -prof-dir="${CMAKE_CURRENT_BINARY_DIR}")
+            list(APPEND LINKER_OPTIONS "-prof-use")
+        else()
+            check_cxx_compiler_flag(-fprofile-use CC_HAS_PROFILE_USE)
+            check_cxx_compiler_flag(-fprofile-correction CC_HAS_PROFILE_CORRECTION)
+            check_cxx_compiler_flag(-Wno-error=coverage-mismatch CC_HAS_COVMISMATCH)
+            if(CC_HAS_PROFILE_USE)
+                add_definitions(-fprofile-use)
+                list(APPEND LINKER_OPTIONS "-fprofile-use")
+            endif(CC_HAS_PROFILE_USE)
+            if(CC_HAS_PROFILE_CORRECTION)
+                # auto-correct corrupted counters (happens a lot with x265)
+                add_definitions(-fprofile-correction)
+            endif(CC_HAS_PROFILE_CORRECTION)
+            if(CC_HAS_COVMISMATCH)
+                # ignore coverage mismatches (also happens a lot)
+                add_definitions(-Wno-error=coverage-mismatch)
+            endif(CC_HAS_COVMISMATCH)
+        endif(INTEL_CXX)
+    endif(FPROFILE_USE)
+    if(STATIC_LINK_CRT)
+        add_definitions(-static)
+        list(APPEND LINKER_OPTIONS "-static")
+    endif(STATIC_LINK_CRT)
+    check_cxx_compiler_flag(-Wno-strict-overflow CC_HAS_NO_STRICT_OVERFLOW)
+    check_cxx_compiler_flag(-Wno-narrowing CC_HAS_NO_NARROWING) 
+    check_cxx_compiler_flag(-Wno-array-bounds CC_HAS_NO_ARRAY_BOUNDS) 
+    if (CC_HAS_NO_ARRAY_BOUNDS)
+        add_definitions(-Wno-array-bounds) # these are unhelpful
+    endif()
+    check_cxx_compiler_flag(-ffast-math CC_HAS_FAST_MATH) 
+    if (CC_HAS_FAST_MATH)
+        add_definitions(-ffast-math)
+    endif()
+    check_cxx_compiler_flag(-mstackrealign CC_HAS_STACK_REALIGN) 
+    if (CC_HAS_STACK_REALIGN)
+        add_definitions(-mstackrealign)
+    endif()
+    # Disable exceptions. Reduce executable size, increase compability.
+    check_cxx_compiler_flag(-fno-exceptions CC_HAS_FNO_EXCEPTIONS_FLAG)
+    if(CC_HAS_FNO_EXCEPTIONS_FLAG)
+        add_definitions(-fno-exceptions)
+    endif()
+    set(FSANITIZE "" CACHE STRING "-fsanitize options for GCC/clang")
+    if(FSANITIZE)
+        add_definitions(-fsanitize=${FSANITIZE})
+        # clang and gcc need the sanitize options to be passed at link
+        # time so the appropriate ASAN/TSAN runtime libraries can be
+        # linked.
+        list(APPEND LINKER_OPTIONS "-fsanitize=${FSANITIZE}")
+    endif()
+    option(ENABLE_AGGRESSIVE_CHECKS "Enable stack protection and -ftrapv" OFF)
+    if(ENABLE_AGGRESSIVE_CHECKS)
+        # use with care, -ftrapv can cause testbench SIGILL exceptions
+        # since it is testing corner cases of signed integer math
+        add_definitions(-DUSING_FTRAPV=1)
+        check_cxx_compiler_flag(-fsanitize=undefined-trap CC_HAS_CATCH_UNDEFINED) # clang
+        check_cxx_compiler_flag(-ftrapv CC_HAS_FTRAPV)                            # gcc
+        check_cxx_compiler_flag(-fstack-protector-all CC_HAS_STACK_PROTECT)       # gcc
+        if(CC_HAS_FTRAPV)
+            add_definitions(-ftrapv)
+        endif()
+        if(CC_HAS_CATCH_UNDEFINED)
+            add_definitions(-fsanitize=undefined-trap -fsanitize-undefined-trap-on-error)
+        endif()
+        if(CC_HAS_STACK_PROTECT)
+            add_definitions(-fstack-protector-all)
+            if(MINGW)
+                list(APPEND PLATFORM_LIBS ssp)
+            endif()
+        endif()
+    endif(ENABLE_AGGRESSIVE_CHECKS)
+    execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE CC_VERSION)
+endif(GCC)
+
+find_package(Yasm)
+if((ARM OR CROSS_COMPILE_ARM) AND (CMAKE_SYSTEM_PROCESSOR STRLESS "armv8l"))
+    option(ENABLE_ASSEMBLY "Enable use of assembly coded primitives" ON)
+elseif((YASM_FOUND AND X86) AND (NOT DISABLE_X86_YASM))
+    if (YASM_VERSION_STRING VERSION_LESS "1.2.0")
+        message(STATUS "Yasm version ${YASM_VERSION_STRING} is too old. 1.2.0 or later required")
+        option(ENABLE_ASSEMBLY "Enable use of assembly coded primitives" OFF)
+    else()
+        message(STATUS "Found Yasm ${YASM_VERSION_STRING} to build assembly primitives")
+        option(ENABLE_ASSEMBLY "Enable use of assembly coded primitives" ON)
+    endif()
+else()
+    option(ENABLE_ASSEMBLY "Enable use of assembly coded primitives" OFF)
+endif()
+
+option(CHECKED_BUILD "Enable run-time sanity checks (debugging)" OFF)
+if(CHECKED_BUILD)
+    add_definitions(-DCHECKED_BUILD=1)
+endif()
+
+# Build options
+set(LIB_INSTALL_DIR lib CACHE STRING "Install location of libraries")
+set(BIN_INSTALL_DIR bin CACHE STRING "Install location of executables")
+set(EXTRA_LIB "" CACHE STRING "Extra libraries to link against")
+set(EXTRA_LINK_FLAGS "" CACHE STRING "Extra link flags")
+if(EXTRA_LINK_FLAGS)
+    list(APPEND LINKER_OPTIONS ${EXTRA_LINK_FLAGS})
+endif()
+if(EXTRA_LIB)
+    option(LINKED_8BIT  "8bit libx265 is being linked with this library" OFF)
+    option(LINKED_10BIT "10bit libx265 is being linked with this library" OFF)
+    option(LINKED_12BIT "12bit libx265 is being linked with this library" OFF)
+endif(EXTRA_LIB)
+mark_as_advanced(EXTRA_LIB EXTRA_LINK_FLAGS)
+
+if(X64)
+    # NOTE: We only officially support high-bit-depth compiles of x265
+    # on 64bit architectures. Main10 plus large resolution plus slow
+    # preset plus 32bit address space usually means malloc failure.  You
+    # can disable this if(X64) check if you desparately need a 32bit
+    # build with 10bit/12bit support, but this violates the "shrink wrap
+    # license" so to speak.  If it breaks you get to keep both halves.
+    # You will need to disable assembly manually.
+    option(HIGH_BIT_DEPTH "Store pixel samples as 16bit values (Main10/Main12)" OFF)
+endif(X64)
+if(HIGH_BIT_DEPTH)
+    option(MAIN12 "Support Main12 instead of Main10" OFF)
+    if(MAIN12)
+        add_definitions(-DHIGH_BIT_DEPTH=1 -DX265_DEPTH=12)
+    else()
+        add_definitions(-DHIGH_BIT_DEPTH=1 -DX265_DEPTH=10)
+    endif()
+else(HIGH_BIT_DEPTH)
+    add_definitions(-DHIGH_BIT_DEPTH=0 -DX265_DEPTH=8)
+endif(HIGH_BIT_DEPTH)
+
+# this option can only be used when linking multiple libx265 libraries
+# together, and some alternate API access method is implemented.
+option(EXPORT_C_API "Implement public C programming interface" ON)
+mark_as_advanced(EXPORT_C_API)
+if(EXPORT_C_API)
+    set(X265_NS x265)
+    add_definitions(-DEXPORT_C_API=1)
+elseif(HIGH_BIT_DEPTH)
+    if(MAIN12)
+        set(X265_NS x265_12bit)
+    else()
+        set(X265_NS x265_10bit)
+    endif()
+    add_definitions(-DEXPORT_C_API=0)
+else()
+    set(X265_NS x265_8bit)
+    add_definitions(-DEXPORT_C_API=0)
+endif()
+add_definitions(-DX265_NS=${X265_NS})
+
+option(WARNINGS_AS_ERRORS "Stop compiles on first warning" OFF)
+if(WARNINGS_AS_ERRORS)
+    if(GCC)
+        add_definitions(-Werror)
+    elseif(MSVC)
+        add_definitions(/WX)
+    endif()
+endif(WARNINGS_AS_ERRORS)
+
+if(WIN32)
+    # Visual leak detector
+    find_package(VLD QUIET)
+    if(VLD_FOUND)
+        add_definitions(-DHAVE_VLD)
+        include_directories(${VLD_INCLUDE_DIRS})
+        list(APPEND PLATFORM_LIBS ${VLD_LIBRARIES})
+        link_directories(${VLD_LIBRARY_DIRS})
+    endif()
+    option(WINXP_SUPPORT "Make binaries compatible with Windows XP and Vista" OFF)
+    if(WINXP_SUPPORT)
+        # force use of workarounds for CONDITION_VARIABLE and atomic
+        # intrinsics introduced after XP
+        add_definitions(-D_WIN32_WINNT=_WIN32_WINNT_WINXP -D_WIN32_WINNT_WIN7=0x0601)
+    else(WINXP_SUPPORT)
+        # default to targeting Windows 7 for the NUMA APIs
+        add_definitions(-D_WIN32_WINNT=_WIN32_WINNT_WIN7)
+    endif(WINXP_SUPPORT)
+endif()
+
+include(version) # determine X265_VERSION and X265_LATEST_TAG
+include_directories(. common encoder "${PROJECT_BINARY_DIR}")
+
+option(ENABLE_PPA "Enable PPA profiling instrumentation" OFF)
+if(ENABLE_PPA)
+    add_definitions(-DENABLE_PPA)
+    list(APPEND PLATFORM_LIBS PPA)
+    if(UNIX)
+        list(APPEND PLATFORM_LIBS dl)
+    endif(UNIX)
+    add_subdirectory(profile/PPA)
+endif(ENABLE_PPA)
+
+option(ENABLE_VTUNE "Enable Vtune profiling instrumentation" OFF)
+if(ENABLE_VTUNE)
+    find_package(Vtune)
+    if(VTUNE_FOUND)
+        add_definitions(-DENABLE_VTUNE)
+        include_directories(${VTUNE_INCLUDE_DIR})
+        list(APPEND PLATFORM_LIBS vtune)
+        link_directories(${VTUNE_LIBRARY_DIR})
+        if(WIN32)
+            list(APPEND PLATFORM_LIBS libittnotify.lib)
+        else()
+            list(APPEND PLATFORM_LIBS libittnotify.a dl)
+        endif()
+        add_subdirectory(profile/vtune)
+    endif(VTUNE_FOUND)
+endif(ENABLE_VTUNE)
+
+option(DETAILED_CU_STATS "Enable internal profiling of encoder work" OFF)
+if(DETAILED_CU_STATS)
+    add_definitions(-DDETAILED_CU_STATS)
+endif(DETAILED_CU_STATS)
+
+add_subdirectory(encoder)
+add_subdirectory(common)
+
+if((MSVC_IDE OR XCODE OR GCC) AND ENABLE_ASSEMBLY)
+    # this is required because of this cmake bug
+    # http://www.cmake.org/Bug/print_bug_page.php?bug_id=8170
+    if(WIN32)
+        set(SUFFIX obj)
+    else()
+        set(SUFFIX o)
+    endif()
+
+    if(ARM OR CROSS_COMPILE_ARM)
+    # compile ARM arch asm files here
+        enable_language(ASM)
+        foreach(ASM ${ARM_ASMS})
+            set(ASM_SRC ${CMAKE_CURRENT_SOURCE_DIR}/common/arm/${ASM})
+            list(APPEND ASM_SRCS ${ASM_SRC})
+            list(APPEND ASM_OBJS ${ASM}.${SUFFIX})
+            add_custom_command(
+                OUTPUT ${ASM}.${SUFFIX}
+                COMMAND ${CMAKE_CXX_COMPILER}
+                ARGS ${ARM_ARGS} -c ${ASM_SRC} -o ${ASM}.${SUFFIX}
+                DEPENDS ${ASM_SRC})
+        endforeach()
+    elseif(X86)
+    # compile X86 arch asm files here
+        foreach(ASM ${MSVC_ASMS})
+            set(ASM_SRC ${CMAKE_CURRENT_SOURCE_DIR}/common/x86/${ASM})
+            list(APPEND ASM_SRCS ${ASM_SRC})
+            list(APPEND ASM_OBJS ${ASM}.${SUFFIX})
+            add_custom_command(
+                OUTPUT ${ASM}.${SUFFIX}
+                COMMAND ${YASM_EXECUTABLE} ARGS ${YASM_FLAGS} ${ASM_SRC} -o ${ASM}.${SUFFIX}
+                DEPENDS ${ASM_SRC})
+        endforeach()
+    endif()
+endif()
+
+source_group(ASM FILES ${ASM_SRCS})
+add_library(x265-static STATIC $<TARGET_OBJECTS:encoder> $<TARGET_OBJECTS:common> ${ASM_OBJS} ${ASM_SRCS})
+if(NOT MSVC)
+    set_target_properties(x265-static PROPERTIES OUTPUT_NAME x265)
+endif()
+if(EXTRA_LIB)
+    target_link_libraries(x265-static ${EXTRA_LIB})
+endif()
+install(TARGETS x265-static
+    LIBRARY DESTINATION ${LIB_INSTALL_DIR}
+    ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
+install(FILES x265.h "${PROJECT_BINARY_DIR}/x265_config.h" DESTINATION include)
+
+if(CMAKE_RC_COMPILER)
+    # The resource compiler does not need CFLAGS or macro defines. It
+    # often breaks them
+    string(REPLACE "<FLAGS>" "" CMAKE_RC_COMPILE_OBJECT "${CMAKE_RC_COMPILE_OBJECT}")
+    string(REPLACE "<DEFINES>" "" CMAKE_RC_COMPILE_OBJECT "${CMAKE_RC_COMPILE_OBJECT}")
+
+    # convert X265_LATEST_TAG (ex: 0.7) and X265_TAG_DISTANCE (ex: 103) to
+    # @X265_VERSION_MAJOR@,@X265_VERSION_MINOR@,@X265_BRANCH_ID@,@X265_TAG_DISTANCE@
+    string(REPLACE "." ";" VERSION_LIST "${X265_LATEST_TAG}")
+    list(GET VERSION_LIST 0 X265_VERSION_MAJOR)
+    list(GET VERSION_LIST 1 X265_VERSION_MINOR)
+    set(X265_BRANCH_ID 0) # TODO: 0 - stable, 1 - default or other
+    set(X265_RC_FILE "${CMAKE_CURRENT_BINARY_DIR}/x265.rc")
+    configure_file("${CMAKE_CURRENT_SOURCE_DIR}/x265.rc.in" "${X265_RC_FILE}" @ONLY)
+endif()
+
+if(NOT (MSVC_IDE OR XCODE))
+    add_custom_target(clean-generated COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/clean-generated.cmake)
+endif()
+
+option(ENABLE_SHARED "Build shared library" ON)
+if(ENABLE_SHARED)
+    add_library(x265-shared SHARED "${PROJECT_BINARY_DIR}/x265.def" ${ASM_OBJS}
+                ${X265_RC_FILE} $<TARGET_OBJECTS:encoder> $<TARGET_OBJECTS:common>)
+    if(EXTRA_LIB)
+        target_link_libraries(x265-shared ${EXTRA_LIB})
+    endif()
+    target_link_libraries(x265-shared ${PLATFORM_LIBS})
+    if(MSVC)
+        set_target_properties(x265-shared PROPERTIES OUTPUT_NAME libx265)
+    else()
+        set_target_properties(x265-shared PROPERTIES OUTPUT_NAME x265)
+    endif()
+    if(UNIX)
+        set_target_properties(x265-shared PROPERTIES VERSION ${X265_BUILD})
+        if(APPLE)
+            set_target_properties(x265-shared PROPERTIES MACOSX_RPATH 1)
+        elseif(CYGWIN)
+            # Cygwin is not officially supported or tested. MinGW with msys is recommended.
+        else()
+            list(APPEND LINKER_OPTIONS "-Wl,-Bsymbolic,-znoexecstack")
+        endif()
+    endif()
+    set_target_properties(x265-shared PROPERTIES SOVERSION ${X265_BUILD})
+    if(X265_LATEST_TAG)
+        if(WINDOWS)
+            set_target_properties(x265-shared PROPERTIES VERSION ${X265_LATEST_TAG})
+        endif()
+        # shared library is not installed if a tag is not found
+        install(TARGETS x265-shared
+                LIBRARY DESTINATION ${LIB_INSTALL_DIR}
+                ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
+                RUNTIME DESTINATION ${BIN_INSTALL_DIR})
+    endif()
+    if(LINKER_OPTIONS)
+        # set_target_properties can't do list expansion
+        string(REPLACE ";" " " LINKER_OPTION_STR "${LINKER_OPTIONS}")
+        set_target_properties(x265-shared PROPERTIES LINK_FLAGS "${LINKER_OPTION_STR}")
+    endif()
+endif()
+
+if(X265_LATEST_TAG)
+    # convert lists of link libraries into -lstdc++ -lm etc..
+    foreach(LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES} ${PLATFORM_LIBS})
+        if(IS_ABSOLUTE ${LIB} AND EXISTS ${LIB})
+            list(APPEND PLIBLIST "${LIB}")
+        else()
+            list(APPEND PLIBLIST "-l${LIB}")
+        endif()
+    endforeach()
+    if(PLIBLIST)
+        # blacklist of libraries that should not be in Libs.private
+        list(REMOVE_ITEM PLIBLIST "-lc" "-lpthread")
+        string(REPLACE ";" " " PRIVATE_LIBS "${PLIBLIST}")
+    else()
+        set(PRIVATE_LIBS "")
+    endif(PLIBLIST)
+
+    # Produce a pkg-config file
+    configure_file("x265.pc.in" "x265.pc" @ONLY)
+    install(FILES       "${CMAKE_CURRENT_BINARY_DIR}/x265.pc"
+            DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")
+endif()
+
+if(NOT WIN32)
+    configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
+                   "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
+                   IMMEDIATE @ONLY)
+    add_custom_target(uninstall
+                      "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake")
+endif()
+
+# Main CLI application
+set(ENABLE_CLI ON CACHE BOOL "Build standalone CLI application")
+if(ENABLE_CLI)
+    file(GLOB InputFiles input/input.cpp input/yuv.cpp input/y4m.cpp input/*.h)
+    file(GLOB OutputFiles output/output.cpp output/reconplay.cpp output/*.h
+                          output/yuv.cpp output/y4m.cpp # recon
+                          output/raw.cpp)               # muxers
+    source_group(input FILES ${InputFiles})
+    source_group(output FILES ${OutputFiles})
+
+    check_include_files(getopt.h HAVE_GETOPT_H)
+    if(NOT HAVE_GETOPT_H)
+        if(MSVC)
+            set_source_files_properties(compat/getopt/getopt.c PROPERTIES COMPILE_FLAGS "/wd4100 /wd4131 -DHAVE_STRING_H=1")
+        endif(MSVC)
+        include_directories(compat/getopt)
+        set(GETOPT compat/getopt/getopt.c compat/getopt/getopt.h)
+    endif(NOT HAVE_GETOPT_H)
+    if(WIN32)
+        set(ExportDefs "${PROJECT_BINARY_DIR}/x265.def")
+    endif(WIN32)
+
+    if(XCODE)
+        # Xcode seems unable to link the CLI with libs, so link as one targget
+        add_executable(cli ../COPYING ${InputFiles} ${OutputFiles} ${GETOPT}
+                       x265.cpp x265.h x265cli.h x265-extras.h x265-extras.cpp
+                       $<TARGET_OBJECTS:encoder> $<TARGET_OBJECTS:common> ${ASM_OBJS} ${ASM_SRCS})
+    else()
+        add_executable(cli ../COPYING ${InputFiles} ${OutputFiles} ${GETOPT} ${X265_RC_FILE}
+                       ${ExportDefs} x265.cpp x265.h x265cli.h x265-extras.h x265-extras.cpp)
+        if(WIN32 OR NOT ENABLE_SHARED OR INTEL_CXX)
+            # The CLI cannot link to the shared library on Windows, it
+            # requires internal APIs not exported from the DLL
+            target_link_libraries(cli x265-static ${PLATFORM_LIBS})
+        else()
+            target_link_libraries(cli x265-shared ${PLATFORM_LIBS})
+        endif()
+    endif()
+    set_target_properties(cli PROPERTIES OUTPUT_NAME x265)
+    if(LINKER_OPTIONS)
+        # set_target_properties can't do list expansion
+        string(REPLACE ";" " " LINKER_OPTION_STR "${LINKER_OPTIONS}")
+        set_target_properties(cli PROPERTIES LINK_FLAGS "${LINKER_OPTION_STR}")
+    endif()
+
+    install(TARGETS cli DESTINATION ${BIN_INSTALL_DIR})
+endif(ENABLE_CLI)
+
+if(ENABLE_ASSEMBLY AND NOT XCODE)
+    option(ENABLE_TESTS "Enable Unit Tests" OFF)
+    if(ENABLE_TESTS)
+        add_subdirectory(test)
+    endif()
+endif()
+
+get_directory_property(hasParent PARENT_DIRECTORY)
+if(hasParent)
+    if(PLATFORM_LIBS)
+        LIST(REMOVE_DUPLICATES PLATFORM_LIBS)
+        set(PLATFORM_LIBS ${PLATFORM_LIBS} PARENT_SCOPE)
+    endif(PLATFORM_LIBS)
+endif(hasParent)
diff --git a/sources/packages/m/x265/create-2.1-version-patch/create.patch.sh b/sources/packages/m/x265/create-2.1-version-patch/create.patch.sh
new file mode 100755
index 000000000..1e33577cd
--- /dev/null
+++ b/sources/packages/m/x265/create-2.1-version-patch/create.patch.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+VERSION=2.1
+
+tar --files-from=file.list -xzvf ../x265-$VERSION.tar.gz
+mv x265-$VERSION x265-$VERSION-orig
+
+cp -rf ./x265-$VERSION-new ./x265-$VERSION
+
+diff -b --unified -Nr  x265-$VERSION-orig  x265-$VERSION > x265-$VERSION-version.patch
+
+mv x265-$VERSION-version.patch ../patches
+
+rm -rf ./x265-$VERSION
+rm -rf ./x265-$VERSION-orig
diff --git a/sources/packages/m/x265/create-2.1-version-patch/file.list b/sources/packages/m/x265/create-2.1-version-patch/file.list
new file mode 100644
index 000000000..ce2c4d37f
--- /dev/null
+++ b/sources/packages/m/x265/create-2.1-version-patch/file.list
@@ -0,0 +1 @@
+x265-2.1/source/cmake/version.cmake
diff --git a/sources/packages/m/x265/create-2.1-version-patch/x265-2.1-new/source/cmake/version.cmake b/sources/packages/m/x265/create-2.1-version-patch/x265-2.1-new/source/cmake/version.cmake
new file mode 100644
index 000000000..2fc78bea1
--- /dev/null
+++ b/sources/packages/m/x265/create-2.1-version-patch/x265-2.1-new/source/cmake/version.cmake
@@ -0,0 +1,106 @@
+if(CMAKE_VERSION VERSION_LESS "2.8.10")
+    find_program(HG_EXECUTABLE hg)
+else()
+    find_package(Hg QUIET)
+endif()
+find_package(Git QUIET) # present in 2.8.8
+
+# defaults, in case everything below fails
+set(X265_VERSION "unknown")
+set(X265_LATEST_TAG "2.1")
+set(X265_TAG_DISTANCE "0")
+
+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.hg_archival.txt)
+    # read the lines of the archive summary file to extract the version
+    file(READ ${CMAKE_CURRENT_SOURCE_DIR}/../.hg_archival.txt archive)
+    STRING(REGEX REPLACE "\n" ";" archive "${archive}")
+    foreach(f ${archive})
+        string(FIND "${f}" ": " pos)
+        string(SUBSTRING "${f}" 0 ${pos} key)
+        string(SUBSTRING "${f}" ${pos} -1 value)
+        string(SUBSTRING "${value}" 2 -1 value)
+        set(hg_${key} ${value})
+    endforeach()
+    if(DEFINED hg_tag)
+        set(X265_VERSION ${hg_tag})
+        set(X265_LATEST_TAG ${hg_tag})
+        set(X265_TAG_DISTANCE "0")
+    elseif(DEFINED hg_node)
+        string(SUBSTRING "${hg_node}" 0 16 hg_id)
+        set(X265_VERSION "${hg_latesttag}+${hg_latesttagdistance}-${hg_id}")
+    endif()
+elseif(HG_EXECUTABLE AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.hg)
+    if(EXISTS "${HG_EXECUTABLE}.bat")
+        # mercurial source installs on Windows require .bat extension
+        set(HG_EXECUTABLE "${HG_EXECUTABLE}.bat")
+    endif()
+    message(STATUS "hg found at ${HG_EXECUTABLE}")
+
+    execute_process(COMMAND
+        ${HG_EXECUTABLE} log -r. --template "{latesttag}"
+        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+        OUTPUT_VARIABLE X265_LATEST_TAG
+        ERROR_QUIET
+        OUTPUT_STRIP_TRAILING_WHITESPACE
+        )
+    execute_process(COMMAND
+        ${HG_EXECUTABLE} log -r. --template "{latesttagdistance}"
+        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+        OUTPUT_VARIABLE X265_TAG_DISTANCE
+        ERROR_QUIET
+        OUTPUT_STRIP_TRAILING_WHITESPACE
+        )
+    execute_process(
+        COMMAND
+        ${HG_EXECUTABLE} log -r. --template "{node}"
+        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+        OUTPUT_VARIABLE X265_REVISION_ID
+        ERROR_QUIET
+        OUTPUT_STRIP_TRAILING_WHITESPACE
+        )
+    string(SUBSTRING "${X265_REVISION_ID}" 0 12 X265_REVISION_ID)
+
+    if(X265_LATEST_TAG MATCHES "^r")
+        string(SUBSTRING ${X265_LATEST_TAG} 1 -1 X265_LATEST_TAG)
+    endif()
+elseif(GIT_EXECUTABLE AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git)
+    execute_process(
+        COMMAND
+        ${GIT_EXECUTABLE} rev-list --tags --max-count=1
+        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+        OUTPUT_VARIABLE X265_LATEST_TAG_COMMIT
+        ERROR_QUIET
+        OUTPUT_STRIP_TRAILING_WHITESPACE
+        )
+    execute_process(
+        COMMAND
+        ${GIT_EXECUTABLE} describe --tags ${X265_LATEST_TAG_COMMIT}
+        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+        OUTPUT_VARIABLE X265_LATEST_TAG
+        ERROR_QUIET
+        OUTPUT_STRIP_TRAILING_WHITESPACE
+        )
+    execute_process(
+        COMMAND
+        ${GIT_EXECUTABLE} rev-list ${X265_LATEST_TAG}.. --count --first-parent
+        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+        OUTPUT_VARIABLE X265_TAG_DISTANCE
+        ERROR_QUIET
+        OUTPUT_STRIP_TRAILING_WHITESPACE
+        )
+    execute_process(
+        COMMAND
+        ${GIT_EXECUTABLE} log -1 --format=g%h
+        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+        OUTPUT_VARIABLE X265_REVISION_ID
+        ERROR_QUIET
+        OUTPUT_STRIP_TRAILING_WHITESPACE
+        )
+endif()
+if(X265_TAG_DISTANCE STREQUAL "0")
+    set(X265_VERSION "${X265_LATEST_TAG}")
+else()
+    set(X265_VERSION "${X265_LATEST_TAG}+${X265_TAG_DISTANCE}-${X265_REVISION_ID}")
+endif()
+
+message(STATUS "x265 version ${X265_VERSION}")