SDL: Moved the SDL version back to SDL_version.h

From fbe7e2e6d3b6f808009c486af69da68d6053bb22 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 15 May 2024 14:22:41 -0700
Subject: [PATCH] Moved the SDL version back to SDL_version.h

Added a comment at the top of SDL.h with the current version, for informational purposes
---
 .wikiheaders-options                          |  2 +-
 .../cmake/sdl3-config-version.cmake           |  8 ++---
 .../resources/CMake/sdl3-config-version.cmake |  4 +--
 build-scripts/android-prefab.sh               |  6 ++--
 build-scripts/build-release.py                |  2 +-
 build-scripts/rename_api.py                   |  2 +-
 build-scripts/showrev.sh                      |  6 ++--
 build-scripts/test-versioning.sh              | 32 ++++++++++++-------
 build-scripts/update-version.sh               |  8 +++--
 build-scripts/wikiheaders.pl                  |  2 +-
 include/SDL3/SDL.h                            | 10 +-----
 include/SDL3/SDL_version.h                    |  7 ++++
 12 files changed, 49 insertions(+), 40 deletions(-)

diff --git a/.wikiheaders-options b/.wikiheaders-options
index aefa8b714e7e4..2f74ee75044d7 100644
--- a/.wikiheaders-options
+++ b/.wikiheaders-options
@@ -5,7 +5,7 @@ wikisubdir =
 readmesubdir = docs
 apiprefixregex = (SDL_|SDLK_)
 mainincludefname = SDL3/SDL.h
-versionfname = include/SDL3/SDL.h
+versionfname = include/SDL3/SDL_version.h
 versionmajorregex = \A\#define\s+SDL_MAJOR_VERSION\s+(\d+)\Z
 versionminorregex = \A\#define\s+SDL_MINOR_VERSION\s+(\d+)\Z
 versionmicroregex = \A\#define\s+SDL_MICRO_VERSION\s+(\d+)\Z
diff --git a/VisualC/pkg-support/cmake/sdl3-config-version.cmake b/VisualC/pkg-support/cmake/sdl3-config-version.cmake
index 2f522c64aac6d..fc0d826b17021 100644
--- a/VisualC/pkg-support/cmake/sdl3-config-version.cmake
+++ b/VisualC/pkg-support/cmake/sdl3-config-version.cmake
@@ -3,12 +3,12 @@
 # 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.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")
+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")
     return()
 endif()
 
-file(READ "${CMAKE_CURRENT_LIST_DIR}/../include/SDL3/SDL.h" _sdl_version_h)
+file(READ "${CMAKE_CURRENT_LIST_DIR}/../include/SDL3/SDL_version.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}")
@@ -18,7 +18,7 @@ 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.h.")
+    message(AUTHOR_WARNING "Could not extract version from SDL3/SDL_version.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 be9696cf57ef0..6c833a7f2ab06 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.h")                                         # /SDL3.xcframework/macos-arm64_x86_64/SDL3.framework/Headers/SDL.h
+set(_sdl3_version_h "${_sdl3_framework}/Headers/SDL_version.h")                                         # /SDL3.xcframework/macos-arm64_x86_64/SDL3.framework/Headers/SDL_version.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")
@@ -35,7 +35,7 @@ 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.h.")
+    message(AUTHOR_WARNING "Could not extract version from SDL_version.h.")
     return()
 endif()
 
diff --git a/build-scripts/android-prefab.sh b/build-scripts/android-prefab.sh
index 41592ee5c32ee..2cbdaa81cbb5d 100755
--- a/build-scripts/android-prefab.sh
+++ b/build-scripts/android-prefab.sh
@@ -40,9 +40,9 @@ 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.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_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_micro=$(sed -ne 's/^#define SDL_MICRO_VERSION  *//p' "${sdl_root}/include/SDL3/SDL_version.h")
 sdl_version="${sdl_major}.${sdl_minor}.${sdl_micro}"
 echo "Building Android prefab package for SDL version $sdl_version"
 
