Pre-Compile.sh 8.8 KB

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