xref: /OK3568_Linux_fs/kernel/scripts/lld-version.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#!/bin/sh
2*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0
3*4882a593Smuzhiyun#
4*4882a593Smuzhiyun# Usage: $ ./scripts/lld-version.sh ld.lld
5*4882a593Smuzhiyun#
6*4882a593Smuzhiyun# Print the linker version of `ld.lld' in a 5 or 6-digit form
7*4882a593Smuzhiyun# such as `100001' for ld.lld 10.0.1 etc.
8*4882a593Smuzhiyun
9*4882a593Smuzhiyunset -e
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun# Convert the version string x.y.z to a canonical 5 or 6-digit form.
12*4882a593Smuzhiyunget_canonical_version()
13*4882a593Smuzhiyun{
14*4882a593Smuzhiyun	IFS=.
15*4882a593Smuzhiyun	set -- $1
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun	# If the 2nd or 3rd field is missing, fill it with a zero.
18*4882a593Smuzhiyun	echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0}))
19*4882a593Smuzhiyun}
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun# Get the first line of the --version output.
22*4882a593SmuzhiyunIFS='
23*4882a593Smuzhiyun'
24*4882a593Smuzhiyunset -- $(LC_ALL=C "$@" --version)
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun# Split the line on spaces.
27*4882a593SmuzhiyunIFS=' '
28*4882a593Smuzhiyunset -- $1
29*4882a593Smuzhiyun
30*4882a593Smuzhiyunwhile [ $# -gt 1 -a "$1" != "LLD" ]; do
31*4882a593Smuzhiyun	shift
32*4882a593Smuzhiyundone
33*4882a593Smuzhiyunif [ "$1" = LLD ]; then
34*4882a593Smuzhiyun	echo $(get_canonical_version ${2%-*})
35*4882a593Smuzhiyunelse
36*4882a593Smuzhiyun	echo 0
37*4882a593Smuzhiyunfi
38