Pre-Compile.sh 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. #!/bin/sh
  2. #
  3. # Pre-Compile.sh
  4. #
  5. # Script that install libvlc and its modules inside VLCKit.
  6. #
  7. # This is for some creepy reasons also used by legacy VLC-release.app or
  8. # the moz plugin.
  9. #
  10. # We are building VLC-release.app or the moz plugin
  11. #
  12. if test "${ACTION}" = "release-makefile"; then
  13. echo "running Pre-Compile.sh in release-makefile mode"
  14. FULL_PRODUCT_NAME="${PRODUCT}"
  15. if [ "$FULL_PRODUCT_NAME" = "VLC-Plugin.plugin" ] ; then
  16. TARGET_BUILD_DIR="${src_dir}"
  17. else
  18. TARGET_BUILD_DIR="${build_dir}"
  19. fi
  20. CONTENTS_FOLDER_PATH="${FULL_PRODUCT_NAME}/Contents/MacOS"
  21. VLC_BUILD_DIR="${build_dir}"
  22. VLC_SRC_DIR="${src_dir}"
  23. ACTION="build"
  24. RELEASE_MAKEFILE="yes"
  25. use_archs="no"
  26. main_build_dir="${VLC_BUILD_DIR}"
  27. else
  28. use_archs="yes"
  29. main_build_dir="${VLC_BUILD_DIR}/x86_64"
  30. fi
  31. if test "${ACTION}" != "build"; then
  32. echo "This script is supposed to run from xcodebuild or Xcode"
  33. exit 1
  34. fi
  35. lib="lib"
  36. modules="modules"
  37. share="share"
  38. include="include"
  39. target="${TARGET_BUILD_DIR}/${CONTENTS_FOLDER_PATH}"
  40. target_lib="${target}/${lib}" # Should we consider using a different well-known folder like shared resources?
  41. target_modules="${target}/${modules}" # Should we consider using a different well-known folder like shared resources?
  42. target_share="${target}/${share}" # Should we consider using a different well-known folder like shared resources?
  43. target_include="${target}/${include}" # Should we consider using a different well-known folder like shared resources?
  44. linked_libs=""
  45. prefix=".libs/"
  46. suffix="dylib"
  47. ##########################
  48. # @function vlc_install(src_lib, dest_dir, type, lib_install_prefix, destination_name)
  49. # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
  50. # @param src_lib source library to copy to the destination directory
  51. # @param dest_dir destination directory where the src_lib should be copied to
  52. vlc_install() {
  53. local src_lib=${1}
  54. local dest_dir=${2}
  55. local type=${3}
  56. local lib_install_prefix=${4}
  57. local destination_name=${5}
  58. if [ $type = "library" ]; then
  59. local install_name="@loader_path/lib"
  60. elif [ $type = "module" ]; then
  61. local install_name="@loader_path/modules"
  62. fi
  63. if [ "$destination_name" != "" ]; then
  64. local lib_dest="$dest_dir/$destination_name"
  65. else
  66. local lib_dest="$dest_dir/`basename $src_lib`"
  67. fi
  68. if [ "$lib_install_prefix" != "" ]; then
  69. local lib_install_prefix="$lib_install_prefix"
  70. else
  71. local lib_install_prefix="@loader_path/../lib"
  72. fi
  73. if test -e ${src_lib} && ((! test -e ${lib_dest}) || test ${src_lib} -nt ${lib_dest} ); then
  74. mkdir -p ${dest_dir}
  75. # Lets copy the library from the source folder to our new destination folder
  76. if [ "${type}" = "bin" ]; then
  77. install -m 755 ${src_lib} ${lib_dest}
  78. else
  79. install -m 644 ${src_lib} ${lib_dest}
  80. fi
  81. # Update the dynamic library so it will know where to look for the other libraries
  82. echo "Installing ${type} `basename ${lib_dest}`"
  83. if [ "${type}" = "lib" ]; then
  84. # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
  85. install_name_tool -id "${install_name}/`basename ${lib_dest}`" ${lib_dest} > /dev/null
  86. fi
  87. if [ "${type}" != "data" ]; then
  88. # Iterate through each installed library and modify the references to other dynamic libraries to match the framework's library directory
  89. for linked_lib in `otool -L ${lib_dest} | grep '(' | sed 's/\((.*)\)//'`; do
  90. local name=`basename ${linked_lib}`
  91. case "${linked_lib}" in
  92. */vlc_build_dir/* | */vlc_install_dir/* | *vlc* | */extras/contrib/lib/*)
  93. if test -e ${linked_lib}; then
  94. install_name_tool -change "$linked_lib" "${lib_install_prefix}/${name}" "${lib_dest}"
  95. linked_libs="${linked_libs} ${ref_lib}"
  96. vlc_install ${linked_lib} ${target_lib} "library"
  97. fi
  98. ;;
  99. esac
  100. done
  101. fi
  102. fi
  103. }
  104. # @function vlc_install
  105. ##########################
  106. ##########################
  107. # Hack for VLC-release.app
  108. if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
  109. vlc_install "${main_build_dir}/bin/${prefix}vlc" "${target}" "bin" "@loader_path/lib"
  110. mv ${target}/vlc ${target}/VLC
  111. chmod +x ${target}/VLC
  112. elif [ "$FULL_PRODUCT_NAME" = "VLC-Plugin.plugin" ] ; then
  113. # install Safari webplugin
  114. vlc_install "${main_build_dir}/projects/mozilla/${prefix}npvlc.${suffix}" "${target}" "library" "@loader_path/lib"
  115. mv ${target}/npvlc.${suffix} "${target}/VLC Plugin"
  116. chmod +x "${target}/VLC Plugin"
  117. else
  118. vlc_install "${main_build_dir}/bin/${prefix}vlc" "${target}/bin" "bin" "@loader_path/../lib"
  119. fi
  120. ##########################
  121. # Build the modules folder (Same as VLCKit.framework/modules in Makefile)
  122. echo "Building modules folder..."
  123. # Figure out what modules are available to install
  124. for module in `find ${main_build_dir}/modules -name *.${suffix}` ; do
  125. # Check to see that the reported module actually exists
  126. if test -n ${module}; then
  127. vlc_install ${module} ${target_modules} "module"
  128. fi
  129. done
  130. # Install the module cache
  131. vlc_install `ls ${main_build_dir}/modules/plugins-*.dat` ${target_modules} "data"
  132. # Build the modules folder
  133. ##########################
  134. ##########################
  135. # Create a symbolic link in the root of the framework
  136. mkdir -p ${target_lib}
  137. mkdir -p ${target_modules}
  138. if [ "$RELEASE_MAKEFILE" != "yes" ] ; then
  139. pushd `pwd` > /dev/null
  140. cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
  141. ln -sf Versions/Current/${lib} .
  142. ln -sf Versions/Current/${modules} .
  143. ln -sf Versions/Current/${include} .
  144. ln -sf Versions/Current/${share} .
  145. ln -sf Versions/Current/bin .
  146. ln -sf ../modules Versions/Current/bin
  147. ln -sf ../share Versions/Current/bin
  148. popd > /dev/null
  149. fi
  150. ##########################
  151. # Build the library folder
  152. echo "Building library folder... ${linked_libs}"
  153. for linked_lib in ${linked_libs} ; do
  154. case "${linked_lib}" in
  155. */extras/contrib/lib/*.dylib|*/vlc_install_dir/lib/*.dylib)
  156. if test -e ${linked_lib}; then
  157. vlc_install ${linked_lib} ${target_lib} "library"
  158. fi
  159. ;;
  160. esac
  161. done
  162. vlc_install "${main_build_dir}/src/${prefix}libvlc.5.dylib" "${target_lib}" "library"
  163. vlc_install "${main_build_dir}/src/${prefix}libvlccore.4.dylib" "${target_lib}" "library"
  164. pushd `pwd` > /dev/null
  165. cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}/lib
  166. ln -sf libvlc.5.dylib libvlc.dylib
  167. ln -sf libvlccore.4.dylib libvlccore.dylib
  168. popd > /dev/null
  169. ##########################
  170. # Build the share folder
  171. echo "Building share folder..."
  172. pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks"
  173. mkdir -p ${target_share}
  174. $pbxcp ${main_build_dir}/share/lua ${target_share}
  175. ##########################
  176. # Exporting headers
  177. if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
  178. echo "Exporting headers..."
  179. mkdir -p ${target_include}/vlc
  180. $pbxcp ${main_build_dir}/include/vlc/*.h ${target_include}/vlc
  181. else
  182. echo "Headers not needed for this product"
  183. fi