SDL_ttf: Fixed handling of DYLIB_COMPATIBILITY_VERSION (ca3dd)

From ca3dd0e77fbede82b95fdb7135214327bc3b6608 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 5 Sep 2022 18:41:30 -0700
Subject: [PATCH] Fixed handling of DYLIB_COMPATIBILITY_VERSION

Also make sure we test the version in configure
---
 CMakeLists.txt                          |  3 --
 Xcode/SDL_ttf.xcodeproj/project.pbxproj |  4 +--
 cmake/PrivateSdlFunctions.cmake         |  2 +-
 release_checklist.md                    | 26 ++++++-----------
 test-versioning.sh                      | 38 +++++++++++++++++--------
 5 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a05ce56..ccb55d7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,9 +8,6 @@ set(MINOR_VERSION 21)
 set(MICRO_VERSION 0)
 set(SDL_REQUIRED_VERSION 2.0.10)
 
-# For historical reasons this is 15.0.0 rather than the expected 1.0.0
-set(DYLIB_COMPATIBILITY_VERSION "15.0.0")
-
 include(PrivateSdlFunctions)
 sdl_calculate_derived_version_variables()
 
diff --git a/Xcode/SDL_ttf.xcodeproj/project.pbxproj b/Xcode/SDL_ttf.xcodeproj/project.pbxproj
index 11f354f..249fc12 100644
--- a/Xcode/SDL_ttf.xcodeproj/project.pbxproj
+++ b/Xcode/SDL_ttf.xcodeproj/project.pbxproj
@@ -984,7 +984,7 @@
 				CLANG_CXX_LANGUAGE_STANDARD = "c++0x";
 				CLANG_CXX_LIBRARY = "libc++";
 				COPY_PHASE_STRIP = NO;
-				DYLIB_COMPATIBILITY_VERSION = 15.0.0;
+				DYLIB_COMPATIBILITY_VERSION = 2101.0.0;
 				DYLIB_CURRENT_VERSION = 2101.0.0;
 				DYLIB_INSTALL_NAME_BASE = "@rpath";
 				ENABLE_TESTABILITY = YES;
@@ -1024,7 +1024,7 @@
 				CLANG_CXX_LANGUAGE_STANDARD = "c++0x";
 				CLANG_CXX_LIBRARY = "libc++";
 				DEPLOYMENT_POSTPROCESSING = YES;
-				DYLIB_COMPATIBILITY_VERSION = 15.0.0;
+				DYLIB_COMPATIBILITY_VERSION = 2101.0.0;
 				DYLIB_CURRENT_VERSION = 2101.0.0;
 				DYLIB_INSTALL_NAME_BASE = "@rpath";
 				FRAMEWORK_SEARCH_PATHS = "\"$(SRCROOT)/$(PLATFORM)\"";
diff --git a/cmake/PrivateSdlFunctions.cmake b/cmake/PrivateSdlFunctions.cmake
index 398770b..bf6ff0a 100644
--- a/cmake/PrivateSdlFunctions.cmake
+++ b/cmake/PrivateSdlFunctions.cmake
@@ -39,8 +39,8 @@ macro(sdl_calculate_derived_version_variables)
     # which are normally 0-based.
     math(EXPR DYLIB_CURRENT_VERSION_MAJOR "${LT_MAJOR} + ${LT_AGE} + 1")
     math(EXPR DYLIB_CURRENT_VERSION_MINOR "${LT_REVISION}")
-    math(EXPR DYLIB_COMPAT_VERSION_MAJOR "${LT_MAJOR} + 1")
     set(DYLIB_CURRENT_VERSION "${DYLIB_CURRENT_VERSION_MAJOR}.${DYLIB_CURRENT_VERSION_MINOR}.0")
+    set(DYLIB_COMPATIBILITY_VERSION "${DYLIB_CURRENT_VERSION_MAJOR}.0.0")
 endmacro()
 
 macro(sdl_find_sdl2 TARGET VERSION)
diff --git a/release_checklist.md b/release_checklist.md
index f5a272f..0c0f29c 100644
--- a/release_checklist.md
+++ b/release_checklist.md
@@ -28,16 +28,12 @@
         * set first number in `DYLIB_CURRENT_VERSION` to
             (100 * *minor*) + 1
         * set second number in `DYLIB_CURRENT_VERSION` to 0
-        * if backwards compatibility has been broken,
-            increase `DYLIB_COMPATIBILITY_VERSION` (?)
-    * `CMakeLists.txt`:
-		* if backwards compatibility has been broken,
-		  increase `DYLIB_COMPATIBILITY_VERSION` (?)
-
-* Run `./test-versioning.sh` to verify that everything is consistent
+        * set `DYLIB_COMPATIBILITY_VERSION` to the same value
 
 * Regenerate `configure`
 
+* Run `./test-versioning.sh` to verify that everything is consistent
+
 * Do the release
 
 ## New bugfix release
@@ -55,11 +51,12 @@
 	* `Xcode/SDL_ttf.xcodeproj/project.pbxproj`:
 	  `DYLIB_CURRENT_VERSION`, `DYLIB_COMPATIBILITY_VERSION`
 		* set second number in `DYLIB_CURRENT_VERSION` to *patchlevel*
