Pre-Compile.sh 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. echo "Building for $ARCHS"
  31. fi
  32. if test "${ACTION}" = "clean"; then
  33. rm -Rf "${VLC_BUILD_DIR}/tmp"
  34. exit 0
  35. fi
  36. if test "${ACTION}" != "build"; then
  37. echo "This script is supposed to run from xcodebuild or Xcode"
  38. exit 1
  39. fi
  40. lib="lib"
  41. modules="modules"
  42. share="share"
  43. include="include"
  44. target="${TARGET_BUILD_DIR}/${CONTENTS_FOLDER_PATH}"
  45. target_bin="${target}/bin"
  46. target_lib="${target}/${lib}" # Should we consider using a different well-known folder like shared resources?
  47. target_modules="${target}/${modules}" # Should we consider using a different well-known folder like shared resources?
  48. target_share="${target}/${share}" # Should we consider using a different well-known folder like shared resources?
  49. target_include="${target}/${include}" # Should we consider using a different well-known folder like shared resources?
  50. linked_libs=""
  51. prefix=".libs/"
  52. suffix="dylib"
  53. ##########################
  54. # @function vlc_install_object(src_lib, dest_dir, type, lib_install_prefix, destination_name, suffix)
  55. # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
  56. # @param src_lib source library to copy to the destination directory
  57. # @param dest_dir destination directory where the src_lib should be copied to
  58. vlc_install_object() {
  59. local src_lib=${1}
  60. local dest_dir=${2}
  61. local type=${3}
  62. local lib_install_prefix=${4}
  63. local destination_name=${5}
  64. local suffix=${6}
  65. if [ $type = "lib" ]; then
  66. local install_name="@loader_path/lib"
  67. elif [ $type = "module" ]; then
  68. local install_name="@loader_path/modules"
  69. fi
  70. if [ "$destination_name" != "" ]; then
  71. local lib_dest="$dest_dir/$destination_name$suffix"
  72. local lib_name=`basename $destination_name`
  73. else
  74. local lib_dest="$dest_dir/`basename $src_lib`$suffix"
  75. local lib_name=`basename $src_lib`
  76. fi
  77. if [ "x$lib_install_prefix" != "x" ]; then
  78. local lib_install_prefix="$lib_install_prefix"
  79. else
  80. local lib_install_prefix="@loader_path/../lib"
  81. fi
  82. if ! test -e ${src_lib}; then
  83. return
  84. fi
  85. if ((! test -e ${lib_dest}) || test ${src_lib} -nt ${lib_dest} ); then
  86. mkdir -p ${dest_dir}
  87. # Lets copy the library from the source folder to our new destination folder
  88. if [ "${type}" = "bin" ]; then
  89. install -m 755 ${src_lib} ${lib_dest}
  90. else
  91. install -m 644 ${src_lib} ${lib_dest}
  92. fi
  93. # Update the dynamic library so it will know where to look for the other libraries
  94. echo "Installing ${type} `basename ${lib_dest}`"
  95. if [ "${type}" = "lib" ]; then
  96. # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
  97. install_name_tool -id "${install_name}/${lib_name}" ${lib_dest} > /dev/null
  98. fi
  99. if [ "${type}" != "data" ]; then
  100. # Iterate through each installed library and modify the references to other dynamic libraries to match the framework's library directory
  101. for linked_lib in `otool -L ${lib_dest} | grep '(' | sed 's/\((.*)\)//'`; do
  102. local name=`basename ${linked_lib}`
  103. case "${linked_lib}" in
  104. */vlc_build_dir/* | */vlc_install_dir/* | *vlc* | */extras/contrib/lib/*)
  105. if test -e ${linked_lib}; then
  106. install_name_tool -change "$linked_lib" "${lib_install_prefix}/${name}" "${lib_dest}"
  107. linked_libs="${linked_libs} ${ref_lib}"
  108. vlc_install_object ${linked_lib} ${target_lib} "library"
  109. fi
  110. ;;
  111. esac
  112. done
  113. fi
  114. fi
  115. }
  116. # @function vlc_install
  117. ##########################
  118. ##########################
  119. # @function vlc_install(src_lib_dir, src_lib_name, dest_dir, type, lib_install_prefix)
  120. # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
  121. # @param src_lib source library to copy to the destination directory
  122. # @param dest_dir destination directory where the src_lib should be copied to
  123. vlc_install() {
  124. local dest_dir=$3
  125. local type=$4
  126. if test "$use_archs" = "no"; then
  127. vlc_install_object "$VLC_BUILD_DIR/$1/$2" "$dest_dir" "$type" $5
  128. else
  129. if test $type = "data"; then
  130. vlc_install_object "$main_build_dir/$1/$2" "$dest_dir" "$type" $5
  131. else
  132. objects=""
  133. tmp_dest_dir="$VLC_BUILD_DIR/tmp/$type"
  134. mkdir -p "$tmp_dest_dir"
  135. newinstall="no"
  136. for arch in $ARCHS; do
  137. vlc_install_object "$VLC_BUILD_DIR/$arch/$1/$2" "$tmp_dest_dir" "$type" "$5" "" ".$arch"
  138. local dest="$tmp_dest_dir/$2.$arch"
  139. if test -e ${dest}; then
  140. if ! test "$dest_dir/$2" -nt "${dest}"; then
  141. newinstall="yes"
  142. fi
  143. objects="${dest} $objects"
  144. else
  145. echo "Warning: building $2 without $arch"
  146. fi
  147. done;
  148. if test "$newinstall" = "yes"; then
  149. echo "Creating fat $type $dest_dir/$2"
  150. lipo $objects -output "$dest_dir/$2" -create
  151. fi
  152. fi
  153. fi
  154. }
  155. # @function vlc_install
  156. ##########################
  157. ##########################
  158. # Create a symbolic link in the root of the framework
  159. mkdir -p ${target_lib}
  160. mkdir -p ${target_modules}
  161. mkdir -p ${target_bin}
  162. if [ "$RELEASE_MAKEFILE" != "yes" ] ; then
  163. pushd `pwd` > /dev/null
  164. cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
  165. ln -sf Versions/Current/${lib} .
  166. ln -sf Versions/Current/${modules} .
  167. ln -sf Versions/Current/${include} .
  168. ln -sf Versions/Current/${share} .
  169. ln -sf Versions/Current/bin .
  170. ln -sf ../modules Versions/Current/bin
  171. ln -sf ../share Versions/Current/bin
  172. popd > /dev/null
  173. fi
  174. ##########################
  175. # Hack for VLC-release.app
  176. if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
  177. vlc_install "bin/${prefix}" "vlc" "${target}" "bin" "@loader_path/lib"
  178. mv ${target}/vlc ${target}/VLC
  179. chmod +x ${target}/VLC
  180. elif [ "$FULL_PRODUCT_NAME" = "VLC-Plugin.plugin" ] ; then
  181. # install Safari webplugin
  182. vlc_install "projects/mozilla/${prefix}" "npvlc.${suffix}" "${target}" "lib" "@loader_path/lib"
  183. mv ${target}/npvlc.${suffix} "${target}/VLC Plugin"
  184. chmod +x "${target}/VLC Plugin"
  185. else
  186. vlc_install "bin/${prefix}" "vlc" "${target}/bin" "bin" "@loader_path/../lib"
  187. fi
  188. ##########################
  189. # Build the modules folder (Same as VLCKit.framework/modules in Makefile)
  190. echo "Building modules folder..."
  191. # Figure out what modules are available to install
  192. for module in `find ${main_build_dir}/modules -path "*dylib.dSYM*" -prune -o -name "lib*_plugin.dylib" -print | sed -e s:${main_build_dir}/::` ; do
  193. # Check to see that the reported module actually exists
  194. if test -n ${module}; then
  195. vlc_install `dirname ${module}` `basename ${module}` ${target_modules} "module"
  196. fi
  197. done
  198. # Install the module cache
  199. cache=`ls ${main_build_dir}/modules/plugins-*.dat | sed -e s:${main_build_dir}/::`
  200. vlc_install `dirname ${cache}` `basename ${cache}` ${target_modules} "data"
  201. # Build the lib folder
  202. ##########################
  203. vlc_install "src/${prefix}" "libvlc.5.dylib" "${target_lib}" "lib"
  204. vlc_install "src/${prefix}" "libvlccore.4.dylib" "${target_lib}" "lib"
  205. pushd `pwd` > /dev/null
  206. cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}/lib
  207. ln -sf libvlc.5.dylib libvlc.dylib
  208. ln -sf libvlccore.4.dylib libvlccore.dylib
  209. popd > /dev/null
  210. ##########################
  211. # Build the share folder
  212. echo "Building share folder..."
  213. pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks"
  214. mkdir -p ${target_share}
  215. $pbxcp ${main_build_dir}/share/lua ${target_share}
  216. ##########################
  217. # Exporting headers
  218. if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
  219. echo "Exporting headers..."
  220. mkdir -p ${target_include}/vlc
  221. $pbxcp ${main_build_dir}/include/vlc/*.h ${target_include}/vlc
  222. else
  223. echo "Headers not needed for this product"
  224. fi