From 2264ed9de667b7f02ee8dab35a12ce5e80af427f Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sat, 12 Aug 2023 22:35:52 +0200 Subject: [PATCH] Fix calculation of version number in the library mapfiles As reported by Andreas Metzler, the latest API change in lib WRaster caused a compatibility issue because the internal version number was increased. To correctly handle this situation, this patch does 2 things: - do not discard the 2 last number in the "c:r:a" version, because we need them; - when calculating the version for the mapfile, use the formula that is suggested in libtool's documentation. The purpose of the formula is that when API is changed, if a new function is added then the version is not incremented to reflect that we are still compatible with current binaries, it will be incremented only when there is a break in compatibility. --- script/generate-mapfile-from-header.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/script/generate-mapfile-from-header.sh b/script/generate-mapfile-from-header.sh index e643ca50..0b82a5bb 100755 --- a/script/generate-mapfile-from-header.sh +++ b/script/generate-mapfile-from-header.sh @@ -77,10 +77,8 @@ while [ $# -gt 0 ]; do -v) shift - # Version may be 'x:y:z', we keep only 'x' - version="`echo "$1" | sed -e 's,:.*$,,' `" - # the version should only be a number - echo "$version" | grep '^[1-9][0-9]*$' > /dev/null || \ + version="$1" + echo "$version" | grep -E '^[1-9][0-9]*(:[0-9]+(:[0-9]+)?)?$' > /dev/null || \ arg_error "version \"$1\" is not valid" ;; @@ -109,9 +107,18 @@ fi # generate the rest of the script so that other symbols will not be kept. awk ' BEGIN { + # Version number here uses only 1 number from the full version used in libtool + libversion="'"$version"'"; + if (split(libversion, subversions, ":") > 1) { + # Calculate [CURRENT - AGE], the goal is that the number will not + # change when functions are added to the API, but it will be incremented + # when functions are removed or argument change (which breaks compat) + libversion = subversions[1] - subversions[3]; + } + print "/* Generated version-script for ld */"; print ""; - print "'"$libname$version"'"; + print "'"$libname"'" libversion; print "{"; print " global:"; }