From 2189ad980eae15916143975e774bd06f62a0b387 Mon Sep 17 00:00:00 2001 From: midipix Date: Wed, 26 Dec 2018 08:48:48 -0500 Subject: build system: major overhaul: removed sysinfo, integrated ccenv. --- sofort/version.sh | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 sofort/version.sh (limited to 'sofort/version.sh') diff --git a/sofort/version.sh b/sofort/version.sh new file mode 100755 index 0000000..f510a32 --- /dev/null +++ b/sofort/version.sh @@ -0,0 +1,72 @@ +#!/bin/sh + +set -eu + +usage() +{ +cat << EOF >&2 + +Usage: + -h show this HELP message + -s SRCDIR set source directory + -o OUTPUT set output header + -p PREFIX set macro prefix + +EOF +exit 1 +} + + +# one +workdir=$(pwd) +srcdir= +output= +prefix= + + +while getopts "hs:o:p:" opt; do + case $opt in + h) + usage + ;; + s) + srcdir="$OPTARG" + ;; + o) + output="$OPTARG" + ;; + p) + prefix="$OPTARG" + ;; + \?) + printf "Invalid option: -%s" "$OPTARG" >&2 + usage + ;; + esac +done + + +# two +if [ -z "$srcdir" ] || [ -z "$output" ] || [ -z "$prefix" ]; then + usage +fi + +cd "$srcdir" + +gitver=$(git rev-parse --verify HEAD 2>/dev/null) || gitver="unknown" +cvdate=$(git show -s --format=%ci $gitver 2>/dev/null) || cvdate=$(date) + +vmacro=$(printf '%s' "$prefix"'_GIT_VERSION' | tr '[:lower:]' '[:upper:]') +dmacro=$(printf '%s' "$prefix"'_GIT_DATE ' | tr '[:lower:]' '[:upper:]') + +cd "$workdir" + + +# three +printf '#define %s "%s"\n#define %s "%s"\n' \ + "$vmacro" "$gitver" \ + "$dmacro" "$cvdate" \ + > "$output" + +# all done +exit 0 -- cgit v1.2.3