__deps__ := FREETYPE

$(eval $(call import.MODULE.defs,HARFBUZZ,harfbuzz,$(__deps__)))
$(eval $(call import.CONTRIB.defs,HARFBUZZ))

HARFBUZZ.FETCH.url     = https://download.handbrake.fr/handbrake/contrib/harfbuzz-2.6.4.tar.xz
HARFBUZZ.FETCH.url    += https://www.freedesktop.org/software/harfbuzz/release/harfbuzz-2.6.4.tar.xz
HARFBUZZ.FETCH.sha256  = 9413b8d96132d699687ef914ebb8c50440efc87b3f775d25856d7ec347c03c12

HARFBUZZ.build_dir             = build
HARFBUZZ.CONFIGURE.exe         = cmake
HARFBUZZ.CONFIGURE.args.prefix = -DCMAKE_INSTALL_PREFIX="$(HARFBUZZ.CONFIGURE.prefix)"
HARFBUZZ.CONFIGURE.deps        =
HARFBUZZ.CONFIGURE.static      =
HARFBUZZ.CONFIGURE.shared      = -DBUILD_SHARED_LIBS=OFF
HARFBUZZ.CONFIGURE.extra       = -DHB_BUILD_UTILS=OFF -DHB_BUILD_TESTS=OFF
HARFBUZZ.CONFIGURE.extra      += -DHB_HAVE_FREETYPE=ON \
                                 -DFREETYPE_LIBRARIES="$(call fn.ABSOLUTE,$(CONTRIB.build/))lib" \
                                 -DFREETYPE_INCLUDE_DIRS="$(call fn.ABSOLUTE,$(CONTRIB.build/))include/freetype2" \
                                 -DFREETYPE_INCLUDE_DIR_freetype2="$(call fn.ABSOLUTE,$(CONTRIB.build/))include/freetype2" \
                                 -DFREETYPE_INCLUDE_DIR_ft2build="$(call fn.ABSOLUTE,$(CONTRIB.build/))include/freetype2"

ifeq (1,$(HOST.cross))
    ifeq (mingw,$(HOST.system))
        HARFBUZZ.CONFIGURE.extra += -DWIN32=ON -DMINGW=ON
        HARFBUZZ.CONFIGURE.extra += -DCMAKE_SYSTEM_NAME=Windows
        HARFBUZZ.CONFIGURE.extra += -DCMAKE_C_COMPILER=$(HARFBUZZ.GCC.gcc)
        HARFBUZZ.CONFIGURE.extra += -DCMAKE_C_FLAGS="-static-libgcc -static-libstdc++ -static"
        HARFBUZZ.CONFIGURE.extra += -DCMAKE_SHARED_LIBRARY_LINK_C_FLAGS="-static-libgcc -static-libstdc++ -static"
        HARFBUZZ.CONFIGURE.extra += -DCMAKE_CXX_COMPILER=$(HARFBUZZ.GCC.gxx)
        HARFBUZZ.CONFIGURE.extra += -DCMAKE_CXX_FLAGS="-static-libgcc -static-libstdc++ -static"
        HARFBUZZ.CONFIGURE.extra += -DCMAKE_RC_COMPILER=$(HOST.cross.prefix)windres
        HARFBUZZ.CONFIGURE.extra += -DHB_HAVE_DIRECTWRITE=OFF \
                                    -DHB_HAVE_GLIB=OFF \
                                    -DHB_HAVE_GOBJECT=OFF \
                                    -DHB_HAVE_GRAPHITE2=OFF \
                                    -DHB_HAVE_ICU=OFF \
                                    -DHB_HAVE_UNISCRIBE=OFF
    endif
    HARFBUZZ.CONFIGURE.args.host  = -DCMAKE_SYSTEM_NAME="$(HARFBUZZ.CONFIGURE.host)"
    HARFBUZZ.CONFIGURE.args.build = -DCMAKE_HOST_SYSTEM="$(HARFBUZZ.CONFIGURE.build)"
else
    HARFBUZZ.CONFIGURE.args.host  = -DCMAKE_HOST_SYSTEM="$(HARFBUZZ.CONFIGURE.host)"
endif

ifeq ($(HOST.system),darwin)
    HARFBUZZ.CONFIGURE.extra += -DHB_HAVE_CORETEXT=OFF -DHB_HAVE_GLIB=OFF
endif

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