SDL: Removed the SDL_Version structure, moved SDL version to SDL.h

From 661f2fc1fca76f79f536919fefe5887a875b6afb Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 14 May 2024 07:47:13 -0700
Subject: [PATCH] Removed the SDL_Version structure, moved SDL version to SDL.h

Inspired by https://github.com/libsdl-org/SDL/issues/9788
---
 .wikiheaders-options                          |  4 +-
 .../cmake/sdl3-config-version.cmake           | 16 ++--
 .../resources/CMake/sdl3-config-version.cmake | 16 ++--
 build-scripts/SDL_migration.cocci             | 21 +++--
 build-scripts/android-prefab.sh               |  8 +-
 build-scripts/build-release.py                |  6 +-
 build-scripts/rename_api.py                   |  2 +-
 build-scripts/showrev.sh                      |  6 +-
 build-scripts/test-versioning.sh              | 24 +++---
 build-scripts/update-version.sh               | 26 +++---
 build-scripts/wikiheaders.pl                  | 24 +++---
 docs/README-migration.md                      |  9 +-
 include/SDL3/SDL.h                            |  8 ++
 include/SDL3/SDL_oldnames.h                   |  6 +-
 include/SDL3/SDL_version.h                    | 84 ++++++++-----------
 src/SDL.c                                     | 39 ++-------
 src/core/android/SDL_android.c                |  2 +-
 src/dynapi/SDL_dynapi_procs.h                 |  2 +-
 test/testautomation_platform.c                | 53 ++----------
 test/testver.c                                | 12 +--
 20 files changed, 153 insertions(+), 215 deletions(-)

diff --git a/.wikiheaders-options b/.wikiheaders-options
index bf7661ca5f9fb..aefa8b714e7e4 100644
--- a/.wikiheaders-options
+++ b/.wikiheaders-options
@@ -5,10 +5,10 @@ wikisubdir =
 readmesubdir = docs
 apiprefixregex = (SDL_|SDLK_)
 mainincludefname = SDL3/SDL.h
-versionfname = include/SDL3/SDL_version.h
+versionfname = include/SDL3/SDL.h
 versionmajorregex = \A\#define\s+SDL_MAJOR_VERSION\s+(\d+)\Z
 versionminorregex = \A\#define\s+SDL_MINOR_VERSION\s+(\d+)\Z
-versionpatchregex = \A\#define\s+SDL_PATCHLEVEL\s+(\d+)\Z
+versionmicroregex = \A\#define\s+SDL_MICRO_VERSION\s+(\d+)\Z
 selectheaderregex = \ASDL.*?\.h\Z
 projecturl = https://libsdl.org/
 wikiurl = https://wiki.libsdl.org
diff --git a/VisualC/pkg-support/cmake/sdl3-config-version.cmake b/VisualC/pkg-support/cmake/sdl3-config-version.cmake
index 3c455dc1917cd..2f522c64aac6d 100644
--- a/VisualC/pkg-support/cmake/sdl3-config-version.cmake
+++ b/VisualC/pkg-support/cmake/sdl3-config-version.cmake
@@ -3,22 +3,22 @@
 # SDL CMake version configuration file:
 # This file is meant to be placed in a cmake subfolder of SDL3-devel-3.x.y-VC
 
-if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/../include/SDL3/SDL_version.h")
-    message(AUTHOR_WARNING "Could not find SDL3/SDL_version.h. This script is meant to be placed in the root of SDL3-devel-3.x.y-VC")
+if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/../include/SDL3/SDL.h")
+    message(AUTHOR_WARNING "Could not find SDL3/SDL.h. This script is meant to be placed in the root of SDL3-devel-3.x.y-VC")
     return()
 endif()
 
-file(READ "${CMAKE_CURRENT_LIST_DIR}/../include/SDL3/SDL_version.h" _sdl_version_h)
+file(READ "${CMAKE_CURRENT_LIST_DIR}/../include/SDL3/SDL.h" _sdl_version_h)
 string(REGEX MATCH "#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)" _sdl_major_re "${_sdl_version_h}")
 set(_sdl_major "${CMAKE_MATCH_1}")
 string(REGEX MATCH "#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)" _sdl_minor_re "${_sdl_version_h}")
 set(_sdl_minor "${CMAKE_MATCH_1}")
-string(REGEX MATCH "#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)" _sdl_patch_re "${_sdl_version_h}")
-set(_sdl_patch "${CMAKE_MATCH_1}")
-if(_sdl_major_re AND _sdl_minor_re AND _sdl_patch_re)
-    set(PACKAGE_VERSION "${_sdl_major}.${_sdl_minor}.${_sdl_patch}")
+string(REGEX MATCH "#define[ \t]+SDL_MICRO_VERSION[ \t]+([0-9]+)" _sdl_micro_re "${_sdl_version_h}")
+set(_sdl_micro "${CMAKE_MATCH_1}")
+if(_sdl_major_re AND _sdl_minor_re AND _sdl_micro_re)
+    set(PACKAGE_VERSION "${_sdl_major}.${_sdl_minor}.${_sdl_micro}")
 else()
-    message(AUTHOR_WARNING "Could not extract version from SDL3/SDL_version.h.")
+    message(AUTHOR_WARNING "Could not extract version from SDL3/SDL.h.")
     return()
 endif()
 
