Pre-Compile.sh 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. install -m 644 ${1} ${lib_dest}
  62. # Update the dynamic library so it will know where to look for the other libraries
  63. echo "Installing ${3} `basename ${lib_dest}`"
  64. if [ "${3}" != "bin" ]; then
  65. # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
  66. install_name_tool -id "${install_name}/`basename ${lib_dest}`" ${lib_dest} > /dev/null
  67. fi
  68. # Iterate through each installed library and modify the references to other dynamic libraries to match the framework's library directory
  69. for linked_lib in `otool -L ${lib_dest} | grep '(' | sed 's/\((.*)\)//'`; do
  70. local name=`basename ${linked_lib}`
  71. case "${linked_lib}" in
  72. */vlc_build_dir/* | */vlc_install_dir/* | *vlc* | */extras/contrib/lib/*)
  73. if test -e ${linked_lib}; then
  74. install_name_tool -change "$linked_lib" "${lib_install_prefix}/${name}" "${lib_dest}"
  75. linked_libs="${linked_libs} ${ref_lib}"
  76. install_library ${linked_lib} ${target_lib} "library"
  77. fi
  78. ;;
  79. esac
  80. done
  81. fi
  82. }
  83. # @function install_library
  84. ##########################
  85. prefix=".libs/"
  86. suffix="dylib"
  87. ##########################
  88. # Hack for VLC-release.app
  89. if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
  90. install_library "${VLC_BUILD_DIR}/bin/${prefix}vlc" "${target}" "bin" "@loader_path/lib"
  91. mv ${target}/vlc ${target}/VLC
  92. chmod +x ${target}/VLC
  93. elif [ "$FULL_PRODUCT_NAME" = "VLC-Plugin.plugin" ] ; then
  94. # install Safari webplugin
  95. install_library "${VLC_BUILD_DIR}/projects/mozilla/${prefix}npvlc.${suffix}" "${target}" "library" "@loader_path/lib"
  96. mv ${target}/npvlc.${suffix} "${target}/VLC Plugin"
  97. chmod +x "${target}/VLC Plugin"
  98. fi
  99. ##########################
  100. # Build the modules folder (Same as VLCKit.framework/modules in Makefile)
  101. echo "Building modules folder..."
  102. # Figure out what modules are available to install
  103. for module in `find ${VLC_BUILD_DIR}/modules -name *.${suffix}` ; do
  104. # Check to see that the reported module actually exists
  105. if test -n ${module}; then
  106. install_library ${module} ${target_modules} "module"
  107. fi
  108. done
  109. # Build the modules folder
  110. ##########################
  111. ##########################
  112. # Create a symbolic link in the root of the framework
  113. mkdir -p ${target_lib}
  114. mkdir -p ${target_modules}
  115. if [ "$RELEASE_MAKEFILE" != "yes" ] ; then
  116. pushd `pwd` > /dev/null
  117. cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
  118. ln -sf Versions/Current/${lib} .
  119. ln -sf Versions/Current/${modules} .
  120. ln -sf Versions/Current/${include} .
  121. ln -sf Versions/Current/${share} .
  122. popd > /dev/null
  123. fi
  124. # remove stuff we don't need
  125. if [ "$FULL_PRODUCT_NAME" = "VLCKit.framework" ] ; then
  126. echo "Removing module libmacosx_plugin.dylib"
  127. rm ${target_modules}/libmacosx_plugin.dylib
  128. fi
  129. ##########################
  130. # Build the library folder
  131. echo "Building library folder... ${linked_libs}"
  132. for linked_lib in ${linked_libs} ; do
  133. case "${linked_lib}" in
  134. */extras/contrib/lib/*.dylib|*/vlc_install_dir/lib/*.dylib)
  135. if test -e ${linked_lib}; then
  136. install_library ${linked_lib} ${target_lib} "library"
  137. fi
  138. ;;
  139. esac
  140. done
  141. install_library "${VLC_BUILD_DIR}/src/${prefix}libvlc.dylib" "${target_lib}" "library"
  142. ##########################
  143. # Build the share folder
  144. echo "Building share folder..."
  145. pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks"
  146. mkdir -p ${target_share}
  147. $pbxcp ${VLC_SRC_DIR}/share/lua ${target_share}
  148. ##########################
  149. # Exporting headers
  150. if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
  151. echo "Exporting headers..."
  152. mkdir -p ${target_include}/vlc
  153. $pbxcp ${VLC_SRC_DIR}/include/vlc/*.h ${target_include}/vlc
  154. else
  155. echo "Headers not needed for this product"
  156. fi
  157. fi