18c2ecf20Sopenharmony_ci#!/bin/sh
28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
38c2ecf20Sopenharmony_ci#
48c2ecf20Sopenharmony_ci# Usage: $ ./scripts/lld-version.sh ld.lld
58c2ecf20Sopenharmony_ci#
68c2ecf20Sopenharmony_ci# Print the linker version of `ld.lld' in a 5 or 6-digit form
78c2ecf20Sopenharmony_ci# such as `100001' for ld.lld 10.0.1 etc.
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ciset -e
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci# Convert the version string x.y.z to a canonical 5 or 6-digit form.
128c2ecf20Sopenharmony_ciget_canonical_version()
138c2ecf20Sopenharmony_ci{
148c2ecf20Sopenharmony_ci	IFS=.
158c2ecf20Sopenharmony_ci	set -- $1
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci	# If the 2nd or 3rd field is missing, fill it with a zero.
188c2ecf20Sopenharmony_ci	echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0}))
198c2ecf20Sopenharmony_ci}
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci# Get the first line of the --version output.
228c2ecf20Sopenharmony_ciIFS='
238c2ecf20Sopenharmony_ci'
248c2ecf20Sopenharmony_ciset -- $(LC_ALL=C "$@" --version)
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci# Split the line on spaces.
278c2ecf20Sopenharmony_ciIFS=' '
288c2ecf20Sopenharmony_ciset -- $1
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ciwhile [ $# -gt 1 -a "$1" != "LLD" ]; do
318c2ecf20Sopenharmony_ci	shift
328c2ecf20Sopenharmony_cidone
338c2ecf20Sopenharmony_ciif [ "$1" = LLD ]; then
348c2ecf20Sopenharmony_ci	echo $(get_canonical_version ${2%-*})
358c2ecf20Sopenharmony_cielse
368c2ecf20Sopenharmony_ci	echo 0
378c2ecf20Sopenharmony_cifi
38