Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 

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