Rework code for libtool versioning
[libjaylink.git] / m4 / jaylink.m4
blob7395421ed4e4a66179b9a631edfa340068edd738
1 ##
2 ## This file is part of the libjaylink project.
3 ##
4 ## Copyright (C) 2016 Marc Schink <jaylink-dev@marcschink.de>
5 ##
6 ## This program is free software: you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation, either version 2 of the License, or
9 ## (at your option) any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 # serial 20161011
22 ## _JAYLINK_SET_PACKAGE_VERSION(prefix, version, major, minor, micro)
24 m4_define([_JAYLINK_SET_PACKAGE_VERSION], [
25         m4_assert([$# == 5])
27         # Get the short Git revision hash of the current commit.
28         git_version=`git rev-parse --short HEAD 2> /dev/null`
30         # Try to get the release tag for the package version from the current
31         # commit.
32         tag=`git describe --match "$2" --exact-match 2> /dev/null`
34         version=$2
36         # If Git is available, append the short Git revision hash of the
37         # current commit to the version string if there is no release tag for
38         # the package version on it.
39         AS_IF([test -n "$git_version" && test -z "$tag"],
40                 [version="$version-git-$git_version"])
42         AC_SUBST([$1_MAJOR], [$3])
43         AC_SUBST([$1_MINOR], [$4])
44         AC_SUBST([$1_MICRO], [$5])
45         AC_SUBST([$1], [$version])
48 ## JAYLINK_SET_PACKAGE_VERSION(prefix, version)
50 ## Parse the package version string of the format <major>.<minor>.<micro> and
51 ## set the variables <prefix>_{MAJOR,MINOR,MICRO} to their corresponding
52 ## values.
54 ## Set the variable <prefix> to the package version string. If Git is
55 ## available, append the short Git revision hash of the current commit to the
56 ## version string if there is no release tag for the package version on it.
58 AC_DEFUN([JAYLINK_SET_PACKAGE_VERSION], [
59         m4_assert([$# == 2])
61         _JAYLINK_SET_PACKAGE_VERSION([$1], [$2],
62                 m4_unquote(m4_split(m4_expand([$2]), [\.])))
65 ## _JAYLINK_SET_LIBRARY_VERSION(prefix, version, current, revision, age)
67 m4_define([_JAYLINK_SET_LIBRARY_VERSION], [
68         m4_assert([$# == 5])
70         AC_SUBST([$1_CURRENT], [$3])
71         AC_SUBST([$1_REVISION], [$4])
72         AC_SUBST([$1_AGE], [$5])
73         AC_SUBST([$1], [$2])
76 ## JAYLINK_SET_LIBRARY_VERSION(prefix, version)
78 ## Parse the library version string of the format <current>:<revision>:<age>
79 ## and set the variables <prefix>_{CURRENT,REVISION,AGE} to their corresponding
80 ## values.
82 ## Set the variable <prefix> to the library version string.
84 AC_DEFUN([JAYLINK_SET_LIBRARY_VERSION], [
85         m4_assert([$# == 2])
87         _JAYLINK_SET_LIBRARY_VERSION([$1], [$2],
88                 m4_unquote(m4_split([$2], [:])))