Pre-Compile.sh 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. 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. 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 = "library" ]; then
  66. local install_name="@loader_path/lib"
  67. elif [ $type = "module" ]; then
  68. local install_name="@loader_path/plugins"
  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}" = "library" ]; 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/*)
  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 src_dir=$1
  125. local src=$2
  126. local dest_dir=$3
  127. local type=$4
  128. if test "$use_archs" = "no"; then
  129. vlc_install_object "$VLC_BUILD_DIR/$src_dir/$src" "$dest_dir" "$type" $5
  130. else
  131. if test $type = "data"; then
  132. vlc_install_object "$main_build_dir/$src_dir/$src" "$dest_dir" "$type" $5
  133. else
  134. fatdest="$dest_dir/$2"
  135. shouldUpdateFat="no"
  136. objects=""
  137. # Create a temporary destination dir to store each ARCH object file
  138. tmp_dest_dir="$VLC_BUILD_DIR/tmp/$type"
  139. rm -Rf "${tmp_dest_dir}/*"
  140. mkdir -p "$tmp_dest_dir"
  141. for arch in $ARCHS; do
  142. local arch_src="$VLC_BUILD_DIR/$arch/$src_dir/$src"
  143. # Only install if the new image is newer than the one we have installed.
  144. if ((! test -e ${fatdest}) || test ${arch_src} -nt ${fatdest} ); then
  145. vlc_install_object "$arch_src" "$tmp_dest_dir" "$type" "$5" "" ".$arch"
  146. local dest="$tmp_dest_dir/$src.$arch"
  147. if test -e ${dest}; then
  148. if (! test "$dest_dir/$arch_src" -nt "${dest}"); then
  149. shouldUpdateFat="yes"
  150. fi
  151. objects="${dest} $objects"
  152. else
  153. echo "Warning: building $arch_src without $arch"
  154. fi
  155. fi
  156. done;
  157. if test "$shouldUpdateFat" = "yes"; then
  158. echo "Creating fat $type $fatdest"
  159. lipo $objects -output "$fatdest" -create
  160. fi
  161. fi
  162. fi
  163. }
  164. # @function vlc_install
  165. ##########################
  166. ##########################
  167. # Create a symbolic link in the root of the framework
  168. mkdir -p ${target_lib}
  169. mkdir -p ${target_plugins}
  170. mkdir -p ${target_bin}
  171. if [ "$RELEASE_MAKEFILE" != "yes" ] ; then
  172. pushd `pwd` > /dev/null
  173. cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
  174. ln -sf Versions/Current/${lib} .
  175. ln -sf Versions/Current/${plugins} .
  176. ln -sf Versions/Current/${include} .
  177. ln -sf Versions/Current/${share} .
  178. ln -sf Versions/Current/bin .
  179. ln -sf ../plugins Versions/Current/bin
  180. ln -sf ../share Versions/Current/bin
  181. popd > /dev/null
  182. fi
  183. ##########################
  184. # Hack for VLC-release.app
  185. if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
  186. vlc_install "bin/${prefix}" "vlc" "${target}" "bin" "@loader_path/lib"
  187. mv ${target}/vlc ${target}/VLC
  188. chmod +x ${target}/VLC
  189. elif [ "$FULL_PRODUCT_NAME" = "VLC-Plugin.plugin" ] ; then
  190. # install Safari webplugin
  191. vlc_install "projects/mozilla/${prefix}" "npvlc.${suffix}" "${target}" "lib" "@loader_path/lib"
  192. mv ${target}/npvlc.${suffix} "${target}/VLC Plugin"
  193. chmod +x "${target}/VLC Plugin"
  194. else
  195. vlc_install "bin/${prefix}" "vlc" "${target}/bin" "bin" "@loader_path/../lib"
  196. fi
  197. ##########################
  198. # Build the plugins folder (Same as VLCKit.framework/plugins in Makefile)
  199. echo "Building plugins folder..."
  200. # Figure out what plugins are available to install
  201. 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
  202. # Check to see that the reported module actually exists
  203. if test -n ${module}; then
  204. vlc_install `dirname ${module}` `basename ${module}` ${target_plugins} "module"
  205. fi
  206. done
  207. ##########################
  208. # Install the module cache
  209. if test "$use_archs" = "no"; then
  210. cache=`ls ${main_build_dir}/modules/plugins-*.dat | sed -e s:${main_build_dir}/::`
  211. vlc_install `dirname ${cache}` `basename ${cache}` ${target_plugins} "data"
  212. else
  213. for arch in $ARCHS; do
  214. build="${VLC_BUILD_DIR}/${arch}"
  215. cache=`ls ${build}/modules/plugins-*.dat | sed -e s:${build}/::`
  216. # The cache is arch dependant. Use vlc_install_object directly.
  217. vlc_install_object "${cache}" "${target_plugins}" "data"
  218. done;
  219. fi
  220. ##########################
  221. # Build the lib folder
  222. vlc_install "src/${prefix}" "libvlc.5.dylib" "${target_lib}" "library"
  223. vlc_install "src/${prefix}" "libvlccore.5.dylib" "${target_lib}" "library"
  224. pushd `pwd` > /dev/null
  225. cd ${target_lib}
  226. ln -sf libvlc.5.dylib libvlc.dylib
  227. ln -sf libvlccore.5.dylib libvlccore.dylib
  228. popd > /dev/null
  229. ##########################
  230. # Build the share folder
  231. echo "Building share folder..."
  232. pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks"
  233. mkdir -p ${target_share}
  234. if test "$use_archs" = "no"; then
  235. $pbxcp ${VLC_BUILD_DIR}/share/lua ${target_share}
  236. else
  237. $pbxcp ${main_build_dir}/share/lua ${target_share}
  238. fi
  239. ##########################
  240. # Exporting headers
  241. if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
  242. echo "Exporting headers..."
  243. mkdir -p ${target_include}/vlc
  244. $pbxcp ${VLC_SRC_DIR}/include/vlc/*.h ${target_include}/vlc
  245. else
  246. echo "Headers not needed for this product"
  247. fi