5 # Script that install libvlc and its modules inside VLCKit.
7 # This is for some creepy reasons also used by legacy VLC-release.app or
12 # We are building VLC-release.app or the moz plugin
14 if test "${ACTION}" = "release-makefile"; then
15 echo "running Pre-Compile.sh in release-makefile mode"
17 FULL_PRODUCT_NAME="${PRODUCT}"
18 if [ "$FULL_PRODUCT_NAME" = "VLC-Plugin.plugin" ] ; then
19 TARGET_BUILD_DIR="${src_dir}"
21 TARGET_BUILD_DIR="${build_dir}"
23 CONTENTS_FOLDER_PATH="${FULL_PRODUCT_NAME}/Contents/MacOS"
24 VLC_BUILD_DIR="${build_dir}"
25 VLC_SRC_DIR="${src_dir}"
27 RELEASE_MAKEFILE="yes"
29 main_build_dir="${VLC_BUILD_DIR}"
32 main_build_dir="${VLC_BUILD_DIR}/x86_64"
35 if test "${ACTION}" != "build"; then
36 echo "This script is supposed to run from xcodebuild or Xcode"
44 target="${TARGET_BUILD_DIR}/${CONTENTS_FOLDER_PATH}"
45 target_lib="${target}/${lib}" # Should we consider using a different well-known folder like shared resources?
46 target_modules="${target}/${modules}" # Should we consider using a different well-known folder like shared resources?
47 target_share="${target}/${share}" # Should we consider using a different well-known folder like shared resources?
48 target_include="${target}/${include}" # Should we consider using a different well-known folder like shared resources?
54 ##########################
55 # @function vlc_install(src_lib, dest_dir, type, lib_install_prefix, destination_name)
56 # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
57 # @param src_lib source library to copy to the destination directory
58 # @param dest_dir destination directory where the src_lib should be copied to
64 local lib_install_prefix=${4}
65 local destination_name=${5}
67 if [ $type = "library" ]; then
68 local install_name="@loader_path/lib"
69 elif [ $type = "module" ]; then
70 local install_name="@loader_path/modules"
72 if [ "$destination_name" != "" ]; then
73 local lib_dest="$dest_dir/$destination_name"
75 local lib_dest="$dest_dir/`basename $src_lib`"
78 if [ "$lib_install_prefix" != "" ]; then
79 local lib_install_prefix="$lib_install_prefix"
81 local lib_install_prefix="@loader_path/../lib"
84 if test -e ${src_lib} && ((! test -e ${lib_dest}) || test ${src_lib} -nt ${lib_dest} ); then
88 # Lets copy the library from the source folder to our new destination folder
89 if [ "${type}" = "bin" ]; then
90 install -m 755 ${src_lib} ${lib_dest}
92 install -m 644 ${src_lib} ${lib_dest}
95 # Update the dynamic library so it will know where to look for the other libraries
96 echo "Installing ${type} `basename ${lib_dest}`"
98 if [ "${type}" = "lib" ]; then
99 # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
100 install_name_tool -id "${install_name}/`basename ${lib_dest}`" ${lib_dest} > /dev/null
103 if [ "${type}" != "data" ]; then
104 # Iterate through each installed library and modify the references to other dynamic libraries to match the framework's library directory
105 for linked_lib in `otool -L ${lib_dest} | grep '(' | sed 's/\((.*)\)//'`; do
106 local name=`basename ${linked_lib}`
107 case "${linked_lib}" in
108 */vlc_build_dir/* | */vlc_install_dir/* | *vlc* | */extras/contrib/lib/*)
109 if test -e ${linked_lib}; then
110 install_name_tool -change "$linked_lib" "${lib_install_prefix}/${name}" "${lib_dest}"
111 linked_libs="${linked_libs} ${ref_lib}"
112 vlc_install ${linked_lib} ${target_lib} "library"
120 # @function vlc_install
121 ##########################
123 ##########################
124 # Hack for VLC-release.app
125 if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
126 vlc_install "${main_build_dir}/bin/${prefix}vlc" "${target}" "bin" "@loader_path/lib"
127 mv ${target}/vlc ${target}/VLC
128 chmod +x ${target}/VLC
129 elif [ "$FULL_PRODUCT_NAME" = "VLC-Plugin.plugin" ] ; then
130 # install Safari webplugin
131 vlc_install "${main_build_dir}/projects/mozilla/${prefix}npvlc.${suffix}" "${target}" "library" "@loader_path/lib"
132 mv ${target}/npvlc.${suffix} "${target}/VLC Plugin"
133 chmod +x "${target}/VLC Plugin"
135 vlc_install "${main_build_dir}/bin/${prefix}vlc" "${target}/bin" "bin" "@loader_path/../lib"
138 ##########################
139 # Build the modules folder (Same as VLCKit.framework/modules in Makefile)
140 echo "Building modules folder..."
141 # Figure out what modules are available to install
142 for module in `find ${main_build_dir}/modules -name *.${suffix}` ; do
143 # Check to see that the reported module actually exists
144 if test -n ${module}; then
145 vlc_install ${module} ${target_modules} "module"
149 # Install the module cache
150 vlc_install `ls ${main_build_dir}/modules/plugins-*.dat` ${target_modules} "data"
152 # Build the modules folder
153 ##########################
155 ##########################
156 # Create a symbolic link in the root of the framework
157 mkdir -p ${target_lib}
158 mkdir -p ${target_modules}
160 if [ "$RELEASE_MAKEFILE" != "yes" ] ; then
161 pushd `pwd` > /dev/null
162 cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
164 ln -sf Versions/Current/${lib} .
165 ln -sf Versions/Current/${modules} .
166 ln -sf Versions/Current/${include} .
167 ln -sf Versions/Current/${share} .
168 ln -sf Versions/Current/bin .
169 ln -sf ../modules Versions/Current/bin
170 ln -sf ../share Versions/Current/bin
175 ##########################
176 # Build the library folder
177 echo "Building library folder... ${linked_libs}"
178 for linked_lib in ${linked_libs} ; do
179 case "${linked_lib}" in
180 */extras/contrib/lib/*.dylib|*/vlc_install_dir/lib/*.dylib)
181 if test -e ${linked_lib}; then
182 vlc_install ${linked_lib} ${target_lib} "library"
188 vlc_install "${main_build_dir}/src/${prefix}libvlc.5.dylib" "${target_lib}" "library"
189 vlc_install "${main_build_dir}/src/${prefix}libvlccore.4.dylib" "${target_lib}" "library"
190 pushd `pwd` > /dev/null
191 cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}/lib
192 ln -sf libvlc.5.dylib libvlc.dylib
193 ln -sf libvlccore.4.dylib libvlccore.dylib
196 ##########################
197 # Build the share folder
198 echo "Building share folder..."
199 pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks"
200 mkdir -p ${target_share}
201 $pbxcp ${main_build_dir}/share/lua ${target_share}
204 ##########################
206 if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
207 echo "Exporting headers..."
208 mkdir -p ${target_include}/vlc
209 $pbxcp ${main_build_dir}/include/vlc/*.h ${target_include}/vlc
211 echo "Headers not needed for this product"