-
-* Run test/versioning.sh to verify that everything is consistent
+        * Leave `DYLIB_COMPATIBILITY_VERSION` unchanged
 
 * Regenerate `configure`
 
+* Run test/versioning.sh to verify that everything is consistent
+
 * Do the release
 
 ## After a feature release
@@ -92,15 +89,10 @@
 		* set first number in `DYLIB_CURRENT_VERSION` to
 		  (100 * *minor*) + *patchlevel* + 1
 		* set second number in `DYLIB_CURRENT_VERSION` to 0
-		* if backwards compatibility has been broken,
-		  increase `DYLIB_COMPATIBILITY_VERSION` (?)
-	* `CMakeLists.txt`:
-	  `DYLIB_COMPATIBILITY_VERSION`
-		* if backwards compatibility has been broken,
-		  increase `DYLIB_COMPATIBILITY_VERSION` (?)
-
-* Run test/versioning.sh to verify that everything is consistent
+        * set `DYLIB_COMPATIBILITY_VERSION` to the same value
 
 * Regenerate `configure`
 
+* Run test/versioning.sh to verify that everything is consistent
+
 * Do the release
diff --git a/test-versioning.sh b/test-versioning.sh
index ffb9b3a..11e73bf 100755
--- a/test-versioning.sh
+++ b/test-versioning.sh
@@ -38,6 +38,17 @@ else
     not_ok "configure.ac $version disagrees with SDL_ttf.h $ref_version"
 fi
 
+major=$(sed -ne 's/^MAJOR_VERSION=//p' configure)
+minor=$(sed -ne 's/^MINOR_VERSION=//p' configure)
+micro=$(sed -ne 's/^MICRO_VERSION=//p' configure)
+version="${major}.${minor}.${micro}"
+
+if [ "$ref_version" = "$version" ]; then
+    ok "configure $version"
+else
+    not_ok "configure $version disagrees with SDL_ttf.h $ref_version"
+fi
+
 major=$(sed -ne 's/^set(MAJOR_VERSION \([0-9]*\))$/\1/p' CMakeLists.txt)
 minor=$(sed -ne 's/^set(MINOR_VERSION \([0-9]*\))$/\1/p' CMakeLists.txt)
 micro=$(sed -ne 's/^set(MICRO_VERSION \([0-9]*\))$/\1/p' CMakeLists.txt)
@@ -121,22 +132,25 @@ fi
 
 # For simplicity this assumes we'll never break ABI before SDL 3.
 dylib_compat=$(sed -Ene 's/.*DYLIB_COMPATIBILITY_VERSION = (.*);$/\1/p' Xcode/SDL_ttf.xcodeproj/project.pbxproj)
-ref='15.0.0
-15.0.0'
 
-if [ "$ref" = "$dylib_compat" ]; then
-    ok "project.pbxproj DYLIB_COMPATIBILITY_VERSION is consistent"
-else
-    not_ok "project.pbxproj DYLIB_COMPATIBILITY_VERSION is inconsistent"
-fi
+case "$ref_minor" in
+    (*[02468])
+        major="$(( ref_minor * 100 + 1 ))"
+        minor="0"
+        ;;
+    (*)
+        major="$(( ref_minor * 100 + ref_micro + 1 ))"
+        minor="0"
+        ;;
+esac
 
-dylib_compat=$(sed -ne 's/^set(DYLIB_COMPATIBILITY_VERSION "\([0-9.]*\)")$/\1/p' CMakeLists.txt)
-ref='15.0.0'
+ref="${major}.${minor}.0
+${major}.${minor}.0"
 
 if [ "$ref" = "$dylib_compat" ]; then
-    ok "CMakeLists.txt DYLIB_COMPATIBILITY_VERSION is consistent"
+    ok "project.pbxproj DYLIB_COMPATIBILITY_VERSION is consistent"
 else
-    not_ok "CMakeLists.txt DYLIB_COMPATIBILITY_VERSION is inconsistent"
+    not_ok "project.pbxproj DYLIB_COMPATIBILITY_VERSION is inconsistent, expected $ref, got $dylib_compat"
 fi
 
 dylib_cur=$(sed -Ene 's/.*DYLIB_CURRENT_VERSION = (.*);$/\1/p' Xcode/SDL_ttf.xcodeproj/project.pbxproj)
@@ -158,7 +172,7 @@ ${major}.${minor}.0"
 if [ "$ref" = "$dylib_cur" ]; then
     ok "project.pbxproj DYLIB_CURRENT_VERSION is consistent"
 else
-    not_ok "project.pbxproj DYLIB_CURRENT_VERSION is inconsistent, expected $ref"
+    not_ok "project.pbxproj DYLIB_CURRENT_VERSION is inconsistent, expected $ref, got $dylib_cur"
 fi
 
 sdl_req=$(sed -ne 's/\$sdl2_version = "\([0-9.]*\)"$/\1/p' .github/fetch_sdl_vc.ps1)