5 # Script that install libvlc and its modules inside VLCKit.
7 # This is for some creepy reasons also used by legacy VLC.app or
11 # We are building VLC.app or the moz plugin
13 if test "${ACTION}" = "release-makefile"; then
14 echo "running Pre-Compile.sh in release-makefile mode"
16 FULL_PRODUCT_NAME
="${PRODUCT}"
17 if [ "$FULL_PRODUCT_NAME" = "VLC-Plugin.plugin" ] ; then
18 TARGET_BUILD_DIR
="${src_dir}"
20 TARGET_BUILD_DIR
="${build_dir}"
22 CONTENTS_FOLDER_PATH
="${FULL_PRODUCT_NAME}/Contents/MacOS"
23 VLC_BUILD_DIR
="${build_dir}"
24 VLC_SRC_DIR
="${src_dir}"
26 RELEASE_MAKEFILE
="yes"
28 main_build_dir
="${VLC_BUILD_DIR}"
31 main_build_dir
="${VLC_BUILD_DIR}/${ARCHS%% *}"
32 echo "Building for $ARCHS"
35 if test "${ACTION}" = "clean"; then
36 rm -Rf "${VLC_BUILD_DIR}/tmp"
40 if test "${ACTION}" != "build"; then
41 echo "This script is supposed to run from xcodebuild or Xcode"
49 target
="${TARGET_BUILD_DIR}/${CONTENTS_FOLDER_PATH}"
50 target_bin
="${target}/bin"
51 target_lib
="${target}/${lib}" # Should we consider using a different well-known folder like shared resources?
52 target_plugins
="${target}/${plugins}" # Should we consider using a different well-known folder like shared resources?
53 target_share
="${target}/${share}" # Should we consider using a different well-known folder like shared resources?
57 num_archs
=$
(echo `echo $ARCHS | wc -w`)
59 ##########################
60 # @function vlc_install_object(src_lib, dest_dir, type, lib_install_prefix, destination_name, suffix)
61 # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
62 # @param src_lib source library to copy to the destination directory
63 # @param dest_dir destination directory where the src_lib should be copied to
64 vlc_install_object
() {
68 local lib_install_prefix
=${4}
69 local destination_name
=${5}
72 if [ $type = "library" ]; then
73 local install_name
="@loader_path/lib"
74 elif [ $type = "module" ]; then
75 local install_name
="@loader_path/plugins"
77 if [ "$destination_name" != "" ]; then
78 local lib_dest
="$dest_dir/$destination_name$suffix"
79 local lib_name
=`basename $destination_name`
81 local lib_dest
="$dest_dir/`basename $src_lib`$suffix"
82 local lib_name
=`basename $src_lib`
85 if [ "x$lib_install_prefix" != "x" ]; then
86 local lib_install_prefix
="$lib_install_prefix"
88 local lib_install_prefix
="@loader_path/../lib"
91 if test ! -e ${src_lib}; then
95 if ( (test ! -e ${lib_dest}) || test ${src_lib} -nt ${lib_dest} ); then
99 # Lets copy the library from the source folder to our new destination folder
100 if [ "${type}" = "bin" ]; then
101 install -m 755 ${src_lib} ${lib_dest}
103 install -m 644 ${src_lib} ${lib_dest}
106 # Update the dynamic library so it will know where to look for the other libraries
107 echo "Installing ${type} `basename ${lib_dest}`"
109 if [ "${type}" = "library" ]; then
110 # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
111 install_name_tool
-id "${install_name}/${lib_name}" ${lib_dest} > /dev/null
114 if [ "${type}" != "data
" ]; then
115 # Iterate through each installed library and modify the references to other dynamic libraries to match the framework's library directory
116 for linked_lib in `otool -L ${lib_dest} | grep '(' | sed 's/\((.*)\)//'`; do
117 local name=`basename ${linked_lib}`
118 case "${linked_lib}" in
119 */vlc_build_dir/* | */vlc_install_dir/* | *vlc* | */extras/contrib/*)
120 if test -e ${linked_lib}; then
121 install_name_tool -change "$linked_lib" "${lib_install_prefix}/${name}" "${lib_dest}"
122 linked_libs="${linked_libs} ${ref_lib}"
123 vlc_install_object ${linked_lib} ${target_lib} "library
"
131 # @function vlc_install_object
132 ##########################
134 ##########################
135 # @function vlc_install(src_lib_dir, src_lib_name, dest_dir, type, lib_install_prefix)
136 # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
137 # @param src_lib source library to copy to the destination directory
138 # @param dest_dir destination directory where the src_lib should be copied to
145 if test "$use_archs" = "no
"; then
146 vlc_install_object "$VLC_BUILD_DIR/$src_dir/$src" "$dest_dir" "$type" $5
148 if test $type = "data
"; then
149 vlc_install_object "$main_build_dir/$src_dir/$src" "$dest_dir" "$type" $5
151 local fatdest="$dest_dir/$2"
152 local shouldUpdate="no
"
154 # Determine what architectures are available in the destination image
155 local fatdest_archs=""
156 if [ -e ${fatdest} ]; then
157 fatdest_archs=`lipo -info "${fatdest}" 2> /dev/null | sed -E -e 's/[[:space:]]+$//' -e 's/.+:[[:space:]]*//' -e 's/[^[:space:]]+/(&)/g'`
159 # Check to see if the destination image needs to be reconstructed
160 for arch in $ARCHS; do
161 # Only install if the new image is newer than the one we have installed or the required arch is missing.
162 if test $shouldUpdate = "no
" && (! [[ "$fatdest_archs" =~ \($arch\) ]] || test "$VLC_BUILD_DIR/$arch/$src_dir/$src" -nt "${fatdest}"); then
165 fatdest_archs=${fatdest_archs//\($arch\)/}
168 # Reconstruct the destination image, if the update flag is set or if there are more archs in the desintation then we need
169 fatdest_archs=${fatdest_archs// /}
171 # If the destination image does not exist, then we have to reconstruct it
175 # If we should update the destination image or if there were unexpected archs in the destination image, then reconstruct it
176 if test "$shouldUpdate" = "yes" || test -n "${fatdest_archs}"; then
177 # If the destination image exists, get rid of it so we can copy over the newly constructed image
178 if test -e ${fatdest}; then
182 if test "$num_archs" = "1"; then
183 echo "Copying
$ARCHS $type $fatdest"
184 local arch_src="$VLC_BUILD_DIR/$ARCHS/$src_dir/$src"
185 vlc_install_object "$arch_src" "$dest_dir" "$type" "$5" ""
187 # Create a temporary destination dir to store each ARCH object file
188 local tmp_dest_dir="$VLC_BUILD_DIR/tmp
/$type"
189 rm -Rf "${tmp_dest_dir}/*"
190 mkdir -p "$tmp_dest_dir"
192 # Search for each ARCH object file used to construct a fat image
194 for arch in $ARCHS; do
195 local arch_src="$VLC_BUILD_DIR/$arch/$src_dir/$src"
196 vlc_install_object "$arch_src" "$tmp_dest_dir" "$type" "$5" "" ".
$arch"
197 local dest="$tmp_dest_dir/$src.
$arch"
198 if [ -e ${dest} ]; then
199 objects="${dest} $objects"
201 echo "Warning
: building
$arch_src without
$arch"
205 echo "Creating fat
$type $fatdest"
206 lipo $objects -output "$fatdest" -create
212 # @function vlc_install
213 ##########################
215 ##########################
216 # Create a symbolic link in the root of the framework
217 mkdir -p ${target_lib}
218 mkdir -p ${target_plugins}
219 mkdir -p ${target_bin}
221 if [ "$RELEASE_MAKEFILE" != "yes" ] ; then
222 pushd `pwd` > /dev/null
223 cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
225 ln -sf Versions/Current/${lib} .
226 ln -sf Versions/Current/${plugins} .
227 ln -sf Versions/Current/${include} .
228 ln -sf Versions/Current/${share} .
229 ln -sf Versions/Current/bin .
230 ln -sf ../plugins Versions/Current/bin
231 ln -sf ../share Versions/Current/bin
236 ##########################
238 if [ "$FULL_PRODUCT_NAME" = "VLC.app
" ] ; then
239 vlc_install "bin
/${prefix}" "vlc
" "${target}" "bin
" "@loader_path
/lib
"
240 mv ${target}/vlc ${target}/VLC
241 chmod +x ${target}/VLC
242 elif [ "$FULL_PRODUCT_NAME" = "VLC-Plugin.plugin
" ] ; then
243 # install Safari webplugin
244 vlc_install "projects
/mozilla
/${prefix}" "npvlc.${suffix}" "${target}" "lib
" "@loader_path
/lib
"
245 mv ${target}/npvlc.${suffix} "${target}/VLC Plugin"
246 chmod +x
"${target}/VLC Plugin"
248 vlc_install
"bin/${prefix}" "vlc" "${target}/bin" "bin" "@loader_path/../lib"
251 ##########################
252 # Build the plugins folder (Same as VLCKit.framework/plugins in Makefile)
253 echo "Building plugins folder..."
254 # Figure out what plugins are available to install
255 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
256 # Check to see that the reported module actually exists
257 if test -n ${module}; then
258 vlc_install
`dirname ${module}` `basename ${module}` ${target_plugins} "module"
262 ##########################
263 # Build the lib folder
264 vlc_install "lib/${prefix}" "libvlc.5.dylib" "${target_lib}" "library"
265 vlc_install "src/${prefix}" "libvlccore.5.dylib" "${target_lib}" "library"
266 pushd `pwd` > /dev/null
268 ln -sf libvlc.5.dylib libvlc.dylib
269 ln -sf libvlccore.5.dylib libvlccore.dylib
272 ##########################
273 # Build the share folder
274 if [ $PRODUCT != "VLC.app" ]; then
275 echo "Building share folder..."
276 pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks -v -V"
277 mkdir -p ${target_share}
278 if test "$use_archs" = "no"; then
279 $pbxcp ${VLC_BUILD_DIR}/share/lua ${target_share}
281 $pbxcp ${main_build_dir}/share/lua ${target_share}