CORE_PKGS += libc libm
LDFLAGS += --no-undefined
CFLAGS += -O3 -Wall -pedantic -std=gnu99

SIMPLE_DEPENDS = @(PUBLIC_SRC_STDCXX)

GL_DEPENDS = \
	$(SIMPLE_DEPENDS) \
	@(UPSTREAM_USER)/src/init/@(UPSTREAM_VERSION) \
	@(PUBLIC_SRC_EXPAT) \
	@(PUBLIC_SRC_MESA) \

ifeq ($(TARGET_NAME),testaudio_callback)
	CFLAGS += -I../../libretro-common/include
	SOURCES_C += libretro-test.c
	PKG_DEPENDS += $(SIMPLE_DEPENDS)
	: $(TUP_CWD)/audio.runtime |> !collect_pkg_runtime |>
endif

ifeq ($(TARGET_NAME),testaudio_no_callback)
	CFLAGS += -I../../libretro-common/include
	SOURCES_C += libretro-test.c
	PKG_DEPENDS += $(SIMPLE_DEPENDS)
	: $(TUP_CWD)/audio.runtime |> !collect_pkg_runtime |>
endif

ifeq ($(TARGET_NAME),testaudio_playback_wav)
	CFLAGS += -I../../libretro-common/include
	SOURCES_C += libretro-test.c
	PKG_DEPENDS += $(SIMPLE_DEPENDS)
	: $(TUP_CWD)/audio.runtime |> !collect_pkg_runtime |>
endif

ifeq ($(TARGET_NAME),button_test)
	CFLAGS += -Ilibretro-common/include
	SOURCES_C += libretro.c
	PKG_DEPENDS += $(SIMPLE_DEPENDS)
	: $(TUP_CWD)/simple.runtime |> !collect_pkg_runtime |>
endif

ifeq ($(TARGET_NAME),freebasic)
	TARGET_NAME=
#	: fbastest.bas |> fbc -dll %f -x %o |> libretro.so {core}
#	PKG_DEPENDS += $(SIMPLE_DEPENDS)
#	: $(TUP_CWD)/simple.runtime |> !collect_pkg_runtime |>
endif

ifeq ($(TARGET_NAME),pascal_pong)
	TARGET_NAME=
#	: pong.pas |> fpc -o%o %f |> libretro.so {core}
#	PKG_DEPENDS += $(SIMPLE_DEPENDS)
#	: $(TUP_CWD)/simple.runtime |> !collect_pkg_runtime |>
endif

ifeq ($(TARGET_NAME),midi_test)
	SOURCES_C += libretro.c
	PKG_DEPENDS += $(SIMPLE_DEPENDS)
	: $(TUP_CWD)/midi.runtime |> !collect_pkg_runtime |>
endif

ifeq ($(TARGET_NAME),test)
	TARGET_NAME = simple_tests
	CFLAGS += -I../../libretro-common/include
	SOURCES_C += libretro-test.c
	PKG_DEPENDS += $(SIMPLE_DEPENDS)
	: $(TUP_CWD)/simple.runtime |> !collect_pkg_runtime |>
endif

ifeq ($(TARGET_NAME),cruzes)
	SOURCES_C += cruzes.c ttf2c.c
	# : obj/Carlito-Regular.ttf |> ttf2c 24 font24 %f %o |> font24.h
	# : obj/Carlito-Regular.ttf |> ttf2c 16 font16 %f %o |> font16.h
	# : obj/Carlito-Regular.ttf |> ttf2c 10 font10 %f %o |> font10.h
	PKG_DEPENDS += $(SIMPLE_DEPENDS)
	: $(TUP_CWD)/simple.runtime |> !collect_pkg_runtime |>
endif

ifeq ($(TARGET_NAME),advanced_tests)
	CFLAGS += -I../../libretro-common/include
	SOURCES_C += libretro-test.c
	PKG_DEPENDS += $(SIMPLE_DEPENDS)
	: $(TUP_CWD)/audio.runtime |> !collect_pkg_runtime |>
endif

ifeq ($(TARGET_NAME),testgl_compute_shaders)
	CORE_PKGS += mesa
	CFLAGS += -Igl -DNDEBUG -DHAVE_ZIP_DEFLATE
	SOURCES_CXX += libretro/libretro.cpp
	SOURCES_CXX += gl/*.cpp
	SOURCES_CXX += app/boxes.cpp
	SOURCES_C += glsym/rglgen.c
	SOURCES_C += glsym/glsym_gl.c

	PKG_DEPENDS += $(GL_DEPENDS)
	: $(TUP_CWD)/testgl.runtime |> !collect_pkg_runtime |>
endif

ifeq ($(TARGET_NAME),testgl_ff)
	CORE_PKGS += mesa
	CFLAGS +=
	SOURCES_C += libretro_gl_ff_test.c glsym/rglgen.c glsym/glsym_gl.c
	PKG_DEPENDS += $(GL_DEPENDS)
	: $(TUP_CWD)/testgl.runtime |> !collect_pkg_runtime |>
endif

ifeq ($(TARGET_NAME),testgl)
	CORE_PKGS += mesa
	CFLAGS +=
	SOURCES_C += libretro_gl_test.c
	SOURCES_C += glsym/rglgen.c
	SOURCES_C += glsym/glsym_gl.c

	PKG_DEPENDS += $(GL_DEPENDS)
	: $(TUP_CWD)/testgl.runtime |> !collect_pkg_runtime |>
endif

ifeq ($(TARGET_NAME),testsw)
	CFLAGS += -I../../libretro-common/include
	SOURCES_C += libretro-test.c
	PKG_DEPENDS += $(SIMPLE_DEPENDS)
	: $(TUP_CWD)/simple.runtime |> !collect_pkg_runtime |>
endif

ifeq ($(TARGET_NAME),testsw_vram)
	CFLAGS += -I../../libretro-common/include
	SOURCES_C += libretro-test.c
	PKG_DEPENDS += $(SIMPLE_DEPENDS)
	: $(TUP_CWD)/simple.runtime |> !collect_pkg_runtime |>
endif

ifeq ($(TARGET_NAME),testvulkan_async_compute)
	CFLAGS += -I../../libretro-common/include -Iinclude
	SOURCES_C += libretro-test.c vulkan_symbol_wrapper.c
	PKG_DEPENDS += $(GL_DEPENDS)
	: $(TUP_CWD)/testgl.runtime |> !collect_pkg_runtime |>
endif

ifeq ($(TARGET_NAME),testvulkan)
	CFLAGS += -I../../libretro-common/include -Iinclude
	SOURCES_C += libretro-test.c vulkan_symbol_wrapper.c
	PKG_DEPENDS += $(GL_DEPENDS)
	: $(TUP_CWD)/testgl.runtime |> !collect_pkg_runtime |>
endif

ifneq ($(TARGET_NAME),)
: foreach $(SOURCES_C) |> !libretro_cc |> {libretro_objs}

: {libretro_objs} |> !libretro_core_link |> {core}
: {core} |> !collect_bin |>
: |> !bin |>

: README.md |> !collect_pkg |>

endif
