# Copyright 2024 Collabora Ltd.
# SPDX-License-Identifier: Zlib

all:

CXXFLAGS += -std=c++17
PKG_CONFIG ?= pkg-config
VKD3D_COMPILER ?= vkd3d-compiler

DXVK_D3D9_CFLAGS ?= `$(PKG_CONFIG) --cflags dxvk-d3d9`
DXVK_D3D9_LIBS ?= `$(PKG_CONFIG) --libs dxvk-d3d9`
DXVK_D3D11_CFLAGS ?= `$(PKG_CONFIG) --cflags dxvk-d3d11`
DXVK_D3D11_LIBS ?= `$(PKG_CONFIG) --libs dxvk-d3d11`

tests_dir ?= /usr/libexec/installed-tests/dxvk-native

executables = \
	test_native_d3d9 \
	test_native_d3d11 \
	$(NULL)

shaders = \
	test_native_d3d9_pixel.d3dbc \
	test_native_d3d9_vertex.d3dbc \
	test_native_d3d11_pixel.dxbc \
	test_native_d3d11_vertex.dxbc \
	$(NULL)

all: $(executables) $(shaders)

test_native_d3d9_pixel.d3dbc: %.d3dbc: %.hlsl Makefile
	$(VKD3D_COMPILER) -b d3dbc -p ps_2_0 -o $@ $<

test_native_d3d9_vertex.d3dbc: %.d3dbc: %.hlsl Makefile
	$(VKD3D_COMPILER) -b d3dbc -p vs_2_0 -o $@ $<

test_native_d3d11_pixel.dxbc: %.dxbc: %.hlsl Makefile
	$(VKD3D_COMPILER) -b dxbc-tpf -p ps_5_0 -o $@ $<

test_native_d3d11_vertex.dxbc: %.dxbc: %.hlsl Makefile
	$(VKD3D_COMPILER) -b dxbc-tpf -p vs_5_0 -o $@ $<

test_native_d3d9: %: %.cpp Makefile
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o$@ \
		$< \
		-DDXVK_WSI_SDL2 \
		`$(PKG_CONFIG) --cflags --libs sdl2` \
		$(DXVK_D3D9_CFLAGS) \
		$(DXVK_D3D9_LIBS) \
		$(NULL)

test_native_d3d11: %: %.cpp Makefile
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o$@ \
		$< \
		-DDXVK_WSI_SDL3 \
		`$(PKG_CONFIG) --cflags --libs sdl3` \
		$(DXVK_D3D11_CFLAGS) \
		$(DXVK_D3D11_LIBS) \
		$(NULL)

install:
	install -d $(DESTDIR)$(tests_dir)
	install -m755 $(executables) $(DESTDIR)$(tests_dir)
	install -m644 $(shaders) $(DESTDIR)$(tests_dir)

clean:
	rm -f $(executables)
	rm -f $(shaders)
	rm -f *.log
