1#!/bin/bash 2## 3## Copyright (c) 2010 The WebM project authors. All Rights Reserved. 4## 5## Use of this source code is governed by a BSD-style license 6## that can be found in the LICENSE file in the root of the source 7## tree. An additional intellectual property rights grant can be found 8## in the file PATENTS. All contributing project authors may 9## be found in the AUTHORS file in the root of the source tree. 10## 11 12 13 14for opt in "$@"; do 15 optval="${opt#*=}" 16 case "$opt" in 17 --bare) bare=true ;; 18 *) break ;; 19 esac 20 shift 21done 22source_path=${1:-.} 23out_file=${2} 24id=${3:-VERSION_STRING} 25 26git_version_id="" 27if [ -d ${source_path}/.git ]; then 28 # Source Path is a git working copy. Check for local modifications. 29 export GIT_DIR=${source_path}/.git 30 git_version_id=`git describe --match=v[0-9]* 2>/dev/null` 31fi 32 33changelog_version="" 34for p in "${source_path}" "${source_path}/.."; do 35 if [ -z "$git_version_id" -a -f "${p}/CHANGELOG" ]; then 36 changelog_version=`head -n1 "${p}/CHANGELOG" | awk '{print $2}'` 37 changelog_version="${changelog_version}" 38 break 39 fi 40done 41version_str="${changelog_version}${git_version_id}" 42bare_version=${version_str#v} 43major_version=${bare_version%%.*} 44bare_version=${bare_version#*.} 45minor_version=${bare_version%%.*} 46bare_version=${bare_version#*.} 47patch_version=${bare_version%%-*} 48bare_version=${bare_version#${patch_version}} 49extra_version=${bare_version##-} 50 51#since they'll be used as integers below make sure they are or force to 0 52for v in major_version minor_version patch_version; do 53 if eval echo \$$v |grep -E -q '[^[:digit:]]'; then 54 eval $v=0 55 fi 56done 57 58if [ ${bare} ]; then 59 echo "${changelog_version}${git_version_id}" > $$.tmp 60else 61 cat<<EOF>$$.tmp 62#define VERSION_MAJOR $major_version 63#define VERSION_MINOR $minor_version 64#define VERSION_PATCH $patch_version 65#define VERSION_EXTRA "$extra_version" 66#define VERSION_PACKED ((VERSION_MAJOR<<16)|(VERSION_MINOR<<8)|(VERSION_PATCH)) 67#define ${id}_NOSP "${version_str}" 68#define ${id} " ${version_str}" 69EOF 70fi 71if [ -n "$out_file" ]; then 72diff $$.tmp ${out_file} >/dev/null 2>&1 || cat $$.tmp > ${out_file} 73else 74cat $$.tmp 75fi 76rm $$.tmp 77