1#! /usr/bin/env sh
2
3# output_env.sh
4#
5# Copyright The Mbed TLS Contributors
6# SPDX-License-Identifier: Apache-2.0
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19#
20# Purpose
21#
22# To print out all the relevant information about the development environment.
23#
24# This includes:
25#   - architecture of the system
26#   - type and version of the operating system
27#   - version of make and cmake
28#   - version of armcc, clang, gcc-arm and gcc compilers
29#   - version of libc, clang, asan and valgrind if installed
30#   - version of gnuTLS and OpenSSL
31
32print_version()
33{
34    BIN="$1"
35    shift
36    ARGS="$1"
37    shift
38    VARIANT="$1"
39    shift
40
41    if [ -n "$VARIANT" ]; then
42        VARIANT=" ($VARIANT)"
43    fi
44
45    if ! type "$BIN" > /dev/null 2>&1; then
46        echo " * ${BIN##*/}$VARIANT: Not found."
47        return 0
48    fi
49
50    BIN=`which "$BIN"`
51    VERSION_STR=`$BIN $ARGS 2>&1`
52
53    # Apply all filters
54    while [ $# -gt 0 ]; do
55        FILTER="$1"
56        shift
57        VERSION_STR=`echo "$VERSION_STR" | $FILTER`
58    done
59
60    if [ -z "$VERSION_STR" ]; then
61        VERSION_STR="Version could not be determined."
62    fi
63
64    echo " * ${BIN##*/}$VARIANT: ${BIN} : ${VERSION_STR} "
65}
66
67echo "** Platform:"
68echo
69
70if [ `uname -s` = "Linux" ]; then
71    echo "Linux variant"
72    lsb_release -d -c
73else
74    echo "Unknown Unix variant"
75fi
76
77echo
78
79print_version "uname" "-a" ""
80
81echo
82echo
83echo "** Tool Versions:"
84echo
85
86print_version "make" "--version" "" "head -n 1"
87echo
88
89print_version "cmake" "--version" "" "head -n 1"
90echo
91
92if [ "${RUN_ARMCC:-1}" -ne 0 ]; then
93    : "${ARMC5_CC:=armcc}"
94    print_version "$ARMC5_CC" "--vsn" "" "head -n 2"
95    echo
96
97    : "${ARMC6_CC:=armclang}"
98    print_version "$ARMC6_CC" "--vsn" "" "head -n 2"
99    echo
100fi
101
102print_version "arm-none-eabi-gcc" "--version" "" "head -n 1"
103echo
104
105print_version "gcc" "--version" "" "head -n 1"
106echo
107
108print_version "clang" "--version" "" "head -n 2"
109echo
110
111print_version "ldd" "--version" "" "head -n 1"
112echo
113
114print_version "valgrind" "--version" ""
115echo
116
117print_version "gdb" "--version" "" "head -n 1"
118echo
119
120print_version "perl" "--version" "" "head -n 2" "grep ."
121echo
122
123print_version "python" "--version" "" "head -n 1"
124echo
125
126print_version "python3" "--version" "" "head -n 1"
127echo
128
129# Find the installed version of Pylint. Installed as a distro package this can
130# be pylint3 and as a PEP egg, pylint. In test scripts We prefer pylint over
131# pylint3
132if type pylint >/dev/null 2>/dev/null; then
133    print_version "pylint" "--version" "" "sed /^.*config/d" "grep pylint"
134elif type pylint3 >/dev/null 2>/dev/null; then
135    print_version "pylint3" "--version" "" "sed /^.*config/d" "grep pylint"
136else
137    echo " * pylint or pylint3: Not found."
138fi
139echo
140
141: ${OPENSSL:=openssl}
142print_version "$OPENSSL" "version" "default"
143echo
144
145if [ -n "${OPENSSL_LEGACY+set}" ]; then
146    print_version "$OPENSSL_LEGACY" "version" "legacy"
147else
148    echo " * openssl (legacy): Not configured."
149fi
150echo
151
152if [ -n "${OPENSSL_NEXT+set}" ]; then
153    print_version "$OPENSSL_NEXT" "version" "next"
154else
155    echo " * openssl (next): Not configured."
156fi
157echo
158
159: ${GNUTLS_CLI:=gnutls-cli}
160print_version "$GNUTLS_CLI" "--version" "default" "head -n 1"
161echo
162
163: ${GNUTLS_SERV:=gnutls-serv}
164print_version "$GNUTLS_SERV" "--version" "default" "head -n 1"
165echo
166
167if [ -n "${GNUTLS_LEGACY_CLI+set}" ]; then
168    print_version "$GNUTLS_LEGACY_CLI" "--version" "legacy" "head -n 1"
169else
170     echo " * gnutls-cli (legacy): Not configured."
171fi
172echo
173
174if [ -n "${GNUTLS_LEGACY_SERV+set}" ]; then
175    print_version "$GNUTLS_LEGACY_SERV" "--version" "legacy" "head -n 1"
176else
177    echo " * gnutls-serv (legacy): Not configured."
178fi
179echo
180
181echo " * Installed asan versions:"
182if type dpkg-query >/dev/null 2>/dev/null; then
183    if ! dpkg-query -f '${Status} ${Package}: ${Version}\n' -W 'libasan*' |
184         awk '$3 == "installed" && $4 !~ /-/ {print $4, $5}' |
185         grep .
186    then
187        echo "   No asan versions installed."
188    fi
189else
190    echo "  Unable to determine the asan version without dpkg."
191fi
192echo
193