diff --git a/build-scripts/build-release.py b/build-scripts/build-release.py
index ef01768eb50a0..cc1c6147119f4 100755
--- a/build-scripts/build-release.py
+++ b/build-scripts/build-release.py
@@ -509,7 +509,7 @@ 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.h", "r") as f:
+        with open(root / f"include/{project}/SDL_version.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)
diff --git a/build-scripts/rename_api.py b/build-scripts/rename_api.py
index b1f6c183fe48b..7c02b9e945869 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.h" ).read_text()
+    version_header = pathlib.Path( SDL_INCLUDE_DIR / "SDL_version.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 eba61d5d3cde4..764d3a431571c 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.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)
+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_MICRO_VERSION  *//p' include/SDL3/SDL_version.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 13ae091314e54..55e29a3016345 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.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_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_MICRO_VERSION  *//p' include/SDL3/SDL_version.h)
 ref_version="${ref_major}.${ref_minor}.${ref_micro}"
 
 tests=0
@@ -25,12 +25,20 @@ not_ok () {
     failed=1
 }
 
+version=$(sed -Ene 's/^.* version ([0-9.]*)$/\1/p' include/SDL3/SDL.h)
+
+if [ "$ref_version" = "$version" ]; then
+    ok "SDL.h $version"
+else
+    not_ok "SDL.h $version disagrees with SDL_version.h $ref_version"
+fi
+
 version=$(sed -Ene 's/^project\(SDL[0-9]+ LANGUAGES C VERSION "([0-9.]*)"\)$/\1/p' CMakeLists.txt)
 
 if [ "$ref_version" = "$version" ]; then
     ok "CMakeLists.txt $version"
 else
-    not_ok "CMakeLists.txt $version disagrees with SDL.h $ref_version"
+    not_ok "CMakeLists.txt $version disagrees with SDL_version.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 +49,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.h $ref_version"
+    not_ok "android-project/app/src/main/java/org/libsdl/app/SDLActivity.java $version disagrees with SDL_version.h $ref_version"
 fi
 
 tuple=$(sed -ne 's/^ *FILEVERSION *//p' src/core/windows/version.rc | tr -d '\r')
@@ -50,7 +58,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.h $ref_tuple"
+    not_ok "version.rc FILEVERSION $tuple disagrees with SDL_version.h $ref_tuple"
 fi
 
 tuple=$(sed -ne 's/^ *PRODUCTVERSION *//p' src/core/windows/version.rc | tr -d '\r')
@@ -58,7 +66,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.h $ref_tuple"
+    not_ok "version.rc PRODUCTVERSION $tuple disagrees with SDL_version.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 +75,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.h $ref_tuple"
+    not_ok "version.rc FileVersion $tuple disagrees with SDL_version.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 +83,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.h $ref_tuple"
+    not_ok "version.rc ProductVersion $tuple disagrees with SDL_version.h $ref_tuple"
 fi
 
 version=$(sed -Ene '/CFBundleShortVersionString/,+1 s/.*<string>(.*)<\/string>.*/\1/p' Xcode/SDL/Info-Framework.plist)
@@ -83,7 +91,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.h $ref_version"
+    not_ok "Info-Framework.plist CFBundleShortVersionString $version disagrees with SDL_version.h $ref_version"
 fi
 
 version=$(sed -Ene '/CFBundleVersion/,+1 s/.*<string>(.*)<\/string>.*/\1/p' Xcode/SDL/Info-Framework.plist)
@@ -91,7 +99,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.h $ref_version"
+    not_ok "Info-Framework.plist CFBundleVersion $version disagrees with SDL_version.h $ref_version"
 fi
 
 version=$(sed -Ene 's/Title SDL (.*)/\1/p' Xcode/SDL/pkg-support/SDL.info)
@@ -99,7 +107,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.h $ref_version"
+    not_ok "SDL.info Title $version disagrees with SDL_version.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 0f65dcb699f0a..86ae8163498db 100755
--- a/build-scripts/update-version.sh
+++ b/build-scripts/update-version.sh
@@ -27,6 +27,8 @@ NEWVERSION="$MAJOR.$MINOR.$MICRO"
 
 echo "Updating version to '$NEWVERSION' ..."
 
+perl -w -pi -e 's/\A(.* version )[0-9.]+/${1}'$NEWVERSION'/;' include/SDL3/SDL.h
+
 # !!! FIXME: This first one is a kinda scary search/replace that might fail later if another X.Y.Z version is added to the file.
 perl -w -pi -e 's/(\<string\>)\d+\.\d+\.\d+/${1}'$NEWVERSION'/;' Xcode/SDL/Info-Framework.plist
 
@@ -60,9 +62,9 @@ perl -w -pi -e 's/\A(.* SDL_MAJOR_VERSION = )\d+/${1}'$MAJOR'/;' android-project
 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}'$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.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/(\#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_MICRO_VERSION\s+)\d+/${1}'$MICRO'/;' include/SDL3/SDL_version.h
 
 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
diff --git a/build-scripts/wikiheaders.pl b/build-scripts/wikiheaders.pl
index e7a423cd74e33..6e4219702fb52 100755
--- a/build-scripts/wikiheaders.pl
+++ b/build-scripts/wikiheaders.pl
@@ -13,7 +13,7 @@
 my $incsubdir = 'include';
 my $readmesubdir = undef;
 my $apiprefixregex = undef;
-my $versionfname = 'include/SDL.h';
+my $versionfname = 'include/SDL_version.h';
 my $versionmajorregex = '\A\#define\s+SDL_MAJOR_VERSION\s+(\d+)\Z';
 my $versionminorregex = '\A\#define\s+SDL_MINOR_VERSION\s+(\d+)\Z';
 my $versionmicroregex = '\A\#define\s+SDL_MICRO_VERSION\s+(\d+)\Z';
diff --git a/include/SDL3/SDL.h b/include/SDL3/SDL.h
index c42efc241ac59..4e18f638224be 100644
--- a/include/SDL3/SDL.h
+++ b/include/SDL3/SDL.h
@@ -22,20 +22,12 @@
 /**
  *  \file SDL.h
  *
- *  Main include header for the SDL library
+ *  Main include header for the SDL library, version 3.1.2
  */
 
 #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_version.h b/include/SDL3/SDL_version.h
index 6cfcc3318a139..f9d67f8949eee 100644
--- a/include/SDL3/SDL_version.h
+++ b/include/SDL3/SDL_version.h
@@ -37,6 +37,13 @@
 extern "C" {
 #endif
 
+/**
+ * The current version of SDL
+ */
+#define SDL_MAJOR_VERSION   3
+#define SDL_MINOR_VERSION   1
+#define SDL_MICRO_VERSION   2
+
 /**
  * This macro turns the version numbers into a numeric value.
  *