#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright 2016 Alexander Pyhalov
# Copyright 2019 Michal Nowak
#

BUILD_STYLE= justmake
DROP_STATIC_LIBRARIES= yes
include ../../../make-rules/shared-macros.mk

COMPONENT_NAME=		lz4
COMPONENT_VERSION=	1.10.0
COMPONENT_SRC=		$(COMPONENT_NAME)-$(COMPONENT_VERSION)
COMPONENT_SUMMARY=	Extremely Fast Compression algorithm
COMPONENT_ARCHIVE=	$(COMPONENT_SRC).tar.gz
COMPONENT_ARCHIVE_HASH= sha256:537512904744b35e232912055ccf8ec66d768639ff3abe5788d90d792ec5f48b
COMPONENT_ARCHIVE_URL=	https://github.com/lz4/lz4/archive/v$(COMPONENT_VERSION).tar.gz
COMPONENT_PROJECT_URL=	https://lz4.github.io/lz4/
COMPONENT_FMRI=		library/lz4
COMPONENT_LICENSE=	BSD,GPLv2
COMPONENT_LICENSE_FILE=	lz4.license
COMPONENT_CLASSIFICATION= System/Libraries

include $(WS_MAKE_RULES)/common.mk

PATH= $(PATH.gnu)

# Tests require the full copy of source dir.
COMPONENT_PRE_CONFIGURE_ACTION= ( CLONEY_MODE=copy $(CLONEY) $(SOURCE_DIR) $(@D) )

# Verbose compilation output
COMPONENT_BUILD_ARGS += Q=

COMPONENT_BUILD_ARGS += CFLAGS='$(CFLAGS)'

COMPONENT_INSTALL_ENV += PREFIX=$(USRDIR)
COMPONENT_INSTALL_ENV += LIBDIR=$(USRLIBDIR64)

# The test results differ for x86 and SPARC
COMPONENT_TEST_MASTER = $(COMPONENT_TEST_RESULTS_DIR)/results-$(MACH$(BITS)).master

# To allow reproducible tests (note "frametest", "fuzzer" in tools/time.c).
COMPONENT_TEST_ENV += FUZZER_TIME=1272503297

COMPONENT_TEST_TARGETS = test
COMPONENT_TEST_ENV += CC="$(CC)"
COMPONENT_TEST_COMPARE_CMD =    $(GDIFF) -uN --ignore-blank-lines
COMPONENT_TEST_TRANSFORMS += -e '"s/tests in [0-9\.]\+s/tests in TIME/" '
COMPONENT_TEST_TRANSFORMS += -e '"s/20[2-9][0-9]\/[0-1][0-9]\/[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]/DATETIME/" '
COMPONENT_TEST_TRANSFORMS += -e '"s/[ ]\+[0-9]\+\(\.[0-9]\{1,2\}\)\? Mi\?B\/s/ COMPRESS_SPEED/g" '
COMPONENT_TEST_TRANSFORMS += -e '"s/ [0-9]\+\(\.[0-9]\+\(e-[0-9]\+\)\?\)\? s[ ,]/ X s /g" '
COMPONENT_TEST_TRANSFORMS += -e '"s/cpu load : [0-9]\+%/cpu load X%/"  '
# Removes GCC specific path.
COMPONENT_TEST_TRANSFORMS += -e '"s/\/usr\/gcc\/.*\/bin\/gcc/gcc/" '
# Avoids lines with carriage return(s) as produced during default verbose output.
COMPONENT_TEST_TRANSFORMS += -e '"/^\r/d" '
# Removes output generated by: set -x (which can be messed with error output when pipes are used).
COMPONENT_TEST_TRANSFORMS += -e '"/^+/d" '
# lz4 version info in verbose mode can mess around too.
COMPONENT_TEST_TRANSFORMS += -e '"/^\*\*\* lz4 /d" '

# Auto-generated dependencies
REQUIRED_PACKAGES += system/library