#!/bin/sh package="$1" version_file="$2" ver='unnamed_version' # Try git, version file and gitweb, in this order if [ -e '.git' -o -e '../.git' ]; then git_ver=$(git describe --abbrev=4 --always HEAD 2>/dev/null) [ -z "$git_ver" ] && git_ver="$ver" # update stat information in index to match working tree git update-index -q --refresh > /dev/null # if there are differences (exit code 1), the working tree is dirty git diff-index --quiet HEAD || git_ver=$git_ver-dirty branch=$(git describe --all --contains HEAD 2>/dev/null) [ -n "$branch" ] && git_ver="$git_ver-$branch" ver=$git_ver elif [ -f VERSION ]; then ver=$(cat VERSION) elif [ "${PWD%%-*}" = $package- ]; then ver=${PWD##*/$package-} fi ver=${ver#v} echo "$ver" [ -z "${version_file}" ] && exit 0 # update version file if necessary content="const char *${package}_version(void) {return \"$ver\";}" info=" \"Copyright (C) $COPYRIGHT_YEAR - present $AUTHOR\\n\" \"License: $LICENSE <$LICENSE_URL\\n\" \"This is free software: you are free to change and redistribute it.\\n\" \"There is NO WARRANTY, to the extent permitted by law.\\n\" \"\\n\" \"Project Website: $PROJECT_WEBSITE\\n\" \"Clone URL: $CLONE_URL\\n\" \"Gitweb: $GITWEB_URL\\n\" \"Author Home Page: $HOME_URL\\n\" \"Send feedback to: $AUTHOR <$EMAIL>\\n\" " content="$content const char *${package}_info(void) {return $info;};" [ -r "$version_file" ] && printf '%s\n' "$content" | cmp -s - $version_file && exit 0 [ "$version_file" = "${version_file%/*}" ] || mkdir -p ${version_file%/*} printf '%s\n' "$content" > $version_file