You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.2 KiB

  1. #!/usr/bin/env bash
  2. set -e
  3. SELF=$(readlink -f -- "$0")
  4. HERE=$(dirname -- "$SELF")
  5. show_help()
  6. {
  7. echo -e "`basename $0` [OPTION...]"
  8. echo
  9. echo -e "Options:"
  10. echo -e " -h show this help."
  11. echo -e " -s use system shared libraries"
  12. }
  13. OPT_USE_SYSTEM_LIB=0
  14. while getopts "hs" opt
  15. do
  16. case ${opt} in
  17. h)
  18. show_help
  19. exit 0
  20. ;;
  21. s)
  22. OPT_USE_SYSTEM_LIB=1
  23. ;;
  24. *)
  25. show_help
  26. exit 1
  27. ;;
  28. esac
  29. done
  30. # determine version and release number
  31. GIT_DESCRIBE=$(git describe --tags --match 'v*' --long --dirty)
  32. # GIT_DESCRIBE is like v3.0.3-11-g1e3f35c-dirty
  33. if [[ ! "$GIT_DESCRIBE" =~ ^v([^-]+)-([0-9]+)-g([0-9a-f]+)(-dirty)?$ ]]; then
  34. >&2 echo 'ERROR - unrecognized `git describe` output: '"$GIT_DESCRIBE"
  35. exit 1
  36. fi
  37. TARGET_VERSION=${BASH_REMATCH[1]}
  38. TARGET_COMMITS=${BASH_REMATCH[2]}
  39. TARGET_SHA1=${BASH_REMATCH[3]}
  40. TARGET_DIRTY=${BASH_REMATCH[4]}
  41. TARGET_RELEASE=1
  42. if [ "$TARGET_COMMITS" -gt 0 ]; then
  43. TARGET_RELEASE+=".$TARGET_COMMITS.git$TARGET_SHA1"
  44. fi
  45. if [ -n "$TARGET_DIRTY" ]; then
  46. TARGET_RELEASE+=.dirty
  47. fi
  48. TARGET_VERREL=$TARGET_VERSION-$TARGET_RELEASE
  49. >&2 echo "INFO - RPM version-release is $TARGET_VERREL."
  50. # archive tarball from Git workspace
  51. TARGET_TARBALL_NAME=shadowsocks-libev-$TARGET_VERSION
  52. TARGET_TARBALL_DIR=$HERE/SOURCES
  53. mkdir -p -- "$TARGET_TARBALL_DIR"
  54. #git archive HEAD --format=tar --prefix="$TARGET_TARBALL_NAME/" \
  55. # -o "$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME.tar"
  56. pushd "$HERE"/..
  57. make clean
  58. tar --exclude './rpm' --exclude '.[^/]*' --transform "s,^\.,$TARGET_TARBALL_NAME," \
  59. -cvf "$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME.tar" .
  60. popd
  61. # generate spec file
  62. TARGET_SPEC_DIR=$HERE/SPECS
  63. mkdir -p -- "$TARGET_SPEC_DIR"
  64. TARGET_SPEC_PATH=$TARGET_SPEC_DIR/shadowsocks-libev.spec
  65. sed -e "s/^\(Version:\).*$/\1 ${TARGET_VERSION}/" \
  66. -e "s/^\(Release:\).*$/\1 ${TARGET_RELEASE}%{?dist}/" \
  67. -e "s/^\(Source0:\).*$/\1 ${TARGET_TARBALL_NAME}.tar/" \
  68. "${TARGET_SPEC_PATH}".in > "${TARGET_SPEC_PATH}"
  69. # build rpms
  70. rpmbuild -ba "$TARGET_SPEC_PATH" \
  71. --define "%_topdir $HERE" \
  72. --define "%use_system_lib $OPT_USE_SYSTEM_LIB"