5 # Script that installs libvlc to VLC.app
7 # We are building VLC.app or the moz plugin
9 if test "${ACTION}" = "release-makefile"; then
10 echo "running build-package.sh in release-makefile mode"
12 FULL_PRODUCT_NAME="${PRODUCT}"
13 if [ "$FULL_PRODUCT_NAME" = "VLC-Plugin.plugin" ] ; then
14 TARGET_BUILD_DIR="${src_dir}"
16 TARGET_BUILD_DIR="${build_dir}"
18 CONTENTS_FOLDER_PATH="${FULL_PRODUCT_NAME}/Contents/MacOS"
19 VLC_BUILD_DIR="${build_dir}"
20 VLC_SRC_DIR="${src_dir}"
22 RELEASE_MAKEFILE="yes"
24 main_build_dir="${VLC_BUILD_DIR}"
27 main_build_dir="${VLC_BUILD_DIR}/${ARCHS%% *}"
28 echo "Building for $ARCHS"
31 if test "${ACTION}" = "clean"; then
32 rm -Rf "${VLC_BUILD_DIR}/tmp"
36 if test "${ACTION}" != "build"; then
37 echo "This script is supposed to run from xcodebuild or Xcode"
45 target="${TARGET_BUILD_DIR}/${CONTENTS_FOLDER_PATH}"
46 target_bin="${target}/bin"
47 target_lib="${target}/${lib}" # Should we consider using a different well-known folder like shared resources?
48 target_plugins="${target}/${plugins}" # Should we consider using a different well-known folder like shared resources?
49 target_share="${target}/${share}" # Should we consider using a different well-known folder like shared resources?
53 num_archs=$(echo `echo $ARCHS | wc -w`)
55 ##########################
56 # @function vlc_install_object(src_lib, dest_dir, type, lib_install_prefix, destination_name, suffix)
57 # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
58 # @param src_lib source library to copy to the destination directory
59 # @param dest_dir destination directory where the src_lib should be copied to
60 vlc_install_object() {
64 local lib_install_prefix=${4}
65 local destination_name=${5}
68 if [ $type = "library" ]; then
69 local install_name="@loader_path/lib"
70 elif [ $type = "module" ]; then
71 local install_name="@loader_path/plugins"
73 if [ "$destination_name" != "" ]; then
74 local lib_dest="$dest_dir/$destination_name$suffix"
75 local lib_name=`basename $destination_name`
77 local lib_dest="$dest_dir/`basename $src_lib`$suffix"
78 local lib_name=`basename $src_lib`
81 if [ "x$lib_install_prefix" != "x" ]; then
82 local lib_install_prefix="$lib_install_prefix"
84 local lib_install_prefix="@loader_path/../lib"
87 if test ! -e ${src_lib}; then
91 if ( (test ! -e ${lib_dest}) || test ${src_lib} -nt ${lib_dest} ); then
95 # Lets copy the library from the source folder to our new destination folder
96 if [ "${type}" = "bin" ]; then
97 install -m 755 ${src_lib} ${lib_dest}
99 install -m 644 ${src_lib} ${lib_dest}
102 # Update the dynamic library so it will know where to look for the other libraries
103 echo "Installing ${type} `basename ${lib_dest}`"
105 if [ "${type}" = "library" ]; then
106 # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
107 install_name_tool -id "${install_name}/${lib_name}" ${lib_dest} > /dev/null
110 if [ "${type}" != "data" ]; then
111 # Iterate through each installed library and modify the references to other dynamic libraries to match the framework's library directory
112 for linked_lib in `otool -L ${lib_dest} | grep '(' | sed 's/\((.*)\)//'`; do
113 local name=`basename ${linked_lib}`
114 case "${linked_lib}" in
115 */vlc_build_dir/* | */vlc_install_dir/* | *vlc* | */extras/contrib/*)
116 if test -e ${linked_lib}; then
117 install_name_tool -change "$linked_lib" "${lib_install_prefix}/${name}" "${lib_dest}"
118 linked_libs="${linked_libs} ${ref_lib}"
119 vlc_install_object ${linked_lib} ${target_lib} "library"
127 # @function vlc_install_object
128 ##########################
130 ##########################
131 # @function vlc_install(src_lib_dir, src_lib_name, dest_dir, type, lib_install_prefix)
132 # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
133 # @param src_lib source library to copy to the destination directory
134 # @param dest_dir destination directory where the src_lib should be copied to
141 if test "$use_archs" = "no"; then
142 vlc_install_object "$VLC_BUILD_DIR/$src_dir/$src" "$dest_dir" "$type" $5
144 if test $type = "data"; then
145 vlc_install_object "$main_build_dir/$src_dir/$src" "$dest_dir" "$type" $5
147 local fatdest="$dest_dir/$2"
148 local shouldUpdate="no"
150 # Determine what architectures are available in the destination image
151 local fatdest_archs=""
152 if [ -e ${fatdest} ]; then
153 fatdest_archs=`lipo -info "${fatdest}" 2> /dev/null | sed -E -e 's/[[:space:]]+$//' -e 's/.+:[[:space:]]*//' -e 's/[^[:space:]]+/(&)/g'`
155 # Check to see if the destination image needs to be reconstructed
156 for arch in $ARCHS; do
157 # Only install if the new image is newer than the one we have installed or the required arch is missing.
158 if test $shouldUpdate = "no" && (! [[ "$fatdest_archs" =~ \($arch\) ]] || test "$VLC_BUILD_DIR/$arch/$src_dir/$src" -nt "${fatdest}"); then
161 fatdest_archs=${fatdest_archs//\($arch\)/}
164 # Reconstruct the destination image, if the update flag is set or if there are more archs in the desintation then we need
165 fatdest_archs=${fatdest_archs// /}
167 # If the destination image does not exist, then we have to reconstruct it
171 # If we should update the destination image or if there were unexpected archs in the destination image, then reconstruct it
172 if test "$shouldUpdate" = "yes" || test -n "${fatdest_archs}"; then
173 # If the destination image exists, get rid of it so we can copy over the newly constructed image
174 if test -e ${fatdest}; then
178 if test "$num_archs" = "1"; then
179 echo "Copying $ARCHS $type $fatdest"
180 local arch_src="$VLC_BUILD_DIR/$ARCHS/$src_dir/$src"
181 vlc_install_object "$arch_src" "$dest_dir" "$type" "$5" ""
183 # Create a temporary destination dir to store each ARCH object file
184 local tmp_dest_dir="$VLC_BUILD_DIR/tmp/$type"
185 rm -Rf "${tmp_dest_dir}/*"
186 mkdir -p "$tmp_dest_dir"
188 # Search for each ARCH object file used to construct a fat image
190 for arch in $ARCHS; do
191 local arch_src="$VLC_BUILD_DIR/$arch/$src_dir/$src"
192 vlc_install_object "$arch_src" "$tmp_dest_dir" "$type" "$5" "" ".$arch"
193 local dest="$tmp_dest_dir/$src.$arch"
194 if [ -e ${dest} ]; then
195 objects="${dest} $objects"
197 echo "Warning: building $arch_src without $arch"
201 echo "Creating fat $type $fatdest"
202 lipo $objects -output "$fatdest" -create
208 # @function vlc_install
209 ##########################
211 ##########################
212 # Create a symbolic link in the root of the framework
213 mkdir -p ${target_lib}
214 mkdir -p ${target_plugins}
215 mkdir -p ${target_bin}
217 if [ "$RELEASE_MAKEFILE" != "yes" ] ; then
218 pushd `pwd` > /dev/null
219 cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
221 ln -sf Versions/Current/${lib} .
222 ln -sf Versions/Current/${plugins} .
223 ln -sf Versions/Current/${include} .
224 ln -sf Versions/Current/${share} .
225 ln -sf Versions/Current/bin .
226 ln -sf ../plugins Versions/Current/bin
227 ln -sf ../share Versions/Current/bin
232 ##########################
234 if [ "$FULL_PRODUCT_NAME" = "VLC.app" ] ; then
235 vlc_install "bin/${prefix}" "vlc" "${target}" "bin" "@loader_path/lib"
236 mv ${target}/vlc ${target}/VLC
237 chmod +x ${target}/VLC
238 elif [ "$FULL_PRODUCT_NAME" = "VLC-Plugin.plugin" ] ; then
239 # install Safari webplugin
240 vlc_install "projects/mozilla/${prefix}" "npvlc.${suffix}" "${target}" "lib" "@loader_path/lib"
241 mv ${target}/npvlc.${suffix} "${target}/VLC Plugin"
242 chmod +x "${target}/VLC Plugin"
244 vlc_install "bin/${prefix}" "vlc" "${target}/bin" "bin" "@loader_path/../lib"
247 ##########################
248 # Build the plugins folder
249 echo "Building plugins folder..."
250 # Figure out what plugins are available to install
251 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
252 # Check to see that the reported module actually exists
253 if test -n ${module}; then
254 vlc_install `dirname ${module}` `basename ${module}` ${target_plugins} "module"
258 ##########################
259 # Build the lib folder
260 vlc_install "lib/${prefix}" "libvlc.5.dylib" "${target_lib}" "library"
261 vlc_install "src/${prefix}" "libvlccore.5.dylib" "${target_lib}" "library"
262 pushd `pwd` > /dev/null
264 ln -sf libvlc.5.dylib libvlc.dylib
265 ln -sf libvlccore.5.dylib libvlccore.dylib
268 ##########################
269 # Build the share folder
270 if [ $PRODUCT != "VLC.app" ]; then
271 echo "Building share folder..."
272 pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks -v -V"
273 mkdir -p ${target_share}
274 if test "$use_archs" = "no"; then
275 $pbxcp ${VLC_BUILD_DIR}/share/lua ${target_share}
277 $pbxcp ${main_build_dir}/share/lua ${target_share}