Pre-Compile.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. if test "${ACTION}" = ""; then
  2. # Debug --
  3. TARGET_BUILD_DIR="."
  4. FULL_PRODUCT_NAME="VLCKit.framework"
  5. CONTENTS_FOLDER_PATH="${FULL_PRODUCT_NAME}/Versions/A"
  6. VLC_BUILD_DIR="../../.."
  7. VLC_SRC_DIR="../../.."
  8. ACTION="build"
  9. rm -fr ${FULL_PRODUCT_NAME}
  10. # Debug --
  11. # Hack to use that script with the current VLC-release.app
  12. elif 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. fi
  26. if test "${ACTION}" = "build"; then
  27. lib="lib"
  28. modules="modules"
  29. share="share"
  30. include="include"
  31. target="${TARGET_BUILD_DIR}/${CONTENTS_FOLDER_PATH}"
  32. target_lib="${target}/${lib}" # Should we consider using a different well-known folder like shared resources?
  33. target_modules="${target}/${modules}" # Should we consider using a different well-known folder like shared resources?
  34. target_share="${target}/${share}" # Should we consider using a different well-known folder like shared resources?
  35. target_include="${target}/${include}" # Should we consider using a different well-known folder like shared resources?
  36. linked_libs=""
  37. ##########################
  38. # @function install_library(src_lib, dest_dir, type, lib_install_prefix, destination_name)
  39. # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
  40. # @param src_lib source library to copy to the destination directory
  41. # @param dest_dir destination directory where the src_lib should be copied to
  42. install_library() {
  43. if [ ${3} = "library" ]; then
  44. local install_name="@loader_path/lib"
  45. elif [ ${3} = "module" ]; then
  46. local install_name="@loader_path/modules"
  47. fi
  48. if [ "${5}" != "" ]; then
  49. local lib_dest="${2}/${5}"
  50. else
  51. local lib_dest="${2}/`basename ${1}`"
  52. fi
  53. if [ "${4}" != "" ]; then
  54. local lib_install_prefix="${4}"
  55. else
  56. local lib_install_prefix="@loader_path/../lib"
  57. fi
  58. if test -e ${1} && ((! test -e ${lib_dest}) || test ${1} -nt ${lib_dest} ); then
  59. mkdir -p ${2}
  60. # Lets copy the library from the source folder to our new destination folder
  61. if [ "${3}" != "bin" ]; then
  62. install -m 644 ${1} ${lib_dest}
  63. else
  64. install -m 755 ${1} ${lib_dest}
  65. fi
  66. # Update the dynamic library so it will know where to look for the other libraries
  67. echo "Installing ${3} `basename ${lib_dest}`"
  68. if [ "${3}" != "bin" ]; then
  69. # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
  70. install_name_tool -id "${install_name}/`basename ${lib_dest}`" ${lib_dest} > /dev/null
  71. fi
  72. # Iterate through each installed library and modify the references to other dynamic libraries to match the framework's library directory
  73. for linked_lib in `otool -L ${lib_dest} | grep '(' | sed 's/\((.*)\)//'`; do
  74. local name=`basename ${linked_lib}`
  75. case "${linked_lib}" in
  76. */vlc_build_dir/* | */vlc_install_dir/* | *vlc* | */extras/contrib/lib/*)
  77. if test -e ${linked_lib}; then
  78. install_name_tool -change "$linked_lib" "${lib_install_prefix}/${name}" "${lib_dest}"
  79. linked_libs="${linked_libs} ${ref_lib}"
  80. install_library ${linked_lib} ${target_lib} "library"
  81. fi
  82. ;;
  83. esac
  84. done
  85. fi
  86. }
  87. # @function install_library
  88. ##########################
  89. prefix=".libs/"
  90. suffix="dylib"
  91. ##########################
  92. # Hack for VLC-release.app
  93. if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
  94. install_library "${VLC_BUILD_DIR}/bin/${prefix}vlc" "${target}" "bin" "@loader_path/lib"
  95. mv ${target}/vlc ${target}/VLC
  96. chmod +x ${target}/VLC
  97. elif [ "$FULL_PRODUCT_NAME" = "VLC-Plugin.plugin" ] ; then
  98. # install Safari webplugin
  99. install_library "${VLC_BUILD_DIR}/projects/mozilla/${prefix}npvlc.${suffix}" "${target}" "library" "@loader_path/lib"
  100. mv ${target}/npvlc.${suffix} "${target}/VLC Plugin"
  101. chmod +x "${target}/VLC Plugin"
  102. else
  103. install_library "${VLC_BUILD_DIR}/bin/${prefix}vlc" "${target}/bin" "bin" "@loader_path/../lib"
  104. fi
  105. ##########################
  106. # Build the modules folder (Same as VLCKit.framework/modules in Makefile)
  107. echo "Building modules folder..."
  108. # Figure out what modules are available to install
  109. for module in `find ${VLC_BUILD_DIR}/modules -name *.${suffix}` ; do
  110. # Check to see that the reported module actually exists
  111. if test -n ${module}; then
  112. install_library ${module} ${target_modules} "module"
  113. fi
  114. done
  115. # Build the modules folder
  116. ##########################
  117. ##########################
  118. # Create a symbolic link in the root of the framework
  119. mkdir -p ${target_lib}
  120. mkdir -p ${target_modules}
  121. if [ "$RELEASE_MAKEFILE" != "yes" ] ; then
  122. pushd `pwd` > /dev/null
  123. cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
  124. ln -sf Versions/Current/${lib} .
  125. ln -sf Versions/Current/${modules} .
  126. ln -sf Versions/Current/${include} .
  127. ln -sf Versions/Current/${share} .
  128. ln -sf Versions/Current/bin .
  129. popd > /dev/null
  130. fi
  131. # remove stuff we don't need
  132. if [ "$FULL_PRODUCT_NAME" = "VLCKit.framework" ] ; then
  133. echo "Removing module libmacosx_plugin.dylib"
  134. rm ${target_modules}/libmacosx_plugin.dylib
  135. fi
  136. ##########################
  137. # Build the library folder
  138. echo "Building library folder... ${linked_libs}"
  139. for linked_lib in ${linked_libs} ; do
  140. case "${linked_lib}" in
  141. */extras/contrib/lib/*.dylib|*/vlc_install_dir/lib/*.dylib)
  142. if test -e ${linked_lib}; then
  143. install_library ${linked_lib} ${target_lib} "library"
  144. fi
  145. ;;
  146. esac
  147. done
  148. install_library "${VLC_BUILD_DIR}/src/${prefix}libvlc.dylib" "${target_lib}" "library"
  149. ##########################
  150. # Build the share folder
  151. echo "Building share folder..."
  152. pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks"
  153. mkdir -p ${target_share}
  154. $pbxcp ${VLC_SRC_DIR}/share/lua ${target_share}
  155. ##########################
  156. # Exporting headers
  157. if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
  158. echo "Exporting headers..."
  159. mkdir -p ${target_include}/vlc
  160. $pbxcp ${VLC_SRC_DIR}/include/vlc/*.h ${target_include}/vlc
  161. else
  162. echo "Headers not needed for this product"
  163. fi
  164. fi