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"
30 if test "${ACTION}" != "build"; then
31 echo "This script is supposed to run from xcodebuild or Xcode"
39 target="${TARGET_BUILD_DIR}/${CONTENTS_FOLDER_PATH}"
40 target_lib="${target}/${lib}" # Should we consider using a different well-known folder like shared resources?
41 target_modules="${target}/${modules}" # Should we consider using a different well-known folder like shared resources?
42 target_share="${target}/${share}" # Should we consider using a different well-known folder like shared resources?
43 target_include="${target}/${include}" # Should we consider using a different well-known folder like shared resources?
49 ##########################
50 # @function vlc_install(src_lib, dest_dir, type, lib_install_prefix, destination_name)
51 # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
52 # @param src_lib source library to copy to the destination directory
53 # @param dest_dir destination directory where the src_lib should be copied to
59 local lib_install_prefix=${4}
60 local destination_name=${5}
62 if [ $type = "library" ]; then
63 local install_name="@loader_path/lib"
64 elif [ $type = "module" ]; then
65 local install_name="@loader_path/modules"
67 if [ "$destination_name" != "" ]; then
68 local lib_dest="$dest_dir/$destination_name"
70 local lib_dest="$dest_dir/`basename $src_lib`"
73 if [ "$lib_install_prefix" != "" ]; then
74 local lib_install_prefix="$lib_install_prefix"
76 local lib_install_prefix="@loader_path/../lib"
79 if test -e ${src_lib} && ((! test -e ${lib_dest}) || test ${src_lib} -nt ${lib_dest} ); then
83 # Lets copy the library from the source folder to our new destination folder
84 if [ "${type}" = "bin" ]; then
85 install -m 755 ${src_lib} ${lib_dest}
87 install -m 644 ${src_lib} ${lib_dest}
90 # Update the dynamic library so it will know where to look for the other libraries
91 echo "Installing ${type} `basename ${lib_dest}`"
93 if [ "${type}" = "lib" ]; then
94 # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
95 install_name_tool -id "${install_name}/`basename ${lib_dest}`" ${lib_dest} > /dev/null
98 if [ "${type}" != "data" ]; then
99 # Iterate through each installed library and modify the references to other dynamic libraries to match the framework's library directory
100 for linked_lib in `otool -L ${lib_dest} | grep '(' | sed 's/\((.*)\)//'`; do
101 local name=`basename ${linked_lib}`
102 case "${linked_lib}" in
103 */vlc_build_dir/* | */vlc_install_dir/* | *vlc* | */extras/contrib/lib/*)
104 if test -e ${linked_lib}; then
105 install_name_tool -change "$linked_lib" "${lib_install_prefix}/${name}" "${lib_dest}"
106 linked_libs="${linked_libs} ${ref_lib}"
107 vlc_install ${linked_lib} ${target_lib} "library"
115 # @function vlc_install
116 ##########################
118 ##########################
119 # Hack for VLC-release.app
120 if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
121 vlc_install "${VLC_BUILD_DIR}/bin/${prefix}vlc" "${target}" "bin" "@loader_path/lib"
122 mv ${target}/vlc ${target}/VLC
123 chmod +x ${target}/VLC
124 elif [ "$FULL_PRODUCT_NAME" = "VLC-Plugin.plugin" ] ; then
125 # install Safari webplugin
126 vlc_install "${VLC_BUILD_DIR}/projects/mozilla/${prefix}npvlc.${suffix}" "${target}" "library" "@loader_path/lib"
127 mv ${target}/npvlc.${suffix} "${target}/VLC Plugin"
128 chmod +x "${target}/VLC Plugin"
130 vlc_install "${VLC_BUILD_DIR}/bin/${prefix}vlc" "${target}/bin" "bin" "@loader_path/../lib"
133 ##########################
134 # Build the modules folder (Same as VLCKit.framework/modules in Makefile)
135 echo "Building modules folder..."
136 # Figure out what modules are available to install
137 for module in `find ${VLC_BUILD_DIR}/modules -name *.${suffix}` ; do
138 # Check to see that the reported module actually exists
139 if test -n ${module}; then
140 vlc_install ${module} ${target_modules} "module"
144 # Install the module cache
145 vlc_install `ls ${VLC_BUILD_DIR}/modules/plugins-*.dat` ${target_modules} "data"
147 # Build the modules folder
148 ##########################
150 ##########################
151 # Create a symbolic link in the root of the framework
152 mkdir -p ${target_lib}
153 mkdir -p ${target_modules}
155 if [ "$RELEASE_MAKEFILE" != "yes" ] ; then
156 pushd `pwd` > /dev/null
157 cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
159 ln -sf Versions/Current/${lib} .
160 ln -sf Versions/Current/${modules} .
161 ln -sf Versions/Current/${include} .
162 ln -sf Versions/Current/${share} .
163 ln -sf Versions/Current/bin .
164 ln -sf ../modules Versions/Current/bin
165 ln -sf ../share Versions/Current/bin
170 ##########################
171 # Build the library folder
172 echo "Building library folder... ${linked_libs}"
173 for linked_lib in ${linked_libs} ; do
174 case "${linked_lib}" in
175 */extras/contrib/lib/*.dylib|*/vlc_install_dir/lib/*.dylib)
176 if test -e ${linked_lib}; then
177 vlc_install ${linked_lib} ${target_lib} "library"
183 vlc_install "${VLC_BUILD_DIR}/src/${prefix}libvlc.5.dylib" "${target_lib}" "library"
184 vlc_install "${VLC_BUILD_DIR}/src/${prefix}libvlccore.4.dylib" "${target_lib}" "library"
185 pushd `pwd` > /dev/null
186 cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}/lib
187 ln -sf libvlc.5.dylib libvlc.dylib
188 ln -sf libvlccore.4.dylib libvlccore.dylib
191 ##########################
192 # Build the share folder
193 echo "Building share folder..."
194 pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks"
195 mkdir -p ${target_share}
196 $pbxcp ${VLC_SRC_DIR}/share/lua ${target_share}
199 ##########################
201 if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
202 echo "Exporting headers..."
203 mkdir -p ${target_include}/vlc
204 $pbxcp ${VLC_SRC_DIR}/include/vlc/*.h ${target_include}/vlc
206 echo "Headers not needed for this product"