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