xref: /aosp_15_r20/external/iw/version.sh (revision 92022041c981f431db0b590d0c3272306d0ea2a2)
1#!/bin/sh
2
3VERSION="5.16"
4OUT="$1"
5
6# get the absolute path for the OUT file
7OUT_NAME=$(basename ${OUT})
8OUT_DIR=$(cd $(dirname ${OUT}); pwd)
9OUT="${OUT_DIR}/${OUT_NAME}"
10
11# the version check should be under the source directory
12# where this script is located, instead of the currect directory
13# where this script is excuted.
14SRC_DIR=$(dirname $0)
15SRC_DIR=$(cd ${SRC_DIR}; pwd)
16cd "${SRC_DIR}"
17
18v=""
19if [ -d .git ] && head=`git rev-parse --verify HEAD 2>/dev/null`; then
20    git update-index --refresh --unmerged > /dev/null
21    descr=$(git describe --match=v* 2>/dev/null)
22    if [ $? -eq 0 ]; then
23        # on git builds check that the version number above
24        # is correct...
25        if [ "${descr%%-*}" = "v$VERSION" ]; then
26            v="${descr#v}"
27            if git diff-index --name-only HEAD | read dummy ; then
28                v="$v"-dirty
29            fi
30        fi
31    fi
32fi
33
34# set to the default version when failed to get the version
35# information with git
36if [ -z "${v}" ]; then
37    v="$VERSION"
38fi
39
40echo '#include "iw.h"' > "$OUT"
41echo "const char iw_version[] = \"$v\";" >> "$OUT"
42