1#! /bin/bash 2# 3# Create the wpsvers.h file from version.h.in 4# 5# $Id: wpsvers.sh,v 1.2 2010-04-08 00:08:22 $ 6 7# Check for the in file, if not there we're probably in the wrong directory 8if [ ! -f version.h.in ]; then 9 echo No version.h.in found 10 exit 1 11fi 12 13if echo "${TAG}" | grep -q "BRANCH\|TWIG"; then 14 branchtag=$TAG 15else 16 branchtag="" 17fi 18 19if [ -f wpsvers.h ]; then 20 # If the out file already exists, increment its build number 21 build=`grep MOD_BUILD_NUMBER wpsvers.h | sed -e "s,.*BUILD_NUMBER[ ]*,,"` 22 build=`expr ${build} + 1` 23 echo build=${build} 24 sed -e "s,.*_BUILD_NUMBER.*,#define MOD_BUILD_NUMBER ${build}," \ 25 < wpsvers.h > wpsvers.h.new 26 mv wpsvers.h wpsvers.h.prev 27 mv wpsvers.h.new wpsvers.h 28else 29 # Otherwise create a new file. 30 31 # CVS will insert the cvs tag name when this file is checked out. 32 # If this is a tagged build, use the tag to supply the numbers 33 # Tag should be in the form 34 # <NAME>_REL_<MAJ>_<MINOR> 35 # or 36 # <NAME>_REL_<MAJ>_<MINOR>_RC<RCNUM> 37 # or 38 # <NAME>_REL_<MAJ>_<MINOR>_RC<RCNUM>_<INCREMENTAL> 39 # 40 41 CVSTAG="$Name: not supported by cvs2svn $" 42 43 # Remove leading cvs "Name: " and trailing " $" 44 CVSTAG=${CVSTAG/#*: /} 45 CVSTAG=${CVSTAG/% $/} 46 47 # TAG env var is supplied by calling makefile or build process 48 # 49 # If the checkout is from a branch tag, cvs checkout or export does 50 # not replace rcs keywords. In such instances TAG env variable can 51 # be used (by uncommenting following line). TAG env variable format 52 # itself needs to be validated for number of fields before being used. 53 # (e.g: HEAD is not a valid tag, which results in all '0' values below) 54 # 55 if [ -n "$branchtag" ]; then 56 TAG=${TAG:-${CVSTAG}} 57 else 58 TAG=${CVSTAG/HEAD/} 59 fi 60 61 # Split the tag into an array on underbar or whitespace boundaries. 62 IFS="_ " tag=(${TAG}) 63 unset IFS 64 65 tagged=1 66 if [ ${#tag[*]} -eq 0 ]; then 67 tag=(`date '+TOT REL %Y %m %d 0 %y'`); 68 # reconstruct a TAG from the date 69 TAG=${tag[0]}_${tag[1]}_${tag[2]}_${tag[3]}_${tag[4]}_${tag[5]} 70 tagged=0 71 fi 72 73 # Allow environment variable to override values. 74 # Missing values default to 0 75 # 76 maj=${MOD_MAJOR_VERSION:-${tag[2]:-0}} 77 min=${MOD_MINOR_VERSION:-${tag[3]:-0}} 78 rcnum=${MOD_RC_NUMBER:-${tag[4]:-0}} 79 80 if [ -n "$branchtag" ]; then 81 [ "${tag[5]:-0}" -eq 0 ] && echo "Using date suffix for incr" 82 today=`date '+%Y%m%d'` 83 incremental=${MOD_INCREMENTAL_NUMBER:-${tag[5]:-${today:-0}}} 84 else 85 incremental=${MOD_INCREMENTAL_NUMBER:-${tag[5]:-0}} 86 fi 87 origincr=${MOD_INCREMENTAL_NUMBER:-${tag[5]:-0}} 88 build=${MOD_BUILD_NUMBER:-0} 89 90 # Strip 'RC' from front of rcnum if present 91 rcnum=${rcnum/#RC/} 92 93 # strip leading zero off the number (otherwise they look like octal) 94 maj=${maj/#0/} 95 min=${min/#0/} 96 rcnum=${rcnum/#0/} 97 incremental=${incremental/#0/} 98 origincr=${origincr/#0/} 99 build=${build/#0/} 100 101 # some numbers may now be null. replace with with zero. 102 maj=${maj:-0} 103 min=${min:-0} 104 rcnum=${rcnum:-0} 105 incremental=${incremental:-0} 106 origincr=${origincr:-0} 107 build=${build:-0} 108 109 if [ ${tagged} -eq 1 ]; then 110 # vernum is 32chars max 111 vernum=`printf "0x%02x%02x%02x%02x" ${maj} ${min} ${rcnum} ${origincr}` 112 else 113 vernum=`printf "0x00%02x%02x%02x" ${tag[7]} ${min} ${rcnum}` 114 fi 115 116 # make sure the size of vernum is under 32 bits. Otherwise, truncate. The string will keep 117 # full information. 118 vernum=${vernum:0:10} 119 120 # build the string directly from the tag, irrespective of its length 121 # remove the name , the tag type, then replace all _ by . 122 tag_ver_str=${TAG/${tag[0]}_} 123 tag_ver_str=${tag_ver_str/${tag[1]}_} 124 tag_ver_str=${tag_ver_str//_/.} 125 126 # record tag type 127 tagtype= 128 129 if [ "${tag[1]}" = "BRANCH" -o "${tag[1]}" = "TWIG" ]; then 130 tagtype="(TOB)" 131 fi 132 133 echo version string : "$tag_ver_str" 134 echo tag type $tagtype 135 136 # OK, go do it 137 138 echo "maj=${maj}, min=${min}, rc=${rcnum}, inc=${incremental}, build=${build}" 139 140 sed \ 141 -e "s;@MOD_MAJOR_VERSION@;${maj};" \ 142 -e "s;@MOD_MINOR_VERSION@;${min};" \ 143 -e "s;@MOD_RC_NUMBER@;${rcnum};" \ 144 -e "s;@MOD_INCREMENTAL_NUMBER@;${incremental};" \ 145 -e "s;@MOD_BUILD_NUMBER@;${build};" \ 146 -e "s;@MOD_VERSION@;${maj}, ${min}, ${rcnum}, ${incremental};" \ 147 -e "s;@MOD_VERSION_STR@;${tag_ver_str};" \ 148 -e "s;@MOD_ROUTER_VERSION_STR@;${tag_ver_str};" \ 149 -e "s;@VERSION_TYPE@;${tagtype};" \ 150 -e "s;@MOD_VERSION_NUM@;${vernum};" \ 151 < version.h.in > wpsvers.h 152 153fi 154