Pre-Compile.sh 6.1 KB

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