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