Pre-Compile.sh 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. if test "${ACTION}" = "build"; then
  13. vlc_config="${VLC_SRC_DIR}/vlc-config"
  14. lib="lib"
  15. modules="modules"
  16. target="${TARGET_BUILD_DIR}/${CONTENTS_FOLDER_PATH}"
  17. target_lib="${target}/${lib}" # Should we consider using a different well-known folder like shared resources?
  18. target_modules="${target}/${modules}" # Should we consider using a different well-known folder like shared resources?
  19. linked_libs=" "
  20. ##########################
  21. # @function install_library(src_lib, dest_dir)
  22. # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
  23. # @param src_lib source library to copy to the destination directory
  24. # @param dest_dir destination directory where the src_lib should be copied to
  25. install_library() {
  26. if [ ${3} = "library" ]; then
  27. install_name="@loader_path/lib"
  28. else
  29. install_name="@loader_path/modules"
  30. fi
  31. if [ "${4}" != "" ]; then
  32. lib_dest="${2}/${4}"
  33. else
  34. lib_dest="${2}/`basename ${1}`"
  35. fi
  36. if test -e ${1} && ((! test -e ${lib_dest}) || test ${1} -nt ${lib_dest} ); then
  37. mkdir -p ${2}
  38. # Lets copy the library from the source folder to our new destination folder
  39. cp ${1} ${lib_dest}
  40. # Update the dynamic library so it will know where to look for the other libraries
  41. echo "Installing ${3} `basename ${lib_dest}`"
  42. # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
  43. install_name_tool -change /usr/local/lib/libvlc.1.dylib @loader_path/../lib/libvlc.dylib ${lib_dest}
  44. install_name_tool -change @executable_path/lib/vlc_libintl.dylib @loader_path/../lib/vlc_libintl.dylib ${lib_dest}
  45. install_name_tool -id "${install_name}/`basename ${lib_dest}`" ${lib_dest}
  46. # Iterate through each installed library and modify the references to other dynamic libraries to match the framework's library directory
  47. for linked_lib in `otool -L ${lib_dest} | grep '(' | sed 's/\((.*)\)//'`; do
  48. ref_lib=`echo "${linked_lib}" | sed 's:executable_path/:loader_path/../:'`
  49. if test "${ref_lib}" != "${linked_lib}"; then
  50. install_name_tool -change ${linked_lib} ${ref_lib} ${lib_dest}
  51. fi
  52. if test `echo "${ref_lib}" | grep "^@loader_path"`; then
  53. linked_libs="${linked_libs} ${ref_lib}"
  54. fi;
  55. done
  56. fi
  57. }
  58. # @function install_library
  59. ##########################
  60. ##########################
  61. # Build the modules folder (Same as VLCKit.framework/modules in Makefile)
  62. echo "Building modules folder..."
  63. # Figure out what modules are available to install
  64. for module in `top_builddir="${VLC_BUILD_DIR}" ${vlc_config} --target plugin` ; do
  65. # Check to see that the reported module actually exists
  66. if test -n ${module}; then
  67. module_src="`dirname ${module}`/.libs/`basename ${module}`.dylib"
  68. install_library ${module_src} ${target_modules} "module"
  69. fi
  70. done
  71. # Build the modules folder
  72. ##########################
  73. ##########################
  74. # Create a symbolic link in the root of the framework
  75. mkdir -p ${target_lib}
  76. mkdir -p ${target_modules}
  77. pushd `pwd` > /dev/null
  78. cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
  79. ln -sf Versions/Current/${lib} .
  80. ln -sf Versions/Current/${modules} .
  81. popd > /dev/null
  82. # Create a symbolic link in the root of the framework
  83. ##########################
  84. ##########################
  85. # Build the library folder (Same as VLCKit.framework/lib in Makefile)
  86. echo "Building library folder..."
  87. for linked_lib in ${linked_libs} ; do
  88. case "${linked_lib}" in
  89. @loader_path/../lib/*)
  90. ref_lib=`echo ${linked_lib} | sed 's:@loader_path/../lib/::'`
  91. if test -e ${VLC_BUILD_DIR}/extras/contrib/vlc-lib/${ref_lib}; then
  92. src_lib=${VLC_BUILD_DIR}/extras/contrib/vlc-lib/${ref_lib}
  93. elif test -e ${VLC_BUILD_DIR}/src/.libs/${ref_lib}; then
  94. src_lib=${VLC_BUILD_DIR}/src/.libs/${ref_lib}
  95. fi
  96. install_library ${src_lib} ${target_lib} "library"
  97. ;;
  98. esac
  99. done
  100. # Build the library folder
  101. ##########################
  102. install_library "${VLC_BUILD_DIR}/src/.libs/libvlc-control.dylib" ${target_lib} "library"
  103. fi