xref: /aosp_15_r20/external/libopus/update_version (revision a58d3d2adb790c104798cd88c8a3aff4fa8b82cc)
1*a58d3d2aSXin Li#!/bin/bash
2*a58d3d2aSXin Li
3*a58d3d2aSXin Li# Creates and updates the package_version information used by configure.ac
4*a58d3d2aSXin Li# (or other makefiles).  When run inside a git repository it will use the
5*a58d3d2aSXin Li# version information that can be queried from it unless AUTO_UPDATE is set
6*a58d3d2aSXin Li# to 'no'.  If no version is currently known it will be set to 'unknown'.
7*a58d3d2aSXin Li#
8*a58d3d2aSXin Li# If called with the argument 'release', the PACKAGE_VERSION will be updated
9*a58d3d2aSXin Li# even if AUTO_UPDATE=no, but the value of AUTO_UPDATE shall be preserved.
10*a58d3d2aSXin Li# This is used to force a version update whenever `make dist` is run.
11*a58d3d2aSXin Li#
12*a58d3d2aSXin Li# The exit status is 1 if package_version is not modified, else 0 is returned.
13*a58d3d2aSXin Li#
14*a58d3d2aSXin Li# This script should NOT be included in distributed tarballs, because if a
15*a58d3d2aSXin Li# parent directory contains a git repository we do not want to accidentally
16*a58d3d2aSXin Li# retrieve the version information from it instead.  Tarballs should ship
17*a58d3d2aSXin Li# with only the package_version file.
18*a58d3d2aSXin Li#
19*a58d3d2aSXin Li# Ron <[email protected]>, 2012.
20*a58d3d2aSXin Li
21*a58d3d2aSXin LiSRCDIR=$(dirname $0)
22*a58d3d2aSXin Li
23*a58d3d2aSXin Liif [ -e "$SRCDIR/package_version" ]; then
24*a58d3d2aSXin Li    . "$SRCDIR/package_version"
25*a58d3d2aSXin Lifi
26*a58d3d2aSXin Li
27*a58d3d2aSXin Liif [ "$AUTO_UPDATE" = no ]; then
28*a58d3d2aSXin Li    [ "$1" = release ] || exit 1
29*a58d3d2aSXin Lielse
30*a58d3d2aSXin Li    AUTO_UPDATE=yes
31*a58d3d2aSXin Lifi
32*a58d3d2aSXin Li
33*a58d3d2aSXin Li# We run `git status` before describe here to ensure that we don't get a false
34*a58d3d2aSXin Li# -dirty from files that have been touched but are not actually altered in the
35*a58d3d2aSXin Li# working dir.
36*a58d3d2aSXin LiGIT_VERSION=$(cd "$SRCDIR" && git status > /dev/null 2>&1 \
37*a58d3d2aSXin Li                           && git describe --tags --match 'v*' --dirty 2> /dev/null)
38*a58d3d2aSXin LiGIT_VERSION=${GIT_VERSION#v}
39*a58d3d2aSXin Li
40*a58d3d2aSXin Liif [ -n "$GIT_VERSION" ]; then
41*a58d3d2aSXin Li
42*a58d3d2aSXin Li    [ "$GIT_VERSION" != "$PACKAGE_VERSION" ] || exit 1
43*a58d3d2aSXin Li    PACKAGE_VERSION="$GIT_VERSION"
44*a58d3d2aSXin Li
45*a58d3d2aSXin Lielif [ -z "$PACKAGE_VERSION" ]; then
46*a58d3d2aSXin Li    # No current package_version and no git ...
47*a58d3d2aSXin Li    # We really shouldn't ever get here, because this script should only be
48*a58d3d2aSXin Li    # included in the git repository, and should usually be export-ignored.
49*a58d3d2aSXin Li    PACKAGE_VERSION="unknown"
50*a58d3d2aSXin Lielse
51*a58d3d2aSXin Li    exit 1
52*a58d3d2aSXin Lifi
53*a58d3d2aSXin Li
54*a58d3d2aSXin Licat > "$SRCDIR/package_version" <<-EOF
55*a58d3d2aSXin Li	# Automatically generated by update_version.
56*a58d3d2aSXin Li	# This file may be sourced into a shell script or makefile.
57*a58d3d2aSXin Li
58*a58d3d2aSXin Li	# Set this to 'no' if you do not wish the version information
59*a58d3d2aSXin Li	# to be checked and updated for every build.  Most people will
60*a58d3d2aSXin Li	# never want to change this, it is an option for developers
61*a58d3d2aSXin Li	# making frequent changes that they know will not be released.
62*a58d3d2aSXin Li	AUTO_UPDATE=$AUTO_UPDATE
63*a58d3d2aSXin Li
64*a58d3d2aSXin Li	PACKAGE_VERSION="$PACKAGE_VERSION"
65*a58d3d2aSXin LiEOF
66