#!/usr/bin/env bash MAKE=${MAKE:-make} get_cmd_version() { if [ -z "$1" ]; then return fi VERSION_RAW=$( ($@ --version) 2>&1) ERR=$? VERSION=$(echo "$VERSION_RAW" | head -n 1) if [ $ERR -eq 127 ] ; then # 127 means command not found VERSION="missing" elif [ $ERR -ne 0 ] ; then VERSION="error: ${VERSION}" fi printf "%s" "$VERSION" } get_define() { local cc="$1" local line= if command -v "$cc" 2>&1 >/dev/null; then line=$(echo "$3" | "$cc" -x c -include "$2" -E -o - - 2>/dev/null | sed -e '/^[ ]*#/d' -e '/^[ ]*$/d') fi if [ -z "$line" ]; then line=missing fi printf "%s" "$line" } get_kernel_info() { uname -mprs } get_os_info() { local os="$(uname -s)" local osname="unknown" local osvers="unknown" if [ "$os" = "Linux" ]; then osname="$(cat /etc/os-release | grep ^NAME= | awk -F'=' '{print $2}')" osvers="$(cat /etc/os-release | grep ^VERSION= | awk -F'=' '{print $2}')" elif [ "$os" = "Darwin" ]; then osname="$(sw_vers -productName)" osvers="$(sw_vers -productVersion)" elif [ "$os" = "FreeBSD" ]; then osname="$os" osvers="$(freebsd-version)" fi printf "%s %s" "$osname" "$osvers" } extract_shell_version() { SHELL_NAME=$"(basename $1)" SHELL_VERSION="$($1 --version 2>/dev/null)" ERR=$? if [ $ERR -ne 0 ] ; then # if it does not like the --version switch, it is probably dash printf "%s" "$1" # we do not say "probably dash" if we are sure it IS dash if [ "$SHELL_NAME" != dash ] ; then printf " (probably dash)" fi else printf "%s" "$(echo "$SHELL_VERSION" | head -n 1)" fi } get_sys_shell() { case "$(uname -s)" in MINGW*) # MINGW has no realpath, but also no (meaningful) symlinks SH_PATH=/bin/sh ;; *) SH_PATH="$(realpath /bin/sh)" ;; esac extract_shell_version "$SH_PATH" } _get_make_shell() { ${MAKE} -sf - --no-print-directory 2>/dev/null <