2
0

setup_variables.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. # when options parsed, setup some variables, then build the depends.
  3. OS_KERNEL_NAME=$(uname -s)
  4. OS_KERNRL_RELEASE=$(uname -r|awk -F '-' '{print $1}')
  5. OS_PREFIX="Platform"
  6. # Detect gcc, which is required.
  7. gcc --version >/dev/null 2>/dev/null || (ret=$?; echo "Please install gcc"; exit $ret)
  8. # Discover SRS version from header file.
  9. mkdir -p ${SRS_OBJS} &&
  10. echo '#include <stdio.h>' > ${SRS_OBJS}/test_version.c &&
  11. echo '#include <srs_core_version.hpp>' >> ${SRS_OBJS}/test_version.c &&
  12. echo 'int main(int argc, char** argv) {' >> ${SRS_OBJS}/test_version.c &&
  13. echo ' printf("%d.%d.%d\n", VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION);' >> ${SRS_OBJS}/test_version.c &&
  14. echo ' return 0;' >> ${SRS_OBJS}/test_version.c &&
  15. echo '}' >> ${SRS_OBJS}/test_version.c &&
  16. gcc -g -O0 ${SRS_OBJS}/test_version.c -I${SRS_WORKDIR}/src/core -o ${SRS_OBJS}/test_version 1>/dev/null 2>&1 &&
  17. SRS_VERSION=$(./${SRS_OBJS}/test_version 2>/dev/null) &&
  18. SRS_MAJOR=$(echo $SRS_VERSION |awk -F . '{print $1}');
  19. ret=$?; rm -rf ${SRS_OBJS}/test_version*; if [[ $ret -ne 0 ]]; then echo "Detect SRS version failed"; exit $ret; fi
  20. echo "Discover SRS version=${SRS_VERSION}, major=${SRS_MAJOR}"
  21. if [[ $OSTYPE == cygwin ]]; then
  22. OS_KERNRL_RELEASE=$(uname -r|awk -F '(' '{print $1}')
  23. fi
  24. # Build platform cache.
  25. SRS_PLATFORM="${SRS_BUILD_TAG}${OS_PREFIX}-SRS${SRS_MAJOR}-${OS_KERNEL_NAME}-${OS_KERNRL_RELEASE}"
  26. # Build platform cache with gcc version.
  27. if [[ $OS_KERNEL_NAME == Darwin ]]; then
  28. GCC_VERSION="Clang$(gcc --version 2>/dev/null|grep clang|awk '{print $4}')"
  29. SRS_PLATFORM="${SRS_PLATFORM}-${GCC_VERSION}"
  30. else
  31. GCC_VERSION="GCC$(gcc --version 2>/dev/null|grep gcc|awk '{print $3}')"
  32. echo $GCC_VERSION| grep '-' >/dev/null && GCC_VERSION=$(echo $GCC_VERSION| awk -F '-' '{print$1}')
  33. SRS_PLATFORM="${SRS_PLATFORM}-${GCC_VERSION}"
  34. fi
  35. # Use isolate cache for different SRS version.
  36. SRS_PLATFORM="${SRS_PLATFORM}-$(uname -m)"
  37. if [[ $SRS_CROSS_BUILD == YES ]]; then
  38. SRS_TOOL_CC_NAME=$(basename $SRS_TOOL_CC)
  39. SRS_PLATFORM="${SRS_PLATFORM}-crossbuild-$(echo $SRS_TOOL_CC_NAME|awk -F - '{print $1"-"$2}')"
  40. fi
  41. echo "SRS_WORKDIR: ${SRS_WORKDIR}, SRS_OBJS: ${SRS_OBJS}, SRS_PLATFORM: ${SRS_PLATFORM}"
  42. echo "All outputs to: ${SRS_OBJS}/${SRS_PLATFORM}"
  43. # For src object files on each platform.
  44. (
  45. mkdir -p ${SRS_OBJS} &&
  46. (cd ${SRS_OBJS} && rm -rf src utest srs srs_utest research include lib srs_hls_ingester srs_mp4_parser) &&
  47. mkdir -p ${SRS_OBJS}/src ${SRS_OBJS}/research ${SRS_OBJS}/utest &&
  48. mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty &&
  49. (cd ${SRS_OBJS} && rm -rf st ffmpeg opus srtp2 openssl srt) &&
  50. mkdir -p ${SRS_OBJS}/st ${SRS_OBJS}/ffmpeg ${SRS_OBJS}/opus ${SRS_OBJS}/srtp2 ${SRS_OBJS}/openssl \
  51. ${SRS_OBJS}/srt &&
  52. mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/ffmpeg \
  53. ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/opus ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srtp2 \
  54. ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/openssl ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srt
  55. )
  56. ret=$?; if [[ $ret -ne 0 ]]; then echo "Create build directory failed, ret=$ret"; exit $ret; fi
  57. if [[ $SRS_CLEAN == NO ]]; then
  58. echo "Fast cleanup, if need to do full cleanup, please use: make clean"
  59. fi
  60. # TODO: FIXME: Remove python, use Go for api server demo.
  61. # Python or python2, for CentOS8.
  62. python2 --version >/dev/null 2>&1 && alias python=python2 &&
  63. echo "Alias python2 as python"