generate-srs-librtmp-single.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/bin/bash
  2. OS_IS_OSX=NO
  3. uname -s|grep Darwin >/dev/null 2>&1
  4. ret=$?; if [[ 0 -eq $ret ]]; then
  5. OS_IS_OSX=YES
  6. fi
  7. echo "Is OSX: ${OS_IS_OSX}"
  8. # when export srs-librtmp single files
  9. # package the whole project to srs_librtmp.h and srs_librtmp.cpp
  10. #
  11. # params:
  12. # $SRS_OBJS_DIR the objs directory for Makefile. ie. objs
  13. # $SRS_EXPORT_LIBRTMP_SINGLE the export srs-librtmp single path. ie. srs-librtmp
  14. #
  15. # the target dir must created
  16. if [[ ! -d $SRS_EXPORT_LIBRTMP_SINGLE ]]; then
  17. echo -e "${RED}error, target dir not created: $SRS_EXPORT_LIBRTMP_SINGLE${BLACK}"
  18. exit -1
  19. fi
  20. # generate the srs_librtmp.h
  21. cp $SRS_EXPORT_LIBRTMP_SINGLE/src/libs/srs_librtmp.hpp $SRS_EXPORT_LIBRTMP_SINGLE/srs_librtmp.h
  22. # create srs_librtmp.cpp
  23. FILE=$SRS_EXPORT_LIBRTMP_SINGLE/srs_librtmp.cpp
  24. cat << END >$FILE
  25. /*
  26. The MIT License (MIT)
  27. Copyright (c) 2013-2015 SRS(ossrs)
  28. Permission is hereby granted, free of charge, to any person obtaining a copy of
  29. this software and associated documentation files (the "Software"), to deal in
  30. the Software without restriction, including without limitation the rights to
  31. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  32. the Software, and to permit persons to whom the Software is furnished to do so,
  33. subject to the following conditions:
  34. The above copyright notice and this permission notice shall be included in all
  35. copies or substantial portions of the Software.
  36. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  37. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  38. FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  39. COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  40. IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  41. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  42. */
  43. #include "srs_librtmp.h"
  44. END
  45. # build objs auto files to cpp
  46. cat $SRS_EXPORT_LIBRTMP_SINGLE/$SRS_OBJS_DIR/srs_auto_headers.hpp >>$FILE
  47. ret=$?; if [[ $ret -ne 0 ]]; then
  48. echo -e "${RED}failed to generate the srs_librtmp.cpp${BLACK}"
  49. exit $ret
  50. fi
  51. # module to cpp files.
  52. function build_module_hpp()
  53. {
  54. echo "build files ${SRS_LIBRTMP_OBJS} to $FILE"
  55. for item in ${SRS_LIBRTMP_OBJS[*]}; do
  56. FILE_NAME="${item%.*}"
  57. echo "// following is generated by ${FILE_NAME}.hpp" >> $FILE &&
  58. $SED "s|#include <srs_|//#include <srs_|g" $SRS_EXPORT_LIBRTMP_SINGLE/${FILE_NAME}.hpp &&
  59. cat $SRS_EXPORT_LIBRTMP_SINGLE/${FILE_NAME}.hpp >>$FILE
  60. ret=$?; if [[ $ret -ne 0 ]]; then
  61. echo -e "${RED}failed to generate the srs_librtmp.cpp by ${FILE_NAME}.hpp. {${BLACK}"
  62. exit $ret
  63. fi
  64. done
  65. }
  66. SRS_LIBRTMP_OBJS="${CORE_OBJS[@]}" && build_module_hpp
  67. SRS_LIBRTMP_OBJS="${KERNEL_OBJS[@]}" && build_module_hpp
  68. SRS_LIBRTMP_OBJS="${PROTOCOL_OBJS[@]}" && build_module_hpp
  69. SRS_LIBRTMP_OBJS="${LIBS_OBJS[@]}" && build_module_hpp
  70. # module to cpp files.
  71. function build_module_cpp()
  72. {
  73. echo "build files ${SRS_LIBRTMP_OBJS} to $FILE"
  74. for item in ${SRS_LIBRTMP_OBJS[*]}; do
  75. FILE_NAME="${item%.*}"
  76. echo "// following is generated by ${FILE_NAME}.cpp" >> $FILE &&
  77. $SED "s|#include <srs_|//#include <srs_|g" $SRS_EXPORT_LIBRTMP_SINGLE/${FILE_NAME}.cpp &&
  78. cat $SRS_EXPORT_LIBRTMP_SINGLE/${FILE_NAME}.cpp >>$FILE
  79. ret=$?; if [[ $ret -ne 0 ]]; then
  80. echo -e "${RED}failed to generate the srs_librtmp.cpp by ${FILE_NAME}.cpp. {${BLACK}"
  81. exit $ret
  82. fi
  83. done
  84. }
  85. SRS_LIBRTMP_OBJS="${CORE_OBJS[@]}" && build_module_cpp
  86. SRS_LIBRTMP_OBJS="${KERNEL_OBJS[@]}" && build_module_cpp
  87. SRS_LIBRTMP_OBJS="${PROTOCOL_OBJS[@]}" && build_module_cpp
  88. SRS_LIBRTMP_OBJS="${LIBS_OBJS[@]}" && build_module_cpp
  89. # create example.cpp
  90. FILE=$SRS_EXPORT_LIBRTMP_SINGLE/example.c
  91. SRS_SINGLE_LIBRTMP_COMPILE='gcc example.c srs_librtmp.cpp -g -O0 -lstdc++ -o example'
  92. cat << END >$FILE
  93. /**
  94. # Example to use srs-librtmp
  95. # see: https://github.com/ossrs/srs/wiki/v2_CN_SrsLibrtmp
  96. ${SRS_SINGLE_LIBRTMP_COMPILE}
  97. */
  98. #include <stdio.h>
  99. #include "srs_librtmp.h"
  100. int main(int argc, char** argv)
  101. {
  102. srs_rtmp_t rtmp;
  103. printf("Example for srs-librtmp\n");
  104. printf("SRS(ossrs) client librtmp library.\n");
  105. printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision());
  106. rtmp = srs_rtmp_create("rtmp://ossrs.net/live/livestream");
  107. srs_human_trace("create rtmp success");
  108. srs_rtmp_destroy(rtmp);
  109. return 0;
  110. }
  111. END
  112. # compile the example
  113. (cd $SRS_EXPORT_LIBRTMP_SINGLE && echo "${SRS_SINGLE_LIBRTMP_COMPILE}" &&
  114. `${SRS_SINGLE_LIBRTMP_COMPILE}` && ./example && rm -f example)
  115. ret=$?; if [[ $ret -ne 0 ]]; then
  116. echo "(cd $SRS_EXPORT_LIBRTMP_SINGLE && ${SRS_SINGLE_LIBRTMP_COMPILE} && ./example && rm -f example)"
  117. echo -e "${RED}failed to compile example.${BLACK}"
  118. exit $ret
  119. fi
  120. # clear the files for srs-librtmp project, generated by generate-srs-librtmp-project.sh
  121. (cd $SRS_EXPORT_LIBRTMP_SINGLE && rm -rf auto $SRS_OBJS_DIR research src Makefile)