Simon Glass | d7faa08 | 2021-09-22 11:34:43 -0600 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: GPL-2.0+ |
| 3 | # |
| 4 | # dtc-version dtc-command |
| 5 | # |
| 6 | # Prints the dtc version of `dtc-command' in a canonical 6-digit form |
| 7 | # such as `010404' for dtc 1.4.4 |
| 8 | # |
| 9 | |
| 10 | dtc="$*" |
| 11 | |
| 12 | if [ ${#dtc} -eq 0 ]; then |
Simon Glass | 93b1965 | 2021-09-22 11:34:44 -0600 | [diff] [blame] | 13 | echo "Error: No dtc command specified" |
Simon Glass | d7faa08 | 2021-09-22 11:34:43 -0600 | [diff] [blame] | 14 | printf "Usage:\n\t$0 <dtc-command>\n" |
| 15 | exit 1 |
| 16 | fi |
| 17 | |
Simon Glass | 93b1965 | 2021-09-22 11:34:44 -0600 | [diff] [blame] | 18 | if ! which $dtc >/dev/null ; then |
| 19 | echo "Error: Cannot find dtc: $dtc" |
| 20 | exit 1 |
| 21 | fi |
| 22 | |
Martin Hundebøll | f073815 | 2023-05-03 12:23:39 +0200 | [diff] [blame] | 23 | MAJOR=$($dtc -v | head -1 | awk '{print $NF}' | cut -d . -f 1 | tr -d v) |
Simon Glass | d7faa08 | 2021-09-22 11:34:43 -0600 | [diff] [blame] | 24 | MINOR=$($dtc -v | head -1 | awk '{print $NF}' | cut -d . -f 2) |
| 25 | PATCH=$($dtc -v | head -1 | awk '{print $NF}' | cut -d . -f 3 | cut -d - -f 1) |
| 26 | |
| 27 | printf "%02d%02d%02d\\n" $MAJOR $MINOR $PATCH |