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.

95 lines
2.0 KiB

  1. #!/usr/bin/env bash
  2. set -e
  3. NAME=shadowsocks-libev
  4. SELF=$(readlink -f -- "$0")
  5. HERE=$(dirname -- "$SELF")
  6. SOURCES="${HERE}"/SOURCES
  7. SPEC_TEMPLATE="${HERE}"/SPECS/${NAME}.spec.in
  8. SPEC_FILE="${SPEC_TEMPLATE%%.in}"
  9. GIT_VERSION=$("${HERE}"/../scripts/git_version.sh)
  10. OPT_OUTDIR="${HERE}/SRPMS"
  11. OPT_USE_SYSTEM_LIB=0
  12. OUT_BUILD_RPM=0
  13. version=$(echo ${GIT_VERSION} | cut -d' ' -f1)
  14. release=$(echo ${GIT_VERSION} | cut -d' ' -f2)
  15. name_version=${NAME}-${version}-${release}
  16. source_name=${name_version}.tar.gz
  17. archive()
  18. {
  19. "${HERE}"/../scripts/git_archive.sh -o "${SOURCES}" -n ${name_version}
  20. }
  21. build_src_rpm()
  22. {
  23. rpmbuild -bs "${SPEC_FILE}" \
  24. --undefine "dist" \
  25. --define "%_topdir ${HERE}" \
  26. --define "%_srcrpmdir ${OPT_OUTDIR}"
  27. }
  28. build_rpm()
  29. {
  30. rpmbuild --rebuild "${OPT_OUTDIR}"/${name_version}.src.rpm \
  31. --define "%_topdir ${HERE}" \
  32. --define "%use_system_lib ${OPT_USE_SYSTEM_LIB}"
  33. }
  34. create_spec()
  35. {
  36. sed -e "s/@NAME@/${NAME}/g" \
  37. -e "s/@VERSION@/${version}/g" \
  38. -e "s/@RELEASE@/${release}/g" \
  39. -e "s/@SOURCE@/${source_name}/g" \
  40. -e "s/@NAME_VERSION@/${name_version}/g" \
  41. "${SPEC_TEMPLATE}" > "${SPEC_FILE}"
  42. }
  43. show_help()
  44. {
  45. echo -e "$(basename $0) [OPTION...]"
  46. echo -e "Create and build shadowsocks-libev SRPM"
  47. echo
  48. echo -e "Options:"
  49. echo -e " -h show this help."
  50. echo -e " -b use rpmbuld to build resulting SRPM"
  51. echo -e " -s use system shared libraries (RPM only)"
  52. echo -e " -o output directory"
  53. }
  54. while getopts "hbso:" opt
  55. do
  56. case ${opt} in
  57. h)
  58. show_help
  59. exit 0
  60. ;;
  61. b)
  62. OPT_BUILD_RPM=1
  63. ;;
  64. s)
  65. OPT_USE_SYSTEM_LIB=1
  66. ;;
  67. o)
  68. OPT_OUTDIR=$(readlink -f -- $OPTARG)
  69. ;;
  70. *)
  71. show_help
  72. exit 1
  73. ;;
  74. esac
  75. done
  76. create_spec
  77. archive
  78. build_src_rpm
  79. if [ "${OPT_BUILD_RPM}" = "1" ] ; then
  80. build_rpm
  81. fi