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"
33 echo "Building for $ARCHS"
36 if test "${ACTION}" = "clean"; then
37 rm -Rf "${VLC_BUILD_DIR}/tmp"
41 if test "${ACTION}" != "build"; then
42 echo "This script is supposed to run from xcodebuild or Xcode"
50 target="${TARGET_BUILD_DIR}/${CONTENTS_FOLDER_PATH}"
51 target_bin="${target}/bin"
52 target_lib="${target}/${lib}" # Should we consider using a different well-known folder like shared resources?
53 target_modules="${target}/${modules}" # Should we consider using a different well-known folder like shared resources?
54 target_share="${target}/${share}" # Should we consider using a different well-known folder like shared resources?
55 target_include="${target}/${include}" # Should we consider using a different well-known folder like shared resources?
61 ##########################
62 # @function vlc_install_object(src_lib, dest_dir, type, lib_install_prefix, destination_name, suffix)
63 # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
64 # @param src_lib source library to copy to the destination directory
65 # @param dest_dir destination directory where the src_lib should be copied to
66 vlc_install_object() {
71 local lib_install_prefix=${4}
72 local destination_name=${5}
75 if [ $type = "lib" ]; then
76 local install_name="@loader_path/lib"
77 elif [ $type = "module" ]; then
78 local install_name="@loader_path/modules"
80 if [ "$destination_name" != "" ]; then
81 local lib_dest="$dest_dir/$destination_name$suffix"
82 local lib_name=`basename $destination_name`
84 local lib_dest="$dest_dir/`basename $src_lib`$suffix"
85 local lib_name=`basename $src_lib`
88 if [ "x$lib_install_prefix" != "x" ]; then
89 local lib_install_prefix="$lib_install_prefix"
91 local lib_install_prefix="@loader_path/../lib"
94 if ! test -e ${src_lib}; then
97 if ((! test -e ${lib_dest}) || test ${src_lib} -nt ${lib_dest} ); then
101 # Lets copy the library from the source folder to our new destination folder
102 if [ "${type}" = "bin" ]; then
103 install -m 755 ${src_lib} ${lib_dest}
105 install -m 644 ${src_lib} ${lib_dest}
108 # Update the dynamic library so it will know where to look for the other libraries
109 echo "Installing ${type} `basename ${lib_dest}`"
111 if [ "${type}" = "lib" ]; then
112 # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
113 install_name_tool -id "${install_name}/${lib_name}" ${lib_dest} > /dev/null
114 echo "ID=${install_name}/${lib_name}"
117 if [ "${type}" != "data" ]; then
118 # Iterate through each installed library and modify the references to other dynamic libraries to match the framework's library directory
119 for linked_lib in `otool -L ${lib_dest} | grep '(' | sed 's/\((.*)\)//'`; do
120 local name=`basename ${linked_lib}`
121 case "${linked_lib}" in
122 */vlc_build_dir/* | */vlc_install_dir/* | *vlc* | */extras/contrib/lib/*)
123 if test -e ${linked_lib}; then
124 install_name_tool -change "$linked_lib" "${lib_install_prefix}/${name}" "${lib_dest}"
125 linked_libs="${linked_libs} ${ref_lib}"
126 vlc_install_object ${linked_lib} ${target_lib} "library"
134 # @function vlc_install
135 ##########################
137 ##########################
138 # @function vlc_install(src_lib_dir, src_lib_name, dest_dir, type, lib_install_prefix)
139 # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
140 # @param src_lib source library to copy to the destination directory
141 # @param dest_dir destination directory where the src_lib should be copied to
146 if test "$use_archs" = "no"; then
147 vlc_install_object "$VLC_BUILD_DIR/$1/$2" "$dest_dir" "$type" $5
149 if test $type = "data"; then
150 vlc_install_object "$main_build_dir/$1/$2" "$dest_dir" "$type" $5
153 tmp_dest_dir="$VLC_BUILD_DIR/tmp/$type"
154 mkdir -p "$tmp_dest_dir"
156 for arch in $ARCHS; do
157 vlc_install_object "$VLC_BUILD_DIR/$arch/$1/$2" "$tmp_dest_dir" "$type" "$5" "" ".$arch"
158 local dest="$tmp_dest_dir/$2.$arch"
159 if test -e ${dest}; then
160 if ! test "$dest_dir/$2" -nt "${dest}"; then
163 objects="${dest} $objects"
165 echo "Warning: building $2 without $arch"
168 if test "$newinstall" = "yes"; then
169 echo "Creating fat $type $dest_dir/$2"
170 lipo $objects -output "$dest_dir/$2" -create
175 # @function vlc_install
176 ##########################
178 ##########################
179 # Create a symbolic link in the root of the framework
180 mkdir -p ${target_lib}
181 mkdir -p ${target_modules}
182 mkdir -p ${target_bin}
184 if [ "$RELEASE_MAKEFILE" != "yes" ] ; then
185 pushd `pwd` > /dev/null
186 cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
188 ln -sf Versions/Current/${lib} .
189 ln -sf Versions/Current/${modules} .
190 ln -sf Versions/Current/${include} .
191 ln -sf Versions/Current/${share} .
192 ln -sf Versions/Current/bin .
193 ln -sf ../modules Versions/Current/bin
194 ln -sf ../share Versions/Current/bin
199 ##########################
200 # Hack for VLC-release.app
201 if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
202 vlc_install "bin/${prefix}" "vlc" "${target}" "bin" "@loader_path/lib"
203 mv ${target}/vlc ${target}/VLC
204 chmod +x ${target}/VLC
205 elif [ "$FULL_PRODUCT_NAME" = "VLC-Plugin.plugin" ] ; then
206 # install Safari webplugin
207 vlc_install "projects/mozilla/${prefix}" "npvlc.${suffix}" "${target}" "lib" "@loader_path/lib"
208 mv ${target}/npvlc.${suffix} "${target}/VLC Plugin"
209 chmod +x "${target}/VLC Plugin"
211 vlc_install "bin/${prefix}" "vlc" "${target}/bin" "bin" "@loader_path/../lib"
215 ##########################
216 # Build the modules folder (Same as VLCKit.framework/modules in Makefile)
217 echo "Building modules folder..."
218 # Figure out what modules are available to install
219 for module in `find ${main_build_dir}/modules -path "*dylib.dSYM*" -prune -o -name "lib*_plugin.dylib" -print | sed -e s:${main_build_dir}/::` ; do
220 # Check to see that the reported module actually exists
221 if test -n ${module}; then
222 vlc_install `dirname ${module}` `basename ${module}` ${target_modules} "module"
226 # Install the module cache
227 cache=`ls ${main_build_dir}/modules/plugins-*.dat | sed -e s:${main_build_dir}/::`
228 vlc_install `dirname ${cache}` `basename ${cache}` ${target_modules} "data"
230 # Build the lib folder
231 ##########################
233 vlc_install "src/${prefix}" "libvlc.5.dylib" "${target_lib}" "lib"
234 vlc_install "src/${prefix}" "libvlccore.4.dylib" "${target_lib}" "lib"
235 pushd `pwd` > /dev/null
236 cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}/lib
237 ln -sf libvlc.5.dylib libvlc.dylib
238 ln -sf libvlccore.4.dylib libvlccore.dylib
241 ##########################
242 # Build the share folder
243 echo "Building share folder..."
244 pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks"
245 mkdir -p ${target_share}
246 $pbxcp ${main_build_dir}/share/lua ${target_share}
249 ##########################
251 if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
252 echo "Exporting headers..."
253 mkdir -p ${target_include}/vlc
254 $pbxcp ${main_build_dir}/include/vlc/*.h ${target_include}/vlc
256 echo "Headers not needed for this product"