generate-srs-librtmp-single.sh 4.9 KB

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