diff --git a/Xcode/SDL/pkg-support/resources/CMake/sdl3-config-version.cmake b/Xcode/SDL/pkg-support/resources/CMake/sdl3-config-version.cmake
index 21d6f7d7c57c4..be9696cf57ef0 100644
--- a/Xcode/SDL/pkg-support/resources/CMake/sdl3-config-version.cmake
+++ b/Xcode/SDL/pkg-support/resources/CMake/sdl3-config-version.cmake
@@ -12,7 +12,7 @@ get_filename_component(_sdl3_xcframework_parent_path "${_sdl3_xcframework_parent
 get_filename_component(_sdl3_xcframework_parent_path "${_sdl3_xcframework_parent_path}" PATH)           # /
 set(_sdl3_xcframework "${_sdl3_xcframework_parent_path}/SDL3.xcframework")                              # /SDL3.xcframework
 set(_sdl3_framework "${_sdl3_xcframework}/macos-arm64_x86_64/SDL3.framework")                           # /SDL3.xcframework/macos-arm64_x86_64/SDL3.framework
-set(_sdl3_version_h "${_sdl3_framework}/Headers/SDL_version.h")                                         # /SDL3.xcframework/macos-arm64_x86_64/SDL3.framework/Headers/SDL_version.h
+set(_sdl3_version_h "${_sdl3_framework}/Headers/SDL.h")                                         # /SDL3.xcframework/macos-arm64_x86_64/SDL3.framework/Headers/SDL.h
 
 if(NOT EXISTS "${_sdl3_version_h}")
     message(AUTHOR_WARNING "Cannot not find ${_sdl3_framework}. This script is meant to be placed in share/cmake/SDL3, next to SDL3.xcframework")
@@ -30,12 +30,12 @@ string(REGEX MATCH "#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)" _sdl_major_re
 set(_sdl_major "${CMAKE_MATCH_1}")
 string(REGEX MATCH "#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)" _sdl_minor_re "${_sdl_version_h}")
 set(_sdl_minor "${CMAKE_MATCH_1}")
-string(REGEX MATCH "#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)" _sdl_patch_re "${_sdl_version_h}")
-set(_sdl_patch "${CMAKE_MATCH_1}")
-if(_sdl_major_re AND _sdl_minor_re AND _sdl_patch_re)
-    set(PACKAGE_VERSION "${_sdl_major}.${_sdl_minor}.${_sdl_patch}")
+string(REGEX MATCH "#define[ \t]+SDL_MICRO_VERSION[ \t]+([0-9]+)" _sdl_micro_re "${_sdl_version_h}")
+set(_sdl_micro "${CMAKE_MATCH_1}")
+if(_sdl_major_re AND _sdl_minor_re AND _sdl_micro_re)
+    set(PACKAGE_VERSION "${_sdl_major}.${_sdl_minor}.${_sdl_micro}")
 else()
-    message(AUTHOR_WARNING "Could not extract version from SDL_version.h.")
+    message(AUTHOR_WARNING "Could not extract version from SDL.h.")
     return()
 endif()
 
@@ -43,8 +43,8 @@ unset(_sdl_major_re)
 unset(_sdl_major)
 unset(_sdl_minor_re)
 unset(_sdl_minor)
-unset(_sdl_patch_re)
-unset(_sdl_patch)
+unset(_sdl_micro_re)
+unset(_sdl_micro)
 
 if(PACKAGE_FIND_VERSION_RANGE)
     # Package version must be in the requested version range
diff --git a/build-scripts/SDL_migration.cocci b/build-scripts/SDL_migration.cocci
index 0abd449edd68a..d4e4f0d09e29e 100644
--- a/build-scripts/SDL_migration.cocci
+++ b/build-scripts/SDL_migration.cocci
@@ -2985,11 +2985,6 @@ SDL_GamepadBinding *e1;
 - e1->outputType
 + e1->output_type
 @@
-typedef SDL_version, SDL_Version;
-@@
-- SDL_version
-+ SDL_Version
-@@
 @@
 - SDL_HINT_ALLOW_TOPMOST
 + SDL_HINT_WINDOW_ALLOW_TOPMOST
@@ -3137,15 +3132,23 @@ typedef SDL_Colour, SDL_Color;
   (...)
 @@
 @@
-- SDL_TABLESIZE
-+ SDL_arraysize
-@@
-@@
 - SDL_iPhoneSetEventPump
 + SDL_iOSSetEventPump
   (...)
 @@
 @@
+- SDL_COMPILEDVERSION
++ SDL_VERSION
+@@
+@@
+- SDL_PATCHLEVEL
++ SDL_MICRO_VERSION
+@@
+@@
+- SDL_TABLESIZE
++ SDL_arraysize
+@@
+@@
 - SDLK_QUOTE
 + SDLK_APOSTROPHE
 @@
diff --git a/build-scripts/android-prefab.sh b/build-scripts/android-prefab.sh
index 586054204c0fc..41592ee5c32ee 100755
--- a/build-scripts/android-prefab.sh
+++ b/build-scripts/android-prefab.sh
@@ -40,10 +40,10 @@ android_api=19
 android_ndk=21
 android_stl="c++_shared"
 
-sdl_major=$(sed -ne 's/^#define SDL_MAJOR_VERSION  *//p' "${sdl_root}/include/SDL3/SDL_version.h")
-sdl_minor=$(sed -ne 's/^#define SDL_MINOR_VERSION  *//p' "${sdl_root}/include/SDL3/SDL_version.h")
-sdl_patch=$(sed -ne 's/^#define SDL_PATCHLEVEL  *//p' "${sdl_root}/include/SDL3/SDL_version.h")
-sdl_version="${sdl_major}.${sdl_minor}.${sdl_patch}"
+sdl_major=$(sed -ne 's/^#define SDL_MAJOR_VERSION  *//p' "${sdl_root}/include/SDL3/SDL.h")
+sdl_minor=$(sed -ne 's/^#define SDL_MINOR_VERSION  *//p' "${sdl_root}/include/SDL3/SDL.h")
+sdl_micro=$(sed -ne 's/^#define SDL_MICRO_VERSION  *//p' "${sdl_root}/include/SDL3/SDL.h")
+sdl_version="${sdl_major}.${sdl_minor}.${sdl_micro}"
 echo "Building Android prefab package for SDL version $sdl_version"
 
 prefabhome="${build_root}/prefab-${sdl_version}"
diff --git a/build-scripts/build-release.py b/build-scripts/build-release.py
index d2c38abe8d517..ef01768eb50a0 100755
--- a/build-scripts/build-release.py
+++ b/build-scripts/build-release.py
@@ -509,12 +509,12 @@ def zip_directory(zf: zipfile.ZipFile, directory: Path, arcrelpath: str):
 
     @classmethod
     def extract_sdl_version(cls, root: Path, project: str):
-        with open(root / f"include/{project}/SDL_version.h", "r") as f:
+        with open(root / f"include/{project}/SDL.h", "r") as f:
             text = f.read()
         major = next(re.finditer(r"^#define SDL_MAJOR_VERSION\s+([0-9]+)$", text, flags=re.M)).group(1)
         minor = next(re.finditer(r"^#define SDL_MINOR_VERSION\s+([0-9]+)$", text, flags=re.M)).group(1)
-        patch = next(re.finditer(r"^#define SDL_PATCHLEVEL\s+([0-9]+)$", text, flags=re.M)).group(1)
-        return f"{major}.{minor}.{patch}"
+        micro = next(re.finditer(r"^#define SDL_MICRO_VERSION\s+([0-9]+)$", text, flags=re.M)).group(1)
+        return f"{major}.{minor}.{micro}"
 
 
 def main(argv=None):
diff --git a/build-scripts/rename_api.py b/build-scripts/rename_api.py
index 7c02b9e945869..b1f6c183fe48b 100755
--- a/build-scripts/rename_api.py
+++ b/build-scripts/rename_api.py
@@ -23,7 +23,7 @@ def main():
         exit(1)
 
     # Check whether we can still modify the ABI
-    version_header = pathlib.Path( SDL_INCLUDE_DIR / "SDL_version.h" ).read_text()
+    version_header = pathlib.Path( SDL_INCLUDE_DIR / "SDL.h" ).read_text()
     if not re.search("SDL_MINOR_VERSION\s+[01]\s", version_header):
         raise Exception("ABI is frozen, symbols cannot be renamed")
 
diff --git a/build-scripts/showrev.sh b/build-scripts/showrev.sh
index 98bb335b2afad..eba61d5d3cde4 100755
--- a/build-scripts/showrev.sh
+++ b/build-scripts/showrev.sh
@@ -10,9 +10,9 @@ if [ -e ./VERSION.txt ]; then
     exit 0
 fi
 
-major=$(sed -ne 's/^#define SDL_MAJOR_VERSION  *//p' include/SDL3/SDL_version.h)
-minor=$(sed -ne 's/^#define SDL_MINOR_VERSION  *//p' include/SDL3/SDL_version.h)
-micro=$(sed -ne 's/^#define SDL_PATCHLEVEL  *//p' include/SDL3/SDL_version.h)
+major=$(sed -ne 's/^#define SDL_MAJOR_VERSION  *//p' include/SDL3/SDL.h)
+minor=$(sed -ne 's/^#define SDL_MINOR_VERSION  *//p' include/SDL3/SDL.h)
+micro=$(sed -ne 's/^#define SDL_MICRO_VERSION  *//p' include/SDL3/SDL.h)
 version="${major}.${minor}.${micro}"
 
 if [ -x "$(command -v git)" ]; then
diff --git a/build-scripts/test-versioning.sh b/build-scripts/test-versioning.sh
index a887a9cc86946..13ae091314e54 100755
--- a/build-scripts/test-versioning.sh
+++ b/build-scripts/test-versioning.sh
@@ -6,9 +6,9 @@ set -eu
 
 cd `dirname $0`/..
 
-ref_major=$(sed -ne 's/^#define SDL_MAJOR_VERSION  *//p' include/SDL3/SDL_version.h)
-ref_minor=$(sed -ne 's/^#define SDL_MINOR_VERSION  *//p' include/SDL3/SDL_version.h)
-ref_micro=$(sed -ne 's/^#define SDL_PATCHLEVEL  *//p' include/SDL3/SDL_version.h)
+ref_major=$(sed -ne 's/^#define SDL_MAJOR_VERSION  *//p' include/SDL3/SDL.h)
+ref_minor=$(sed -ne 's/^#define SDL_MINOR_VERSION  *//p' include/SDL3/SDL.h)
+ref_micro=$(sed -ne 's/^#define SDL_MICRO_VERSION  *//p' include/SDL3/SDL.h)
 ref_version="${ref_major}.${ref_minor}.${ref_micro}"
 
 tests=0
@@ -30,7 +30,7 @@ version=$(sed -Ene 's/^project\(SDL[0-9]+ LANGUAGES C VERSION "([0-9.]*)"\)$/\1/
 if [ "$ref_version" = "$version" ]; then
     ok "CMakeLists.txt $version"
 else
-    not_ok "CMakeLists.txt $version disagrees with SDL_version.h $ref_version"
+    not_ok "CMakeLists.txt $version disagrees with SDL.h $ref_version"
 fi
 
 major=$(sed -ne 's/.*SDL_MAJOR_VERSION = \([0-9]*\);/\1/p' android-project/app/src/main/java/org/libsdl/app/SDLActivity.java)
@@ -41,7 +41,7 @@ version="${major}.${minor}.${micro}"
 if [ "$ref_version" = "$version" ]; then
     ok "SDLActivity.java $version"
 else
-    not_ok "android-project/app/src/main/java/org/libsdl/app/SDLActivity.java $version disagrees with SDL_version.h $ref_version"
+    not_ok "android-project/app/src/main/java/org/libsdl/app/SDLActivity.java $version disagrees with SDL.h $ref_version"
 fi
 
 tuple=$(sed -ne 's/^ *FILEVERSION *//p' src/core/windows/version.rc | tr -d '\r')
@@ -50,7 +50,7 @@ ref_tuple="${ref_major},${ref_minor},${ref_micro},0"
 if [ "$ref_tuple" = "$tuple" ]; then
     ok "version.rc FILEVERSION $tuple"
 else
-    not_ok "version.rc FILEVERSION $tuple disagrees with SDL_version.h $ref_tuple"
+    not_ok "version.rc FILEVERSION $tuple disagrees with SDL.h $ref_tuple"
 fi
 
 tuple=$(sed -ne 's/^ *PRODUCTVERSION *//p' src/core/windows/version.rc | tr -d '\r')
@@ -58,7 +58,7 @@ tuple=$(sed -ne 's/^ *PRODUCTVERSION *//p' src/core/windows/version.rc | tr -d '
 if [ "$ref_tuple" = "$tuple" ]; then
     ok "version.rc PRODUCTVERSION $tuple"
 else
-    not_ok "version.rc PRODUCTVERSION $tuple disagrees with SDL_version.h $ref_tuple"
+    not_ok "version.rc PRODUCTVERSION $tuple disagrees with SDL.h $ref_tuple"
 fi
 
 tuple=$(sed -Ene 's/^ *VALUE "FileVersion", "([0-9, ]*)\\0"\r?$/\1/p' src/core/windows/version.rc | tr -d '\r')
@@ -67,7 +67,7 @@ ref_tuple="${ref_major}, ${ref_minor}, ${ref_micro}, 0"
 if [ "$ref_tuple" = "$tuple" ]; then
     ok "version.rc FileVersion $tuple"
 else
-    not_ok "version.rc FileVersion $tuple disagrees with SDL_version.h $ref_tuple"
+    not_ok "version.rc FileVersion $tuple disagrees with SDL.h $ref_tuple"
 fi
 
 tuple=$(sed -Ene 's/^ *VALUE "ProductVersion", "([0-9, ]*)\\0"\r?$/\1/p' src/core/windows/version.rc | tr -d '\r')
@@ -75,7 +75,7 @@ tuple=$(sed -Ene 's/^ *VALUE "ProductVersion", "([0-9, ]*)\\0"\r?$/\1/p' src/cor
 if [ "$ref_tuple" = "$tuple" ]; then
     ok "version.rc ProductVersion $tuple"
 else
-    not_ok "version.rc ProductVersion $tuple disagrees with SDL_version.h $ref_tuple"
+    not_ok "version.rc ProductVersion $tuple disagrees with SDL.h $ref_tuple"
 fi
 
 version=$(sed -Ene '/CFBundleShortVersionString/,+1 s/.*<string>(.*)<\/string>.*/\1/p' Xcode/SDL/Info-Framework.plist)
@@ -83,7 +83,7 @@ version=$(sed -Ene '/CFBundleShortVersionString/,+1 s/.*<string>(.*)<\/string>.*
 if [ "$ref_version" = "$version" ]; then
     ok "Info-Framework.plist CFBundleShortVersionString $version"
 else
-    not_ok "Info-Framework.plist CFBundleShortVersionString $version disagrees with SDL_version.h $ref_version"
+    not_ok "Info-Framework.plist CFBundleShortVersionString $version disagrees with SDL.h $ref_version"
 fi
 
 version=$(sed -Ene '/CFBundleVersion/,+1 s/.*<string>(.*)<\/string>.*/\1/p' Xcode/SDL/Info-Framework.plist)
@@ -91,7 +91,7 @@ version=$(sed -Ene '/CFBundleVersion/,+1 s/.*<string>(.*)<\/string>.*/\1/p' Xcod
 if [ "$ref_version" = "$version" ]; then
     ok "Info-Framework.plist CFBundleVersion $version"
 else
-    not_ok "Info-Framework.plist CFBundleVersion $version disagrees with SDL_version.h $ref_version"
+    not_ok "Info-Framework.plist CFBundleVersion $version disagrees with SDL.h $ref_version"
 fi
 
 version=$(sed -Ene 's/Title SDL (.*)/\1/p' Xcode/SDL/pkg-support/SDL.info)
@@ -99,7 +99,7 @@ version=$(sed -Ene 's/Title SDL (.*)/\1/p' Xcode/SDL/pkg-support/SDL.info)
 if [ "$ref_version" = "$version" ]; then
     ok "SDL.info Title $version"
 else
-    not_ok "SDL.info Title $version disagrees with SDL_version.h $ref_version"
+    not_ok "SDL.info Title $version disagrees with SDL.h $ref_version"
 fi
 
 marketing=$(sed -Ene 's/.*MARKETING_VERSION = (.*);/\1/p' Xcode/SDL/SDL.xcodeproj/project.pbxproj)
diff --git a/build-scripts/update-version.sh b/build-scripts/update-version.sh
index dd64761806b38..0f65dcb699f0a 100755
--- a/build-scripts/update-version.sh
+++ b/build-scripts/update-version.sh
@@ -22,8 +22,8 @@ fi
 
 MAJOR="$1"
 MINOR="$2"
-PATCH="$3"
-NEWVERSION="$MAJOR.$MINOR.$PATCH"
+MICRO="$3"
+NEWVERSION="$MAJOR.$MINOR.$MICRO"
 
 echo "Updating version to '$NEWVERSION' ..."
 
@@ -41,14 +41,14 @@ perl -w -pi -e 's/(DYLIB_CURRENT_VERSION\s*=\s*)\d+\.\d+\.\d+/${1}'$DYVER'.0.0/;
 perl -w -pi -e 's/(DYLIB_COMPATIBILITY_VERSION\s*=\s*)\d+\.\d+\.\d+/${1}'$DYVER'.0.0/;' Xcode/SDL/SDL.xcodeproj/project.pbxproj
 
 # non-zero patch?
-if [ "x$PATCH" != "x0" ]; then
+if [ "x$MICRO" != "x0" ]; then
     if [ `expr $MINOR % 2` = "0" ]; then
         # If patch is not zero, but minor is even, it's a bugfix release.
-        perl -w -pi -e 's/(DYLIB_CURRENT_VERSION\s*=\s*)\d+\.\d+\.\d+/${1}'$DYVER'.'$PATCH'.0/;' Xcode/SDL/SDL.xcodeproj/project.pbxproj
+        perl -w -pi -e 's/(DYLIB_CURRENT_VERSION\s*=\s*)\d+\.\d+\.\d+/${1}'$DYVER'.'$MICRO'.0/;' Xcode/SDL/SDL.xcodeproj/project.pbxproj
 
     else
         # If patch is not zero, but minor is odd, it's a development prerelease.
-        DYVER=`expr $MINOR \* 100 + $PATCH + 1`
+        DYVER=`expr $MINOR \* 100 + $MICRO + 1`
         perl -w -pi -e 's/(DYLIB_CURRENT_VERSION\s*=\s*)\d+\.\d+\.\d+/${1}'$DYVER'.0.0/;' Xcode/SDL/SDL.xcodeproj/project.pbxproj
         perl -w -pi -e 's/(DYLIB_COMPATIBILITY_VERSION\s*=\s*)\d+\.\d+\.\d+/${1}'$DYVER'.0.0/;' Xcode/SDL/SDL.xcodeproj/project.pbxproj
     fi
@@ -58,16 +58,16 @@ perl -w -pi -e 's/\A(project\(SDL[0-9]+ LANGUAGES C VERSION ")[0-9.]+/${1}'$NEWV
 
 perl -w -pi -e 's/\A(.* SDL_MAJOR_VERSION = )\d+/${1}'$MAJOR'/;' android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
 perl -w -pi -e 's/\A(.* SDL_MINOR_VERSION = )\d+/${1}'$MINOR'/;' android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
-perl -w -pi -e 's/\A(.* SDL_MICRO_VERSION = )\d+/${1}'$PATCH'/;' android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
+perl -w -pi -e 's/\A(.* SDL_MICRO_VERSION = )\d+/${1}'$MICRO'/;' android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
 
-perl -w -pi -e 's/(\#define SDL_MAJOR_VERSION\s+)\d+/${1}'$MAJOR'/;' include/SDL3/SDL_version.h
-perl -w -pi -e 's/(\#define SDL_MINOR_VERSION\s+)\d+/${1}'$MINOR'/;' include/SDL3/SDL_version.h
-perl -w -pi -e 's/(\#define SDL_PATCHLEVEL\s+)\d+/${1}'$PATCH'/;' include/SDL3/SDL_version.h
+perl -w -pi -e 's/(\#define SDL_MAJOR_VERSION\s+)\d+/${1}'$MAJOR'/;' include/SDL3/SDL.h
+perl -w -pi -e 's/(\#define SDL_MINOR_VERSION\s+)\d+/${1}'$MINOR'/;' include/SDL3/SDL.h
+perl -w -pi -e 's/(\#define SDL_MICRO_VERSION\s+)\d+/${1}'$MICRO'/;' include/SDL3/SDL.h
 
-perl -w -pi -e 's/(FILEVERSION\s+)\d+,\d+,\d+/${1}'$MAJOR','$MINOR','$PATCH'/;' src/core/windows/version.rc
-perl -w -pi -e 's/(PRODUCTVERSION\s+)\d+,\d+,\d+/${1}'$MAJOR','$MINOR','$PATCH'/;' src/core/windows/version.rc
-perl -w -pi -e 's/(VALUE "FileVersion", ")\d+, \d+, \d+/${1}'$MAJOR', '$MINOR', '$PATCH'/;' src/core/windows/version.rc
-perl -w -pi -e 's/(VALUE "ProductVersion", ")\d+, \d+, \d+/${1}'$MAJOR', '$MINOR', '$PATCH'/;' src/core/windows/version.rc
+perl -w -pi -e 's/(FILEVERSION\s+)\d+,\d+,\d+/${1}'$MAJOR','$MINOR','$MICRO'/;' src/core/windows/version.rc
+perl -w -pi -e 's/(PRODUCTVERSION\s+)\d+,\d+,\d+/${1}'$MAJOR','$MINOR','$MICRO'/;' src/core/windows/version.rc
+perl -w -pi -e 's/(VALUE "FileVersion", ")\d+, \d+, \d+/${1}'$MAJOR', '$MINOR', '$MICRO'/;' src/core/windows/version.rc
+perl -w -pi -e 's/(VALUE "ProductVersion", ")\d+, \d+, \d+/${1}'$MAJOR', '$MINOR', '$MICRO'/;' src/core/windows/version.rc
 
 echo "Running build-scripts/test-versioning.sh to verify changes..."
 ./build-scripts/test-versioning.sh
diff --git a/build-scripts/wikiheaders.pl b/build-scripts/wikiheaders.pl
index 185701b479dcf..e7a423cd74e33 100755
--- a/build-scripts/wikiheaders.pl
+++ b/build-scripts/wikiheaders.pl
@@ -13,10 +13,10 @@
 my $incsubdir = 'include';
 my $readmesubdir = undef;
 my $apiprefixregex = undef;
-my $versionfname = 'include/SDL_version.h';
+my $versionfname = 'include/SDL.h';
 my $versionmajorregex = '\A\#define\s+SDL_MAJOR_VERSION\s+(\d+)\Z';
 my $versionminorregex = '\A\#define\s+SDL_MINOR_VERSION\s+(\d+)\Z';
-my $versionpatchregex = '\A\#define\s+SDL_PATCHLEVEL\s+(\d+)\Z';
+my $versionmicroregex = '\A\#define\s+SDL_MICRO_VERSION\s+(\d+)\Z';
 my $mainincludefname = 'SDL.h';
 my $selectheaderregex = '\ASDL.*?\.h\Z';
 my $projecturl = 'https://libsdl.org/';
@@ -92,7 +92,7 @@
             $readmesubdir = $val, next if $key eq 'readmesubdir';
             $versionmajorregex = $val, next if $key eq 'versionmajorregex';
             $versionminorregex = $val, next if $key eq 'versionminorregex';
-            $versionpatchregex = $val, next if $key eq 'versionpatchregex';
+            $versionmicroregex = $val, next if $key eq 'versionmicroregex';
             $versionfname = $val, next if $key eq 'versionfname';
             $mainincludefname = $val, next if $key eq 'mainincludefname';
             $selectheaderregex = $val, next if $key eq 'selectheaderregex';
@@ -2036,19 +2036,19 @@ sub print_undocumented_section {
     open(FH, '<', "$srcpath/$versionfname") or die("Can't open '$srcpath/$versionfname': $!\n");
     my $majorver = 0;
     my $minorver = 0;
-    my $patchver = 0;
+    my $microver = 0;
     while (<FH>) {
         chomp;
         if (/$versionmajorregex/) {
             $majorver = int($1);
         } elsif (/$versionminorregex/) {
             $minorver = int($1);
-        } elsif (/$versionpatchregex/) {
-            $patchver = int($1);
+        } elsif (/$versionmicroregex/) {
+            $microver = int($1);
         }
     }
     close(FH);
-    my $fullversion = "$majorver.$minorver.$patchver";
+    my $fullversion = "$majorver.$minorver.$microver";
 
     foreach (keys %headersyms) {
         my $sym = $_;
@@ -2318,19 +2318,19 @@ sub print_undocumented_section {
     open(FH, '<', "$srcpath/$versionfname") or die("Can't open '$srcpath/$versionfname': $!\n");
     my $majorver = 0;
     my $minorver = 0;
-    my $patchver = 0;
+    my $microver = 0;
     while (<FH>) {
         chomp;
         if (/$versionmajorregex/) {
             $majorver = int($1);
         } elsif (/$versionminorregex/) {
             $minorver = int($1);
-        } elsif (/$versionpatchregex/) {
-            $patchver = int($1);
+        } elsif (/$versionmicroregex/) {
+            $microver = int($1);
         }
     }
     close(FH);
-    my $fullversion = "$majorver.$minorver.$patchver";
+    my $fullversion = "$majorver.$minorver.$microver";
 
     my $latex_fname = "$srcpath/$projectshortname.tex";
     my $latex_tmpfname = "$latex_fname.tmp";
@@ -2369,7 +2369,7 @@ sub print_undocumented_section {
 \\begin{document}
 \\frontmatter
 
-\\title{$projectfullname $majorver.$minorver.$patchver Reference Manual}
+\\title{$projectfullname $majorver.$minorver.$microver Reference Manual}
 \\author{The $projectshortname Developers}
 \\maketitle
 
diff --git a/docs/README-migration.md b/docs/README-migration.md
index e96c7430ec31f..bb85f65d79675 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -1671,9 +1671,14 @@ The following functions have been removed:
 
 SDL_GetRevisionNumber() has been removed from the API, it always returned 0 in SDL 2.0.
 
+SDL_GetVersion() returns the version number, which can be directly compared with another version wrapped with SDL_VERSIONNUM().
 
-The following structures have been renamed:
-* SDL_version => SDL_Version
+The following structures have been removed:
+* SDL_version
+
+The following symbols have been renamed:
+* SDL_COMPILEDVERSION => SDL_VERSION
+* SDL_PATCHLEVEL => SDL_MICRO_VERSION
 
 ## SDL_video.h
 
diff --git a/include/SDL3/SDL.h b/include/SDL3/SDL.h
index 6cda579f79ad7..c42efc241ac59 100644
--- a/include/SDL3/SDL.h
+++ b/include/SDL3/SDL.h
@@ -28,6 +28,14 @@
 #ifndef SDL_h_
 #define SDL_h_
 
+/**
+ * The current version of SDL
+ */
+#define SDL_MAJOR_VERSION   3
+#define SDL_MINOR_VERSION   1
+#define SDL_MICRO_VERSION   2
+
+
 #include <SDL3/SDL_stdinc.h>
 #include <SDL3/SDL_assert.h>
 #include <SDL3/SDL_atomic.h>
diff --git a/include/SDL3/SDL_oldnames.h b/include/SDL3/SDL_oldnames.h
index f4cdc01ac094b..d0e5c800d1cec 100644
--- a/include/SDL3/SDL_oldnames.h
+++ b/include/SDL3/SDL_oldnames.h
@@ -529,7 +529,8 @@
 #define SDL_GetTicks64 SDL_GetTicks
 
 /* ##SDL_version.h */
-#define SDL_version SDL_Version
+#define SDL_COMPILEDVERSION SDL_VERSION
+#define SDL_PATCHLEVEL SDL_MICRO_VERSION
 
 /* ##SDL_video.h */
 #define SDL_GetClosestDisplayMode SDL_GetClosestFullscreenDisplayMode
@@ -1038,7 +1039,8 @@
 #define SDL_GetTicks64 SDL_GetTicks64_renamed_SDL_GetTicks
 
 /* ##SDL_version.h */
-#define SDL_version SDL_version_renamed_SDL_Version
+#define SDL_COMPILEDVERSION SDL_COMPILEDVERSION_renamed_SDL_VERSION
+#define SDL_PATCHLEVEL SDL_PATCHLEVEL_renamed_SDL_MICRO_VERSION
 
 /* ##SDL_video.h */
 #define SDL_GetClosestDisplayMode SDL_GetClosestDisplayMode_renamed_SDL_GetClosestFullscreenDisplayMode
diff --git a/include/SDL3/SDL_version.h b/include/SDL3/SDL_version.h
index 9f05677200112..6cfcc3318a139 100644
--- a/include/SDL3/SDL_version.h
+++ b/include/SDL3/SDL_version.h
@@ -38,75 +38,59 @@ extern "C" {
 #endif
 
 /**
- * Information about the version of SDL in use.
+ * This macro turns the version numbers into a numeric value.
  *
- * Represents the library's version as three levels: major revision
- * (increments with massive changes, additions, and enhancements), minor
- * revision (increments with backwards-compatible changes to the major
- * revision), and patchlevel (increments with fixes to the minor revision).
+ * (1,2,3) becomes 1002003.
  *
- * \since This struct is available since SDL 3.0.0.
+ * \param major the major version number.
+ * \param minor the minorversion number.
+ * \param patch the patch version number.
  *
- * \sa SDL_VERSION
- * \sa SDL_GetVersion
+ * \since This macro is available since SDL 3.0.0.
  */
-typedef struct SDL_Version
-{
-    Uint8 major;        /**< major version */
-    Uint8 minor;        /**< minor version */
-    Uint8 patch;        /**< update version */
-} SDL_Version;
-
-/* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL */
-#define SDL_MAJOR_VERSION   3
-#define SDL_MINOR_VERSION   1
-#define SDL_PATCHLEVEL      2
+#define SDL_VERSIONNUM(major, minor, patch) \
+    ((major) * 1000000 + (minor) * 1000 + (patch))
 
 /**
- * Macro to determine SDL version program was compiled against.
+ * This macro extracts the major version from a version number
  *
- * This macro fills in an SDL_Version structure with the version of the
- * library you compiled against. This is determined by what header the
- * compiler uses. Note that if you dynamically linked the library, you might
- * have a slightly newer or older version at runtime. That version can be
- * determined with SDL_GetVersion(), which, unlike SDL_VERSION(), is not a
- * macro.
+ * 1002003 becomes 1.
  *
- * \param x A pointer to an SDL_Version struct to initialize.
+ * \param version the version number.
  *
  * \since This macro is available since SDL 3.0.0.
+ */
+#define SDL_VERSIONNUM_MAJOR(version) ((version) / 1000000)
+
+/**
+ * This macro extracts the minor version from a version number
  *
- * \sa SDL_Version
- * \sa SDL_GetVersion
+ * 1002003 becomes 2.
+ *
+ * \param version the version number.
+ *
+ * \since This macro is available since SDL 3.0.0.
  */
-#define SDL_VERSION(x)                \
-{                                     \
-    (x)->major = SDL_MAJOR_VERSION;   \
-    (x)->minor = SDL_MINOR_VERSION;   \
-    (x)->patch = SDL_PATCHLEVEL;      \
-}
+#define SDL_VERSIONNUM_MINOR(version) (((version) / 1000) % 1000)
 
 /**
- * This macro turns the version numbers into a numeric value.
+ * This macro extracts the micro version from a version number
  *
- * (1,2,3) becomes 0x1000203.
+ * 1002003 becomes 3.
  *
- * \param major the major version number.
- * \param minor the minorversion number.
- * \param patch the patch version number.
+ * \param version the version number.
  *
  * \since This macro is available since SDL 3.0.0.
  */
-#define SDL_VERSIONNUM(major, minor, patch) \
-    ((major) << 24 | (minor) << 8 | (patch) << 0)
+#define SDL_VERSIONNUM_MICRO(version) ((version) % 1000)
 
 /**
  * This is the version number macro for the current SDL version.
  *
  * \since This macro is available since SDL 3.0.0.
  */
-#define SDL_COMPILEDVERSION \
-    SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL)
+#define SDL_VERSION \
+    SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION)
 
 /**
  * This macro will evaluate to true if compiled with SDL at least X.Y.Z.
@@ -114,27 +98,25 @@ typedef struct SDL_Version
  * \since This macro is available since SDL 3.0.0.
  */
 #define SDL_VERSION_ATLEAST(X, Y, Z) \
-    (SDL_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z))
+    (SDL_VERSION >= SDL_VERSIONNUM(X, Y, Z))
 
 /**
  * Get the version of SDL that is linked against your program.
  *
  * If you are linking to SDL dynamically, then it is possible that the current
  * version will be different than the version you compiled against. This
- * function returns the current version, while SDL_VERSION() is a macro that
- * tells you what version you compiled with.
+ * function returns the current version, while SDL_VERSION is the version you
+ * compiled with.
  *
  * This function may be called safely at any time, even before SDL_Init().
  *
- * \param ver the SDL_Version structure that contains the version information
- * \returns 0 on success or a negative error code on failure; call
- *          SDL_GetError() for more information.
+ * \returns the version of the linked library.
  *
  * \since This function is available since SDL 3.0.0.
  *
  * \sa SDL_GetRevision
  */
-extern DECLSPEC int SDLCALL SDL_GetVersion(SDL_Version * ver);
+extern DECLSPEC int SDLCALL SDL_GetVersion(void);
 
 /**
  * Get the code revision of SDL that is linked against your program.
diff --git a/src/SDL.c b/src/SDL.c
index 9430043004ca4..6295fa6662efe 100644
--- a/src/SDL.c
+++ b/src/SDL.c
@@ -65,20 +65,16 @@ SDL_COMPILE_TIME_ASSERT(SDL_BUILD_MAJOR_VERSION,
 SDL_COMPILE_TIME_ASSERT(SDL_BUILD_MINOR_VERSION,
                         SDL_MINOR_VERSION == SDL_BUILD_MINOR_VERSION);
 SDL_COMPILE_TIME_ASSERT(SDL_BUILD_MICRO_VERSION,
-                        SDL_PATCHLEVEL == SDL_BUILD_MICRO_VERSION);
+                        SDL_MICRO_VERSION == SDL_BUILD_MICRO_VERSION);
 #endif
 
+/* Limited by its encoding in SDL_VERSIONNUM */
 SDL_COMPILE_TIME_ASSERT(SDL_MAJOR_VERSION_min, SDL_MAJOR_VERSION >= 0);
-/* Limited only by the need to fit in SDL_Version */
-SDL_COMPILE_TIME_ASSERT(SDL_MAJOR_VERSION_max, SDL_MAJOR_VERSION <= 255);
-
+SDL_COMPILE_TIME_ASSERT(SDL_MAJOR_VERSION_max, SDL_MAJOR_VERSION <= 10);
 SDL_COMPILE_TIME_ASSERT(SDL_MINOR_VERSION_min, SDL_MINOR_VERSION >= 0);
-/* Limited only by the need to fit in SDL_Version */
-SDL_COMPILE_TIME_ASSERT(SDL_MINOR_VERSION_max, SDL_MINOR_VERSION <= 255);
-
-SDL_COMPILE_TIME_ASSERT(SDL_PATCHLEVEL_min, SDL_PATCHLEVEL >= 0);
-/* Limited by its encoding in SDL_VERSIONNUM and in the ABI versions */
-SDL_COMPILE_TIME_ASSERT(SDL_PATCHLEVEL_max, SDL_PATCHLEVEL <= 99);
+SDL_COMPILE_TIME_ASSERT(SDL_MINOR_VERSION_max, SDL_MINOR_VERSION <= 999);
+SDL_COMPILE_TIME_ASSERT(SDL_MICRO_VERSION_min, SDL_MICRO_VERSION >= 0);
+SDL_COMPILE_TIME_ASSERT(SDL_MICRO_VERSION_max, SDL_MICRO_VERSION <= 999);
 
 /* This is not declared in any header, although it is sha

(Patch may be truncated, please check the link at the top of this post.)