Pre-Compile.sh 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. TARGET_BUILD_DIR="${build_dir}"
  14. FULL_PRODUCT_NAME="${PRODUCT}"
  15. CONTENTS_FOLDER_PATH="${FULL_PRODUCT_NAME}/Contents/MacOS"
  16. VLC_BUILD_DIR="${build_dir}"
  17. VLC_SRC_DIR="${src_dir}"
  18. ACTION="build"
  19. RELEASE_MAKEFILE="yes"
  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. elif [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
  89. install_library "${VLC_BUILD_DIR}/src/${prefix}npvlc.${suffix}" "${target}" "bin" "@loader_path/lib"
  90. mv ${target}/npvlc.${suffix} "${target}/VLC Plugin.plugin"
  91. chmod +x "${target}/VLC Plugin.plugin"
  92. fi
  93. ##########################
  94. # Build the modules folder (Same as VLCKit.framework/modules in Makefile)
  95. echo "Building modules folder..."
  96. # Figure out what modules are available to install
  97. for module in `find ${VLC_BUILD_DIR}/modules -name *.${suffix}` ; do
  98. # Check to see that the reported module actually exists
  99. if test -n ${module}; then
  100. install_library ${module} ${target_modules} "module"
  101. fi
  102. done
  103. # Build the modules folder
  104. ##########################
  105. ##########################
  106. # Create a symbolic link in the root of the framework
  107. mkdir -p ${target_lib}
  108. mkdir -p ${target_modules}
  109. if [ "$RELEASE_MAKEFILE" != "yes" ] ; then
  110. pushd `pwd` > /dev/null
  111. cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
  112. ln -sf Versions/Current/${lib} .
  113. ln -sf Versions/Current/${modules} .
  114. ln -sf Versions/Current/${include} .
  115. ln -sf Versions/Current/${share} .
  116. popd > /dev/null
  117. fi
  118. ##########################
  119. # Build the library folder
  120. echo "Building library folder... ${linked_libs}"
  121. for linked_lib in ${linked_libs} ; do
  122. case "${linked_lib}" in
  123. */extras/contrib/lib/*.dylib|*/vlc_install_dir/lib/*.dylib)
  124. if test -e ${linked_lib}; then
  125. install_library ${linked_lib} ${target_lib} "library"
  126. fi
  127. ;;
  128. esac
  129. done
  130. install_library "${VLC_BUILD_DIR}/src/${prefix}libvlc.dylib" ${target_lib} "library"
  131. ##########################
  132. # Build the share folder
  133. echo "Building share folder..."
  134. pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks"
  135. mkdir -p ${target_share}
  136. $pbxcp ${VLC_SRC_DIR}/share/lua ${target_share}
  137. ##########################
  138. # Exporting headers
  139. echo "Exporting headers..."
  140. mkdir -p ${target_include}/vlc
  141. $pbxcp ${VLC_SRC_DIR}/include/vlc/*.h ${target_include}/vlc
  142. fi