Pre-Compile.sh 9.0 KB

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