$(eval $(call import.MODULE.defs,TEST,test,LIBHB))
$(eval $(call import.GCC,TEST))

TEST.src/   = $(SRC/)test/
TEST.build/ = $(BUILD/)test/

TEST.c   = $(wildcard $(TEST.src/)*.c)
TEST.c.o = $(patsubst $(SRC/)%.c,$(BUILD/)%.o,$(TEST.c))

TEST.exe = $(BUILD/)$(call TARGET.exe,$(HB.name)CLI)

TEST.GCC.L = $(CONTRIB.build/)lib

TEST.libs = $(LIBHB.a)

TEST.GCC.l = \
        ass avformat avfilter avcodec avutil swresample postproc mp3lame dvdnav \
        dvdread fribidi \
        samplerate swscale vpx theoraenc theoradec vorbis vorbisenc ogg x264 \
        bluray freetype xml2 bz2 z jansson harfbuzz opus speex lzma

ifeq (,$(filter $(BUILD.system),darwin cygwin mingw))
    TEST.GCC.l += fontconfig
endif

ifeq (1,$(FEATURE.qsv))
    TEST.GCC.D += USE_QSV HAVE_THREADS=1
ifeq ($(BUILD.system),linux)
    TEST.GCC.l += va va-drm
endif
endif

ifeq (1,$(FEATURE.vce))
    TEST.GCC.D += USE_VCE
endif

ifeq (1,$(FEATURE.nvenc))
    TEST.GCC.D += USE_NVENC
endif

ifeq (1,$(FEATURE.x265))
    TEST.GCC.D += USE_X265
endif

ifeq (1,$(FEATURE.flatpak))
    TEST.GCC.l += glib-2.0
endif

TEST.GCC.l += $(foreach m,$(MODULES.NAMES),$($m.OSL.libs))

TEST.install.exe = $(DESTDIR)$(PREFIX/)bin/$(notdir $(TEST.exe))
ifeq (1,$(FEATURE.flatpak))
    TEST.appdata.template = $(TEST.src/)fr.handbrake.HandBrakeCLI.appdata.xml.template
    TEST.appdata = $(TEST.build/)fr.handbrake.HandBrakeCLI.appdata.xml
    TEST.install.appdata = $(DESTDIR)$(PREFIX/)share/metainfo/$(notdir $(TEST.appdata))
endif

###############################################################################

TEST.out += $(TEST.c.o)
TEST.out += $(TEST.exe)
ifeq (1,$(FEATURE.flatpak))
    TEST.out += $(TEST.appdata)
endif

BUILD.out += $(TEST.out)
BUILD.out += $(TEST.install.exe)
ifeq (1,$(FEATURE.flatpak))
    BUILD.out += $(TEST.install.appdata)
endif

###############################################################################

TEST.GCC.I += $(LIBHB.GCC.I)

ifeq ($(BUILD.system),darwin)
    TEST.GCC.f += IOKit CoreServices CoreText CoreGraphics AudioToolbox VideoToolbox CoreMedia CoreVideo Foundation
    TEST.GCC.l += iconv
else ifeq ($(BUILD.system),linux)
    TEST.GCC.l += pthread dl m
else ifeq ($(BUILD.system),kfreebsd)
    TEST.GCC.l += pthread dl m
else ifeq ($(BUILD.system),freebsd)
    TEST.GCC.L += $(LOCALBASE)/lib
    TEST.GCC.l += pthread m
else ifeq ($(BUILD.system),solaris)
    TEST.GCC.l += pthread nsl socket
ifneq (,$(filter $(BUILD.release),2.10))
    TEST.GCC.l += iconv
endif
    TEST.GCC.D += _POSIX_C_SOURCE=200112L __EXTENSIONS__
else ifeq (1-mingw,$(BUILD.cross)-$(BUILD.system))
ifeq ($(HAS.dlfcn),1)
    TEST.GCC.l += dl
endif
ifeq (1,$(HAS.pthread))
    TEST.GCC.l += pthread
else
    TEST.GCC.l += pthreadGC2
endif
    TEST.GCC.l += bcrypt iconv ws2_32 regex uuid ole32
    TEST.GCC.D += PTW32_STATIC_LIB
    TEST.GCC.args.extra.exe++ += -static
endif #   (1-mingw,$(BUILD.cross)-$(BUILD.system))
