__deps__ := X265_8 X265_10 X265_12
$(eval $(call import.MODULE.defs,X265,x265,$(__deps__)))
$(eval $(call import.CONTRIB.defs,X265))

X265.FETCH.url     = https://download.handbrake.fr/contrib/x265_3.2.1.tar.gz
X265.FETCH.url    += https://bitbucket.org/multicoreware/x265/downloads/x265_3.2.1.tar.gz
X265.FETCH.url    += https://download.videolan.org/pub/videolan/x265/x265_3.2.1.tar.gz
X265.FETCH.sha256  = fb9badcf92364fd3567f8b5aa0e5e952aeea7a39a2b864387cec31e3b58cbbcc
X265.EXTRACT.tarbase = x265_3.2.1

# Silence "warning: overriding recipe for target" messages
X265.FETCH.target =

X265.INSTALL.args.dir = -j 1 -C $(X265.BUILD.dir)/8bit install;
X265.INSTALL.extra = $(CP.exe) $(X265.BUILD.dir)/libx265.a $(CONTRIB.build/)lib
X265.INSTALL.args = !make @dir !extra

X265.UNINSTALL.dir = $(X265.BUILD.dir)/8bit

X265.CLEAN.make = $(RM.exe) -rf
X265.CLEAN.args.dir = cd $(1);
X265.CLEAN.extra = libx265.a
X265.CLEAN.args = @dir !make !extra

## find CMakeLists.txt
X265.CONFIGURE.extra += "$(call fn.ABSOLUTE,$(X265.EXTRACT.dir/)source/)"

## optional static libs need to be marked
X265.OSL.libs  = x265
X265.OSL.files = $(foreach i,$(X265.OSL.libs),$(call fn.ABSOLUTE,$(CONTRIB.build/)lib/lib$(i).a))

# Override operations that are not needed
X265.FETCH =
X265.VERIFY = $(TOUCH.exe) $@
X265.EXTRACT = $(TOUCH.exe) $@
X265.PATCH = $(TOUCH.exe) $@
X265.CONFIGURE = $(TOUCH.exe) $@
X265.BUILD = $(TOUCH.exe) $@

X265.SOURCE.libs = \
	$(X265.BUILD.dir)/8bit/libx265_main.a \
	$(X265.BUILD.dir)/10bit/libx265_main10.a \
	$(X265.BUILD.dir)/12bit/libx265_main12.a

ifeq (1-mingw,$(HOST.cross)-$(HOST.system))
    X265.O.ext = .obj
else
    X265.O.ext = .o
endif

define X265.LINK
    for a in $(X265.SOURCE.libs); do \
        ($(RM.exe) -rf "$$a"_o && $(MKDIR.exe) -p "$$a"_o && $(AR.exe) x "$$a" && $(MV.exe) *$(X265.O.ext) "$$a"_o && $(AR.exe) cq $@ "$$a"_o/*$(X265.O.ext)); \
    done
    $(RANLIB.exe) $@
endef
