File: version.sh

package info (click to toggle)
crust-firmware 0.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,900 kB
  • sloc: ansic: 19,341; yacc: 596; lex: 479; makefile: 334; asm: 215; sh: 136; python: 42
file content (40 lines) | stat: -rwxr-xr-x 839 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh -eu
#
# Copyright © 2020-2022 The Crust Firmware Authors.
# SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only
#

major=0
minor=6
patch=10000

srcdir=$1
output=$2

if test "$srcdir" = "$(git -C "$srcdir" rev-parse --show-toplevel 2>/dev/null)"; then
  set -- $(git -C "$srcdir" describe --dirty --long --match 'v[0-9]*' | tr '.-' '  ')

  if test "$#" -ge 4; then
    major=${1#v}
    minor=$2
    patch=$3
  fi

  if test "$#" -ge 5 && test "$5" = "dirty"; then
    patch=$((patch+10000))
  fi
fi

trap 'rm -f "$output.tmp"' EXIT

cat > "$output.tmp" << EOF
#define VERSION_MAJOR $major
#define VERSION_MINOR $minor
#define VERSION_PATCH $patch
#define VERSION_STRING "v${major}.${minor}.${patch}"
EOF

if ! test -f "$output" ||
   ! test "$(cat "$output.tmp")" = "$(cat "$output")"; then
  mv -f "$output.tmp" "$output"
fi