SUMMARY = "7-zip is a commandline utility handling 7z archives."
HOMEPAGE = "http://www.7-zip.org/"
LICENSE = "LGPL-2.1-or-later & unRAR & PD & BSD-2-Clause & BSD-3-Clause"
LIC_FILES_CHKSUM = "file://DOC/copying.txt;md5=4fbd65380cdd255951079008b364516c \
                    file://DOC/unRarLicense.txt;md5=9c87ddde469ef94aed153b0951d088de \
                    file://DOC/License.txt;md5=a4ae6e492874f0008c7600c2ef80daa4 \
                    "

CVE_PRODUCT = "7-zip 7zip"
SRC_URI = "git://github.com/ip7z/7zip.git;protocol=https;branch=main;tag=${PV} \
           file://0001-support-yocto-cross-compiling.patch \
           file://0001-Remove-treating-warning-as-errors.patch \
           file://7z_wrapper.sh \
           "
SRCREV = "839151eaaad24771892afaae6bac690e31e58384"

UPSTREAM_CHECK_URI = "https://github.com/ip7z/7zip/releases/latest"

EXTRA_OEMAKE += " \
    CXXFLAGS_EXTRA='${CXXFLAGS}' \
    CFLAGS_BASE2='${CFLAGS}' \
    LDFLAGS_STATIC_3='${LDFLAGS}' \
"

# Support clang
MAKEFILE ?= "../../cmpl_gcc.mak"
MAKEFILE:class-target:toolchain-clang = "../../cmpl_clang.mak"

do_compile() {
    oe_runmake -C CPP/7zip/Bundles/Alone2    -f ${MAKEFILE}
    oe_runmake -C CPP/7zip/Bundles/Format7zF -f ${MAKEFILE}
    oe_runmake -C CPP/7zip/UI/Console        -f ${MAKEFILE}
    oe_runmake -C CPP/7zip/Bundles/SFXCon    -f ${MAKEFILE}
    oe_runmake -C CPP/7zip/Bundles/Alone     -f ${MAKEFILE}
    oe_runmake -C CPP/7zip/Bundles/Alone7z   -f ${MAKEFILE}
}

FILES:${PN} += "${libdir}/*"

FILES_SOLIBSDEV = ""
INSANE_SKIP:${PN} += "dev-so"

INSTALLDIR ?= "g"
INSTALLDIR:class-target:toolchain-clang = "c"

do_install() {
	install -d ${D}${bindir}
	install -m 0755 ${S}/CPP/7zip/Bundles/Alone/b/${INSTALLDIR}/7za ${D}${bindir}
	install -m 0755 ${S}/CPP/7zip/Bundles/Alone7z/b/${INSTALLDIR}/7zr ${D}${bindir}
	install -m 0755 ${S}/CPP/7zip/UI/Console/b/${INSTALLDIR}/7z ${D}${bindir}/7z.real
	install -m 0755 ${UNPACKDIR}/7z_wrapper.sh ${D}${bindir}/7z

	install -d ${D}${libdir}
	install -m 0755 ${S}/CPP/7zip/Bundles/Format7zF/b/${INSTALLDIR}/7z.so ${D}${libdir}/lib7z.so
	ln -rsn ${D}${libdir}/lib7z.so ${D}${bindir}/7z.so

	# install headers (for development) and readme (for version information)
	for header_file in $(find ${S}/CPP/${BPN} ${S}/CPP/Common ${S}/C -name "*.h"); do
		header_dir=$(dirname $(echo $header_file | sed "s|${S}/||"))
		install -d ${D}${includedir}/${BPN}/$header_dir
		install -m 0644 $header_file ${D}${includedir}/${BPN}/$header_dir
	done
	install -d ${D}${includedir}/${BPN}/DOC
	install -m 0644 ${S}/DOC/readme.txt ${D}${includedir}/${BPN}/DOC
}

PROVIDES += "p7zip"
RPROVIDES:${PN} += "lib7z.so()(64bit) 7z lib7z.so p7zip"
RPROVIDES:${PN}-dev += "lib7z.so()(64bit) 7z lib7z.so"

BBCLASSEXTEND = "native nativesdk"
