build-macos.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/bin/bash
  2. ##############################################################################
  3. # macOS plugin build script
  4. ##############################################################################
  5. #
  6. # This script contains all steps necessary to:
  7. #
  8. # * Build libobs and obs-frontend-api with all required dependencies
  9. # * Build your plugin
  10. # * Create macOS module bundle
  11. # * Create macOS plugin installer package
  12. # * Notarize macOS plugin installer package
  13. #
  14. # Parameters:
  15. # -h, --help : Print usage help
  16. # -q, --quiet : Suppress most build process output
  17. # -v, --verbose : Enable more verbose build process output
  18. # -d, --skip-dependency-checks : Skip dependency checks
  19. # -p, --package : Create installer for plugin
  20. # -c, --codesign : Codesign plugin and installer
  21. # -n, --notarize : Notarize plugin installer
  22. # (implies --codesign)
  23. # -b, --build-dir : Specify alternative build directory
  24. # (default: build)
  25. #
  26. # Environment Variables (optional):
  27. # MACOS_DEPS_VERSION : Pre-compiled macOS dependencies version
  28. # QT_VERSION : Pre-compiled Qt version
  29. # OBS_VERSION : OBS version
  30. #
  31. ##############################################################################
  32. # Halt on errors
  33. set -eE
  34. ## SET UP ENVIRONMENT ##
  35. _RUN_OBS_BUILD_SCRIPT=TRUE
  36. CHECKOUT_DIR="$(/usr/bin/git rev-parse --show-toplevel)"
  37. if [ -f "${CHECKOUT_DIR}/CI/include/build_environment.sh" ]; then
  38. source "${CHECKOUT_DIR}/CI/include/build_environment.sh"
  39. fi
  40. PRODUCT_NAME="${PRODUCT_NAME:-obs-plugin}"
  41. DEPS_BUILD_DIR="${CHECKOUT_DIR}/../obs-build-dependencies"
  42. OBS_BUILD_DIR="${CHECKOUT_DIR}/../obs-studio"
  43. source "${CHECKOUT_DIR}/CI/include/build_support.sh"
  44. source "${CHECKOUT_DIR}/CI/include/build_support_macos.sh"
  45. ## DEPENDENCY INSTALLATION ##
  46. source "${CHECKOUT_DIR}/CI/macos/01_install_dependencies.sh"
  47. ## OBS LIBRARY BUILD ##
  48. source "${CHECKOUT_DIR}/CI/macos/02_build_obs_libs.sh"
  49. ## PLUGIN BUILD ##
  50. source "${CHECKOUT_DIR}/CI/macos/03_build_plugin.sh"
  51. ## PLUGIN PACKAGE AND NOTARIZE ##
  52. source "${CHECKOUT_DIR}/CI/macos/04_package_plugin.sh"
  53. ## MAIN SCRIPT FUNCTIONS ##
  54. print_usage() {
  55. echo -e "build_macos.sh - Build script for ${PRODUCT_NAME}\n"
  56. echo -e "Usage: ${0}\n" \
  57. "-h, --help : Print this help\n" \
  58. "-q, --quiet : Suppress most build process output\n" \
  59. "-v, --verbose : Enable more verbose build process output\n" \
  60. "-a, --architecture : Specify build architecture (default: universal, alternative: x86_64, arm64)\n" \
  61. "-d, --skip-dependency-checks : Skip dependency checks\n" \
  62. "-p, --package : Create installer for plugin\n" \
  63. "-c, --codesign : Codesign plugin and installer\n" \
  64. "-n, --notarize : Notarize plugin installer (implies --codesign)\n" \
  65. "-b, --build-dir : Specify alternative build directory (default: build)\n"
  66. }
  67. obs-build-main() {
  68. while true; do
  69. case "${1}" in
  70. -h | --help ) print_usage; exit 0 ;;
  71. -q | --quiet ) export QUIET=TRUE; shift ;;
  72. -v | --verbose ) export VERBOSE=TRUE; shift ;;
  73. -a | --architecture ) ARCH="${2}"; shift 2 ;;
  74. -d | --skip-dependency-checks ) SKIP_DEP_CHECKS=TRUE; shift ;;
  75. -p | --package ) PACKAGE=TRUE; shift ;;
  76. -c | --codesign ) CODESIGN=TRUE; shift ;;
  77. -n | --notarize ) NOTARIZE=TRUE; PACKAGE=TRUE CODESIGN=TRUE; shift ;;
  78. -b | --build-dir ) BUILD_DIR="${2}"; shift 2 ;;
  79. -- ) shift; break ;;
  80. * ) break ;;
  81. esac
  82. done
  83. ensure_dir "${CHECKOUT_DIR}"
  84. check_macos_version
  85. check_archs
  86. step "Fetching version tags..."
  87. /usr/bin/git fetch origin --tags
  88. GIT_BRANCH=$(/usr/bin/git rev-parse --abbrev-ref HEAD)
  89. GIT_HASH=$(/usr/bin/git rev-parse --short HEAD)
  90. GIT_TAG=$(/usr/bin/git describe --tags --abbrev=0 2&>/dev/null || true)
  91. if [ "${ARCH}" = "arm64" ]; then
  92. FILE_NAME="${PRODUCT_NAME}-${GIT_TAG:-${PRODUCT_VERSION}}-${GIT_HASH}-macOS-Apple.pkg"
  93. elif [ "${ARCH}" = "x86_64" ]; then
  94. FILE_NAME="${PRODUCT_NAME}-${GIT_TAG:-${PRODUCT_VERSION}}-${GIT_HASH}-macOS-Intel.pkg"
  95. else
  96. FILE_NAME="${PRODUCT_NAME}-${GIT_TAG:-${PRODUCT_VERSION}}-${GIT_HASH}-macOS-Universal.pkg"
  97. fi
  98. if [ -z "${SKIP_DEP_CHECKS}" ]; then
  99. install_dependencies
  100. fi
  101. build_obs_libs
  102. build_obs_plugin
  103. if [ -n "${PACKAGE}" ]; then
  104. package_obs_plugin
  105. fi
  106. if [ -n "${NOTARIZE}" ]; then
  107. notarize_obs_plugin
  108. fi
  109. cleanup
  110. }
  111. obs-build-main $*