From 4ab720b44ac5a98a9192d87a50630f964ab5eaa6 Mon Sep 17 00:00:00 2001 From: midipix Date: Thu, 26 Nov 2015 21:43:06 -0500 Subject: build system: version.sh: initial implementation. --- sysinfo/version.sh | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 sysinfo/version.sh (limited to 'sysinfo') diff --git a/sysinfo/version.sh b/sysinfo/version.sh new file mode 100755 index 0000000..fb1e8c3 --- /dev/null +++ b/sysinfo/version.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +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" || exit 2 + +gitver=`git rev-parse --verify HEAD` || gitver="unknown" +macro=`echo "$prefix"_GIT_VERSION | tr '[:lower:]' '[:upper:]'` + +cd "$workdir" || exit 2 +printf "#define $macro\t\"$gitver\"\n" > "$output" + +# all done +exit 0 -- cgit v1.2.3