]> git.sesse.net Git - vlc/blob - projects/macosx/framework/Pre-Compile.sh
VLCKit: Update Pre-Compile.sh to use plugins/ instead of modules/
[vlc] / projects / macosx / framework / Pre-Compile.sh
1 #!/bin/sh
2 #
3 # Pre-Compile.sh
4 #
5 # Script that install libvlc and its modules inside VLCKit.
6 #
7 # This is for some creepy reasons also used by legacy VLC-release.app or
8 # the moz plugin.
9
10
11 #
12 # We are building VLC-release.app or the moz plugin
13 #
14 if test "${ACTION}" = "release-makefile"; then
15     echo "running Pre-Compile.sh in release-makefile mode"
16
17     FULL_PRODUCT_NAME="${PRODUCT}"
18     if [ "$FULL_PRODUCT_NAME" = "VLC-Plugin.plugin" ] ; then
19         TARGET_BUILD_DIR="${src_dir}"
20     else
21         TARGET_BUILD_DIR="${build_dir}"
22     fi
23     CONTENTS_FOLDER_PATH="${FULL_PRODUCT_NAME}/Contents/MacOS"
24     VLC_BUILD_DIR="${build_dir}"
25     VLC_SRC_DIR="${src_dir}"
26     ACTION="build"
27     RELEASE_MAKEFILE="yes"
28     use_archs="no"
29     main_build_dir="${VLC_BUILD_DIR}"
30 else
31     use_archs="yes"
32     main_build_dir="${VLC_BUILD_DIR}/x86_64"
33     echo "Building for $ARCHS"
34 fi
35
36 if test "${ACTION}" = "clean"; then
37     rm -Rf "${VLC_BUILD_DIR}/tmp"
38     exit 0
39 fi
40
41 if test "${ACTION}" != "build"; then
42     echo "This script is supposed to run from xcodebuild or Xcode"
43     exit 1
44 fi
45
46 lib="lib"
47 plugins="plugins"
48 share="share"
49 include="include"
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_plugins="${target}/${plugins}"    # 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?
56 linked_libs=""
57 prefix=".libs/"
58 suffix="dylib"
59
60
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() {
67
68     local src_lib=${1}
69     local dest_dir=${2}
70     local type=${3}
71     local lib_install_prefix=${4}
72     local destination_name=${5}
73     local suffix=${6}
74
75     if [ $type = "lib" ]; then
76         local install_name="@loader_path/lib"
77     elif [ $type = "module" ]; then
78         local install_name="@loader_path/plugins"
79     fi
80     if [ "$destination_name" != "" ]; then
81         local lib_dest="$dest_dir/$destination_name$suffix"
82         local lib_name=`basename $destination_name`
83     else
84         local lib_dest="$dest_dir/`basename $src_lib`$suffix"
85         local lib_name=`basename $src_lib`
86     fi
87
88     if [ "x$lib_install_prefix" != "x" ]; then
89         local lib_install_prefix="$lib_install_prefix"
90     else
91         local lib_install_prefix="@loader_path/../lib"
92     fi
93
94     if ! test -e ${src_lib}; then
95         return
96     fi
97
98     if ((! test -e ${lib_dest}) || test ${src_lib} -nt ${lib_dest} ); then
99
100         mkdir -p ${dest_dir}
101
102         # Lets copy the library from the source folder to our new destination folder
103         if [ "${type}" = "bin" ]; then
104             install -m 755 ${src_lib} ${lib_dest}
105         else
106             install -m 644 ${src_lib} ${lib_dest}
107         fi
108
109         # Update the dynamic library so it will know where to look for the other libraries
110         echo "Installing ${type} `basename ${lib_dest}`"
111
112         if [ "${type}" = "lib" ]; then
113             # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
114             install_name_tool -id "${install_name}/${lib_name}" ${lib_dest} > /dev/null
115         fi
116
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"
127                         fi
128                         ;;
129                 esac
130             done
131         fi
132      fi
133 }
134 # @function vlc_install
135 ##########################
136
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
142 vlc_install() {
143     local dest_dir=$3
144     local type=$4
145
146     if test "$use_archs" = "no"; then
147         vlc_install_object "$VLC_BUILD_DIR/$1/$2" "$dest_dir" "$type" $5
148     else
149         if test $type = "data"; then
150             vlc_install_object "$main_build_dir/$1/$2" "$dest_dir" "$type" $5
151         else
152             fatdest="$dest_dir/$2"
153             shouldUpdateFat="no"
154
155             objects=""
156
157             # Create a temporary destination dir to store each ARCH object file
158             tmp_dest_dir="$VLC_BUILD_DIR/tmp/$type"
159             rm -Rf "${tmp_dest_dir}/*"
160             mkdir -p "$tmp_dest_dir"
161
162             for arch in $ARCHS; do
163                 local src="$VLC_BUILD_DIR/$arch/$1/$2"
164
165                 # Only install if the new image is newer than the one we have installed.
166                 if ((! test -e ${fatdest}) || test ${src} -nt ${fatdest} ); then
167                     vlc_install_object "$src" "$tmp_dest_dir" "$type" "$5" "" ".$arch"
168                     local dest="$tmp_dest_dir/$2.$arch"
169                     if test -e ${dest}; then
170                         if ! test "$dest_dir/$2" -nt "${dest}"; then
171                             shouldUpdateFat="yes"
172                         fi
173                         objects="${dest} $objects"
174                     else
175                         echo "Warning: building $2 without $arch"
176                     fi
177                 fi
178             done;
179
180             if test "$shouldUpdateFat" = "yes"; then
181                 echo "Creating fat $type $fatdest"
182                 lipo $objects -output "$fatdest" -create
183             fi
184         fi
185     fi
186 }
187 # @function vlc_install
188 ##########################
189
190 ##########################
191 # Create a symbolic link in the root of the framework
192 mkdir -p ${target_lib}
193 mkdir -p ${target_plugins}
194 mkdir -p ${target_bin}
195
196 if [ "$RELEASE_MAKEFILE" != "yes" ] ; then
197     pushd `pwd` > /dev/null
198     cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
199
200     ln -sf Versions/Current/${lib} .
201     ln -sf Versions/Current/${plugins} .
202     ln -sf Versions/Current/${include} .
203     ln -sf Versions/Current/${share} .
204     ln -sf Versions/Current/bin .
205     ln -sf ../plugins Versions/Current/bin
206     ln -sf ../share Versions/Current/bin
207
208     popd > /dev/null
209 fi
210
211 ##########################
212 # Hack for VLC-release.app
213 if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
214     vlc_install "bin/${prefix}" "vlc" "${target}" "bin" "@loader_path/lib"
215     mv ${target}/vlc ${target}/VLC
216     chmod +x ${target}/VLC
217 elif [ "$FULL_PRODUCT_NAME" = "VLC-Plugin.plugin" ] ; then
218     # install Safari webplugin
219     vlc_install "projects/mozilla/${prefix}" "npvlc.${suffix}" "${target}" "lib" "@loader_path/lib"
220     mv ${target}/npvlc.${suffix} "${target}/VLC Plugin"
221     chmod +x "${target}/VLC Plugin"
222 else
223     vlc_install "bin/${prefix}" "vlc" "${target}/bin" "bin" "@loader_path/../lib"
224 fi
225
226
227 ##########################
228 # Build the plugins folder (Same as VLCKit.framework/plugins in Makefile)
229 echo "Building plugins folder..."
230 # Figure out what plugins are available to install
231 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
232     # Check to see that the reported module actually exists
233     if test -n ${module}; then
234         vlc_install `dirname ${module}` `basename ${module}` ${target_plugins} "module"
235     fi
236 done
237
238 # Install the module cache
239 cache=`ls ${main_build_dir}/modules/plugins-*.dat | sed -e s:${main_build_dir}/::`
240 vlc_install `dirname ${cache}` `basename ${cache}` ${target_plugins} "data"
241
242 # Build the lib folder
243 ##########################
244
245 vlc_install "src/${prefix}" "libvlc.5.dylib" "${target_lib}" "lib"
246 vlc_install "src/${prefix}" "libvlccore.4.dylib" "${target_lib}" "lib"
247 pushd `pwd` > /dev/null
248 cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}/lib
249 ln -sf libvlc.5.dylib libvlc.dylib
250 ln -sf libvlccore.4.dylib libvlccore.dylib
251 popd > /dev/null
252
253 ##########################
254 # Build the share folder
255 echo "Building share folder..."
256 pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks"
257 mkdir -p ${target_share}
258 $pbxcp ${main_build_dir}/share/lua ${target_share}
259
260
261 ##########################
262 # Exporting headers
263 if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
264     echo "Exporting headers..."
265     mkdir -p ${target_include}/vlc
266     $pbxcp ${main_build_dir}/include/vlc/*.h ${target_include}/vlc
267 else
268     echo "Headers not needed for this product"
269 fi