Home | History | Annotate | Download | only in make
      1 #!/bin/sh
      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 
     14 for opt in "$@"; do
     15     optval="${opt#*=}"
     16     case "$opt" in
     17     --bare) bare=true ;;
     18     *) break ;;
     19     esac
     20     shift
     21 done
     22 source_path=${1:-.}
     23 out_file=${2}
     24 id=${3:-VERSION_STRING}
     25 
     26 git_version_id=""
     27 if [ -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`
     31 fi
     32 
     33 changelog_version=""
     34 for 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
     40 done
     41 version_str="${changelog_version}${git_version_id}"
     42 bare_version=${version_str#v}
     43 major_version=${bare_version%%.*}
     44 bare_version=${bare_version#*.}
     45 minor_version=${bare_version%%.*}
     46 bare_version=${bare_version#*.}
     47 patch_version=${bare_version%%-*}
     48 bare_version=${bare_version#${patch_version}}
     49 extra_version=${bare_version##-}
     50 
     51 #since they'll be used as integers below make sure they are or force to 0
     52 for 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
     56 done
     57 
     58 if [ ${bare} ]; then
     59     echo "${changelog_version}${git_version_id}" > $$.tmp
     60 else
     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}"
     69 EOF
     70 fi
     71 if [ -n "$out_file" ]; then
     72 diff $$.tmp ${out_file} >/dev/null 2>&1 || cat $$.tmp > ${out_file}
     73 else
     74 cat $$.tmp
     75 fi
     76 rm $$.tmp
     77