PKG_NAME = libicu
PKG_VERS = 77.1
PKG_EXT = tgz
PKG_DIST_NAME = icu4c-$(subst .,_,$(PKG_VERS))-src.$(PKG_EXT)
PKG_DIST_SITE = https://github.com/unicode-org/icu/releases/download/release-$(subst .,-,$(PKG_VERS))
PKG_DIR = icu/source

# Remarks:
# libicu 74 is the latest version that builds for DSM 6
# libicu >= 75 requires compiler with c++17

BUILD_DEPENDS = native/libicu

HOMEPAGE = http://site.icu-project.org/home
COMMENT  = International Components for Unicode.
LICENSE  = https://www.unicode.org/copyright.html#License

include ../../mk/spksrc.common.mk

# Compiler too old, stdc++11 is required.
UNSUPPORTED_ARCHS = $(ARMv5_ARCHS) $(OLD_PPC_ARCHS)

GNU_CONFIGURE = 1

ifeq ($(findstring $(ARCH),$(ARMv7_ARCHS) $(ARMv7L_ARCHS)),$(ARCH))
CONFIGURE_ARGS = --host=arm-unknown-linux-gnueabi
endif
ifeq ($(findstring $(ARCH),$(ARMv8_ARCHS)),$(ARCH))
CONFIGURE_ARGS = --host=aarch64-unknown-linux-gnu
endif
ifeq ($(findstring $(ARCH),$(PPC_ARCHS)),$(ARCH))
CONFIGURE_ARGS = --host=powerpc-unknown-linux-gnu
endif
ifeq ($(findstring $(ARCH),$(i686_ARCHS)),$(ARCH))
CONFIGURE_ARGS = --host=i686-pc-linux-gnu
endif
ifeq ($(findstring $(ARCH),$(x64_ARCHS)),$(ARCH))
CONFIGURE_ARGS = --host=x86_64-pc-linux-gnu
endif

NATIVE_BUILD_DIR = $(realpath $(WORK_DIR)/../../../native/$(PKG_NAME)/work-native/$(PKG_DIR))

# the packaging can be customized in a dependent package by definition
# of LIBICU_DATA_PACKAGING_MODE like:
# export LIBICU_DATA_PACKAGING_MODE=archive
# 
# valid data packaging values are
# - library (the default)
# - archive

DATA_PACKAGING = $(LIBICU_DATA_PACKAGING_MODE)
ifeq ($(strip $(DATA_PACKAGING)),)
# default data packaging
DATA_PACKAGING = library
endif
CONFIGURE_ARGS += --with-data-packaging=$(DATA_PACKAGING)

ifeq ($(strip $(DATA_PACKAGING)),archive)
# add the ICU data file.
PLIST_TRANSFORM = sed -e '$$a rsc:share/icu/*/icudt*.dat'
endif

PRE_COMPILE_TARGET = libicu_prepare_dir
POST_INSTALL_TARGET = libicu_post_install

CONFIGURE_ARGS += --with-cross-build=$(NATIVE_BUILD_DIR) 
CONFIGURE_ARGS += --prefix=$(INSTALL_PREFIX)
CONFIGURE_ARGS += --disable-samples
CONFIGURE_ARGS += --disable-tools
CONFIGURE_ARGS += --disable-tests

ADDITIONAL_CFLAGS = -O3

include ../../mk/spksrc.cross-cc.mk

.PHONY: libicu_prepare_dir
libicu_prepare_dir:
	@mkdir -p $(WORK_DIR)/$(PKG_DIR)/data/out/tmp

.PHONY: libicu_post_install
libicu_post_install:
	$(RUN) sed -i 's|$(INSTALL_PREFIX)|$(STAGING_INSTALL_PREFIX)|g' $(STAGING_INSTALL_PREFIX)/lib/pkgconfig/icu-*.pc
