Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

204 rindas
4.3 KiB

  1. #!/bin/bash
  2. # set -x #enable debug
  3. SCRIPTPATH=$(readlink -f $0)
  4. SCRIPTNAME=$(basename $SCRIPTPATH)
  5. SCRIPTDIR=$(dirname $SCRIPTPATH)
  6. git="git"
  7. HAS_GIT=true
  8. HEADER_DIR="$SCRIPTDIR/header"
  9. INC_MAJOR=false
  10. INC_MINOR=false
  11. INC_BUGFIX=false
  12. function log()
  13. {
  14. echo "$@" >&2
  15. }
  16. function cleaupAndExit()
  17. {
  18. if $HAS_GIT && [[ -n "$TAGNAME" ]] && [[ $1 -ne 0 ]]; then
  19. log "remove git tag $TAGNAME"
  20. $git tag -d $TAGNAME
  21. fi
  22. exit $1
  23. }
  24. function printHelp()
  25. {
  26. printf "script to build libShaderFile release
  27. Usage:
  28. $SCRIPTNAME [parameter]
  29. [] optional parameters
  30. () required parameters
  31. Parameter:
  32. --major | -m
  33. increment major version and reset the minor version before creating git tag
  34. --minor | -n
  35. increment major version and reset the bugfix version before creating git tag
  36. --bufgix | -b
  37. increment bugfix version before creating git tag
  38. --help | -h | -?
  39. print this help
  40. "
  41. }
  42. function getLastVersion()
  43. {
  44. POS="HEAD"
  45. TAG=$($git describe --tags --abbrev=0 $POS 2>/dev/null)
  46. RET=$?
  47. while [[ $RET -eq 0 ]]; do
  48. if [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  49. echo $(echo $TAG | egrep -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")
  50. return 0
  51. fi
  52. POS=$TAG"^"
  53. TAG=$($git describe --tags --abbrev=0 $POS 2>/dev/null)
  54. RET=$?
  55. done
  56. return 1
  57. }
  58. function incVersion()
  59. {
  60. read -r -a PARTS <<< $(echo "$1" | tr "." " ")
  61. if $INC_MAJOR; then
  62. ((PARTS[0]++))
  63. PARTS[1]=0
  64. fi
  65. if $INC_MINOR; then
  66. ((PARTS[1]++))
  67. PARTS[2]=0
  68. fi
  69. if $INC_BUGFIX; then
  70. ((PARTS[2]++))
  71. fi
  72. ((PARTS[3]++))
  73. local tmp="${PARTS[@]}"
  74. echo "${tmp// /.}"
  75. }
  76. function addGitTag()
  77. {
  78. local INC_VERSION=true
  79. log "create git version tag"
  80. CURRENT=$(getLastVersion)
  81. if [ $? -ne 0 ]; then
  82. CURRENT="0.0.0.0"
  83. INC_VERSION=false
  84. fi
  85. local tmp="v$CURRENT"
  86. LINES=$($git log --pretty=oneline $tmp..HEAD)
  87. if [ $? -eq 0 ]; then
  88. DIFF=$(echo $LINES | wc -l)
  89. if [ $DIFF -eq 0 ] || [ -z "$LINES" ]; then
  90. log "current commit already has a version tag: $tmp"
  91. TAGNAME=$tmp
  92. return 0
  93. fi
  94. fi
  95. if $INC_VERSION; then
  96. NEWVERSION=$(incVersion $CURRENT)
  97. else
  98. NEWVERSION="$CURRENT"
  99. fi
  100. log "current version: $CURRENT"
  101. log "new version: $NEWVERSION"
  102. local tmp="v$NEWVERSION"
  103. $git tag $tmp
  104. if [[ $? -ne 0 ]]; then
  105. log "unable to create version tag: exit"
  106. cleaupAndExit 100
  107. fi
  108. TAGNAME=$tmp
  109. return 0
  110. }
  111. function BuildConfig()
  112. {
  113. CONFIG=$1
  114. POSTFIX=$2
  115. FILEEXT=$3
  116. printf "\n== build project $CONFIG ==\n"
  117. lazbuild --build-mode=$CONFIG --build-all --verbose $SCRIPTDIR/libShaderFile.lpi
  118. if [ $? -ne 0 ]; then
  119. echo "build failed! exit."
  120. cleaupAndExit 1
  121. fi
  122. ZIPDIR="bin/$POSTFIX"
  123. BINDIR="$ZIPDIR"
  124. ZIPPATH="$SCRIPTDIR/libShaderFile-$POSTFIX.zip"
  125. if [ -n "$TAGNAME" ]; then
  126. mkdir -p "$SCRIPTDIR/$TAGNAME/"
  127. ZIPPATH="$SCRIPTDIR/$TAGNAME/libShaderFile-$POSTFIX.zip"
  128. fi
  129. BINNAME="libShaderFile-$POSTFIX$FILEEXT"
  130. if [ ! -f $BINNAME ]; then
  131. echo "file not found: $EXENAME"
  132. cleaupAndExit 2
  133. fi
  134. mkdir -p $BINDIR
  135. mv "$BINNAME" "$BINDIR/" || { log "unable to copy linked binary"; cleaupAndExit 3; }
  136. # use this to copy data folder instead of data archive: cp -R --preserve=links data $BINDIR || { log "unable to copy data folder"; cleaupAndExit 4; }
  137. cp -r "$HEADER_DIR" "$BINDIR" || { log "unable to copy header files"; cleaupAndExit 4; }
  138. pushd $ZIPDIR
  139. rm -rf $ZIPPATH
  140. zip -r $ZIPPATH ./* || { log "unable to create zip archive"; cleaupAndExit 5; }
  141. popd
  142. }
  143. while [[ $# -gt 0 ]]; do
  144. case $1 in
  145. "--major" | "-m")
  146. INC_MAJOR=true
  147. ;;
  148. "--minor" | "-n")
  149. INC_MINOR=true
  150. ;;
  151. "--bufgix" | "-b")
  152. INC_BUGFIX=true
  153. ;;
  154. "--help" | "-h" | "-?")
  155. printHelp
  156. cleaupAndExit 0
  157. ;;
  158. *)
  159. echo "invalid parameter: $1"
  160. echo "use --help to get further information"
  161. ;;
  162. esac
  163. shift
  164. done
  165. if $HAS_GIT; then
  166. GIT_CHANGED=$($git status --untracked-files=all --verbose --porcelain)
  167. if [[ -n "$GIT_CHANGED" ]]; then
  168. log "git has uncommited changes. please commit before building a release"
  169. cleaupAndExit 101
  170. fi
  171. addGitTag
  172. fi
  173. BuildConfig "Win32Release" "i386-win32" ".dll"
  174. BuildConfig "Win64Release" "x86_64-win64" ".dll"
  175. BuildConfig "Linux32Release" "i386-linux" ".so"
  176. BuildConfig "Linux64Release" "x86_64-linux" ".so"
  177. cleaupAndExit 0