No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

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