Pre-Compile.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. fi
  12. # Hack to use that script with the current VLC-release.app
  13. if test "${ACTION}" = "VLC-release.app"; then
  14. TARGET_BUILD_DIR="${build_dir}"
  15. FULL_PRODUCT_NAME="VLC-release.app"
  16. CONTENTS_FOLDER_PATH="${FULL_PRODUCT_NAME}/Contents/MacOS"
  17. VLC_BUILD_DIR="${build_dir}"
  18. VLC_SRC_DIR="${src_dir}"
  19. ACTION="build"
  20. fi
  21. if test "${ACTION}" = "build"; then
  22. lib="lib"
  23. modules="modules"
  24. share="share"
  25. target="${TARGET_BUILD_DIR}/${CONTENTS_FOLDER_PATH}"
  26. target_lib="${target}/${lib}" # Should we consider using a different well-known folder like shared resources?
  27. target_modules="${target}/${modules}" # Should we consider using a different well-known folder like shared resources?
  28. target_share="${target}/${share}" # Should we consider using a different well-known folder like shared resources?
  29. linked_libs=" "
  30. ##########################
  31. # @function install_library(src_lib, dest_dir, type, lib_install_prefix, destination_name)
  32. # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
  33. # @param src_lib source library to copy to the destination directory
  34. # @param dest_dir destination directory where the src_lib should be copied to
  35. install_library() {
  36. if [ ${3} = "library" ]; then
  37. local install_name="@loader_path/lib"
  38. elif [ ${3} = "module" ]; then
  39. local install_name="@loader_path/modules"
  40. fi
  41. if [ "${5}" != "" ]; then
  42. local lib_dest="${2}/${5}"
  43. else
  44. local lib_dest="${2}/`basename ${1}`"
  45. fi
  46. if [ "${4}" != "" ]; then
  47. local lib_install_prefix="${4}"
  48. else
  49. local lib_install_prefix="@loader_path/../lib"
  50. fi
  51. if test -e ${1} && ((! test -e ${lib_dest}) || test ${1} -nt ${lib_dest} ); then
  52. mkdir -p ${2}
  53. # Lets copy the library from the source folder to our new destination folder
  54. install -m 644 ${1} ${lib_dest}
  55. # Update the dynamic library so it will know where to look for the other libraries
  56. echo "Installing ${3} `basename ${lib_dest}`"
  57. if [ "${3}" != "bin" ]; then
  58. # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
  59. install_name_tool -id "${install_name}/`basename ${lib_dest}`" ${lib_dest} > /dev/null
  60. fi
  61. # Iterate through each installed library and modify the references to other dynamic libraries to match the framework's library directory
  62. for linked_lib in `otool -L ${lib_dest} | grep '(' | sed 's/\((.*)\)//'`; do
  63. local name=`basename ${linked_lib}`
  64. case "${linked_lib}" in
  65. */vlc_build_dir/* | *vlc* | */extras/contrib/lib/*)
  66. if test -e ${linked_lib}; then
  67. install_name_tool -change "$linked_lib" "${lib_install_prefix}/${name}" "${lib_dest}"
  68. linked_libs="${linked_libs} ${ref_lib}"
  69. install_library ${linked_lib} ${target_lib} "library"
  70. fi
  71. ;;
  72. esac
  73. done
  74. fi
  75. }
  76. # @function install_library
  77. ##########################
  78. prefix=".libs/"
  79. suffix="dylib"
  80. ##########################
  81. # Hack for VLC-release.app
  82. if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
  83. install_library "${VLC_BUILD_DIR}/src/${prefix}vlc" "${target}" "bin" "@loader_path/lib"
  84. mv ${target}/vlc ${target}/VLC
  85. chmod +x ${target}/VLC
  86. fi
  87. ##########################
  88. # Build the modules folder (Same as VLCKit.framework/modules in Makefile)
  89. echo "Building modules folder..."
  90. # Figure out what modules are available to install
  91. for module in `find ${VLC_BUILD_DIR}/modules -name *.${suffix}` ; do
  92. # Check to see that the reported module actually exists
  93. if test -n ${module}; then
  94. install_library ${module} ${target_modules} "module"
  95. fi
  96. done
  97. # Build the modules folder
  98. ##########################
  99. ##########################
  100. # Create a symbolic link in the root of the framework
  101. mkdir -p ${target_lib}
  102. mkdir -p ${target_modules}
  103. if [ "$FULL_PRODUCT_NAME" != "VLC-release.app" ] ; then
  104. pushd `pwd` > /dev/null
  105. cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
  106. ln -sf Versions/Current/${lib} .
  107. ln -sf Versions/Current/${modules} .
  108. popd > /dev/null
  109. fi
  110. ##########################
  111. # Build the library folder
  112. echo "Building library folder... ${linked_libs}"
  113. for linked_lib in ${linked_libs} ; do
  114. case "${linked_lib}" in
  115. */extras/contrib/lib/*.dylib|*/vlc_install_dir/lib/*.dylib)
  116. if test -e ${linked_lib}; then
  117. install_library ${linked_lib} ${target_lib} "library"
  118. fi
  119. ;;
  120. esac
  121. done
  122. install_library "${VLC_BUILD_DIR}/src/${prefix}libvlc.dylib" ${target_lib} "library"
  123. ##########################
  124. # Build the share folder
  125. echo "Building share folder..."
  126. pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks"
  127. mkdir -p ${target_share}
  128. $pbxcp ${VLC_SRC_DIR}/share/lua ${target_share}
  129. fi