5 # Script that installs libvlc to VLC.app
7 # We are building VLC.app
9 if test "${ACTION}" = "release-makefile"; then
10 echo "running build-package.sh in release-makefile mode"
12 FULL_PRODUCT_NAME="${PRODUCT}"
13 TARGET_BUILD_DIR="${build_dir}"
14 CONTENTS_FOLDER_PATH="${FULL_PRODUCT_NAME}/Contents/MacOS"
15 VLC_BUILD_DIR="${build_dir}"
16 VLC_SRC_DIR="${src_dir}"
18 RELEASE_MAKEFILE="yes"
20 main_build_dir="${VLC_BUILD_DIR}"
23 main_build_dir="${VLC_BUILD_DIR}/${ARCHS%% *}"
24 echo "Building for $ARCHS"
27 if test "${ACTION}" = "clean"; then
28 rm -Rf "${VLC_BUILD_DIR}/tmp"
32 if test "${ACTION}" != "build"; then
33 echo "This script is supposed to run from xcodebuild or Xcode"
41 target="${TARGET_BUILD_DIR}/${CONTENTS_FOLDER_PATH}"
42 target_bin="${target}/bin"
43 target_lib="${target}/${lib}" # Should we consider using a different well-known folder like shared resources?
44 target_plugins="${target}/${plugins}" # Should we consider using a different well-known folder like shared resources?
45 target_share="${target}/${share}" # Should we consider using a different well-known folder like shared resources?
49 num_archs=$(echo `echo $ARCHS | wc -w`)
51 ##########################
52 # @function vlc_install_object(src_lib, dest_dir, type, lib_install_prefix, destination_name, suffix)
53 # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
54 # @param src_lib source library to copy to the destination directory
55 # @param dest_dir destination directory where the src_lib should be copied to
56 vlc_install_object() {
60 local lib_install_prefix=${4}
61 local destination_name=${5}
64 if [ $type = "library" ]; then
65 local install_name="@loader_path/lib"
66 elif [ $type = "module" ]; then
67 local install_name="@loader_path/plugins"
69 if [ "$destination_name" != "" ]; then
70 local lib_dest="$dest_dir/$destination_name$suffix"
71 local lib_name=`basename $destination_name`
73 local lib_dest="$dest_dir/`basename $src_lib`$suffix"
74 local lib_name=`basename $src_lib`
77 if [ "x$lib_install_prefix" != "x" ]; then
78 local lib_install_prefix="$lib_install_prefix"
80 local lib_install_prefix="@loader_path/../lib"
83 if test ! -e ${src_lib}; then
87 if ( (test ! -e ${lib_dest}) || test ${src_lib} -nt ${lib_dest} ); then
91 # Lets copy the library from the source folder to our new destination folder
92 if [ "${type}" = "bin" ]; then
93 install -m 755 ${src_lib} ${lib_dest}
95 install -m 644 ${src_lib} ${lib_dest}
98 # Update the dynamic library so it will know where to look for the other libraries
99 echo "Installing ${type} `basename ${lib_dest}`"
101 if [ "${type}" = "library" ]; then
102 # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
103 install_name_tool -id "${install_name}/${lib_name}" ${lib_dest} > /dev/null
106 if [ "${type}" != "data" ]; then
107 # Iterate through each installed library and modify the references to other dynamic libraries to match the framework's library directory
108 for linked_lib in `otool -L ${lib_dest} | grep '(' | sed 's/\((.*)\)//'`; do
109 local name=`basename ${linked_lib}`
110 case "${linked_lib}" in
111 */vlc_build_dir/* | */vlc_install_dir/* | *vlc* | */extras/contrib/*)
112 if test -e ${linked_lib}; then
113 install_name_tool -change "$linked_lib" "${lib_install_prefix}/${name}" "${lib_dest}"
114 linked_libs="${linked_libs} ${ref_lib}"
115 vlc_install_object ${linked_lib} ${target_lib} "library"
123 # @function vlc_install_object
124 ##########################
126 ##########################
127 # @function vlc_install(src_lib_dir, src_lib_name, dest_dir, type, lib_install_prefix)
128 # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
129 # @param src_lib source library to copy to the destination directory
130 # @param dest_dir destination directory where the src_lib should be copied to
137 if test "$use_archs" = "no"; then
138 vlc_install_object "$VLC_BUILD_DIR/$src_dir/$src" "$dest_dir" "$type" $5
140 if test $type = "data"; then
141 vlc_install_object "$main_build_dir/$src_dir/$src" "$dest_dir" "$type" $5
143 local fatdest="$dest_dir/$2"
144 local shouldUpdate="no"
146 # Determine what architectures are available in the destination image
147 local fatdest_archs=""
148 if [ -e ${fatdest} ]; then
149 fatdest_archs=`lipo -info "${fatdest}" 2> /dev/null | sed -E -e 's/[[:space:]]+$//' -e 's/.+:[[:space:]]*//' -e 's/[^[:space:]]+/(&)/g'`
151 # Check to see if the destination image needs to be reconstructed
152 for arch in $ARCHS; do
153 # Only install if the new image is newer than the one we have installed or the required arch is missing.
154 if test $shouldUpdate = "no" && (! [[ "$fatdest_archs" =~ \($arch\) ]] || test "$VLC_BUILD_DIR/$arch/$src_dir/$src" -nt "${fatdest}"); then
157 fatdest_archs=${fatdest_archs//\($arch\)/}
160 # Reconstruct the destination image, if the update flag is set or if there are more archs in the desintation then we need
161 fatdest_archs=${fatdest_archs// /}
163 # If the destination image does not exist, then we have to reconstruct it
167 # If we should update the destination image or if there were unexpected archs in the destination image, then reconstruct it
168 if test "$shouldUpdate" = "yes" || test -n "${fatdest_archs}"; then
169 # If the destination image exists, get rid of it so we can copy over the newly constructed image
170 if test -e ${fatdest}; then
174 if test "$num_archs" = "1"; then
175 echo "Copying $ARCHS $type $fatdest"
176 local arch_src="$VLC_BUILD_DIR/$ARCHS/$src_dir/$src"
177 vlc_install_object "$arch_src" "$dest_dir" "$type" "$5" ""
179 # Create a temporary destination dir to store each ARCH object file
180 local tmp_dest_dir="$VLC_BUILD_DIR/tmp/$type"
181 rm -Rf "${tmp_dest_dir}/*"
182 mkdir -p "$tmp_dest_dir"
184 # Search for each ARCH object file used to construct a fat image
186 for arch in $ARCHS; do
187 local arch_src="$VLC_BUILD_DIR/$arch/$src_dir/$src"
188 vlc_install_object "$arch_src" "$tmp_dest_dir" "$type" "$5" "" ".$arch"
189 local dest="$tmp_dest_dir/$src.$arch"
190 if [ -e ${dest} ]; then
191 objects="${dest} $objects"
193 echo "Warning: building $arch_src without $arch"
197 echo "Creating fat $type $fatdest"
198 lipo $objects -output "$fatdest" -create
204 # @function vlc_install
205 ##########################
207 ##########################
208 # Create a symbolic link in the root of the framework
209 mkdir -p ${target_lib}
210 mkdir -p ${target_plugins}
211 mkdir -p ${target_bin}
213 if [ "$RELEASE_MAKEFILE" != "yes" ] ; then
214 pushd `pwd` > /dev/null
215 cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
217 ln -sf Versions/Current/${lib} .
218 ln -sf Versions/Current/${plugins} .
219 ln -sf Versions/Current/${include} .
220 ln -sf Versions/Current/${share} .
221 ln -sf Versions/Current/bin .
222 ln -sf ../plugins Versions/Current/bin
223 ln -sf ../share Versions/Current/bin
228 ##########################
230 if [ "$FULL_PRODUCT_NAME" = "VLC.app" ] ; then
231 vlc_install "bin/${prefix}" "vlc" "${target}" "bin" "@loader_path/lib"
232 mv ${target}/vlc ${target}/VLC
233 chmod +x ${target}/VLC
235 vlc_install "bin/${prefix}" "vlc" "${target}/bin" "bin" "@loader_path/../lib"
238 ##########################
239 # Build the plugins folder
240 echo "Building plugins folder..."
241 # Figure out what plugins are available to install
242 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
243 # Check to see that the reported module actually exists
244 if test -n ${module}; then
245 vlc_install `dirname ${module}` `basename ${module}` ${target_plugins} "module"
249 ##########################
250 # Build the lib folder
251 vlc_install "lib/${prefix}" "libvlc.5.dylib" "${target_lib}" "library"
252 vlc_install "src/${prefix}" "libvlccore.7.dylib" "${target_lib}" "library"
253 pushd `pwd` > /dev/null
255 ln -sf libvlc.5.dylib libvlc.dylib
256 ln -sf libvlccore.7.dylib libvlccore.dylib
259 ##########################
260 # Build the share folder
261 if [ $PRODUCT != "VLC.app" ]; then
262 echo "Building share folder..."
263 pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks -v -V"
264 mkdir -p ${target_share}
265 if test "$use_archs" = "no"; then
266 $pbxcp ${VLC_BUILD_DIR}/share/lua ${target_share}
268 $pbxcp ${main_build_dir}/share/lua ${target_share}