# The MIT License (MIT)
#
# Copyright (C) 2026 Scott Duensing
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

# ABI size test: every public SDK struct's size on the DOS target must
# match abiSizes.txt, which records them at the current DVX_ABI_VERSION.
# See abiCheck.py for the rules and DVX_ABI_VERSION (dvxTypes.h) for when
# to bump.
#
#   make          check the sizes (part of make test-host)
#   make update   regenerate abiSizes.txt after a DVX_ABI_VERSION bump, or
#                 after adding a public struct (refuses a changed struct
#                 without a bump)
#   make update KEEP_VERSION=1
#                 regenerate it at the version it has, changed structs too
#                 (nothing built against DVX is released yet, so layouts
#                 change without a bump)
#
# The sizes come from the DOS cross compiler (CC), so nothing is run and
# SAN/COV do not apply.

include ../../common.mk

SDK_ROOT  = $(DVX_ROOT)/
include ../../sdkHeaders.mk

OBJDIR    = $(HOST_OBJROOT)/test/abi
TABLE     = abiSizes.txt
HEADERS   = $(SDK_CORE_H) $(SDK_SHELL_H) $(SDK_TASKS_H) $(SDK_SQL_H) $(SDK_TEXTHELP_H) $(SDK_LISTHELP_H) $(SDK_RICHTEXT_H) $(SDK_FILEOPS_H) $(SDK_HLPFILE_H) $(SDK_XFER_H) $(SDK_CONN_H) $(SDK_PRINT_H) $(SDK_GAME_H) $(SDK_JOYSTICK_H) $(SDK_AUDIO_H) $(SDK_MUSIC_H) $(SDK_PKG_H) $(SDK_JSON_H) $(SDK_HTTP_H) $(SDK_PKGNET_H) $(SDK_SERIAL_H) $(SDK_CRYPTO_H) $(SDK_SECLINK_H) $(SDK_WIDGET_H) $(SDK_NET_H)
ABI_FLAGS = $(WARNFLAGS) -march=i486 -I$(DVX_ROOT)/src/libs/kpunch/libdvx/thirdparty

.PHONY: all check update clean

all: check

check:
	./abiCheck.py check $(TABLE) $(OBJDIR) $(CC) $(ABI_FLAGS) -- $(HEADERS)

update:
	./abiCheck.py $(if $(KEEP_VERSION),keep,update) $(TABLE) $(OBJDIR) $(CC) $(ABI_FLAGS) -- $(HEADERS)

clean:
	rm -rf $(OBJDIR)
