]> git.sesse.net Git - vlc/blob - projects/macosx/framework/Pre-Compile.sh
de9da9d52e21a149a5995dd17984e96b561e0bbf
[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 src_dir=$1
144     local src=$2
145     local dest_dir=$3
146     local type=$4
147
148     if test "$use_archs" = "no"; then
149         vlc_install_object "$VLC_BUILD_DIR/$src_dir/$src" "$dest_dir" "$type" $5
150     else
151         if test $type = "data"; then
152             vlc_install_object "$main_build_dir/$src_dir/$src" "$dest_dir" "$type" $5
153         else
154             fatdest="$dest_dir/$2"
155             shouldUpdateFat="no"
156
157             objects=""
158
159             # Create a temporary destination dir to store each ARCH object file
160             tmp_dest_dir="$VLC_BUILD_DIR/tmp/$type"
161             rm -Rf "${tmp_dest_dir}/*"
162             mkdir -p "$tmp_dest_dir"
163
164             for arch in $ARCHS; do
165                 local src="$VLC_BUILD_DIR/$arch/$src_dir/$src"
166
167                 # Only install if the new image is newer than the one we have installed.
168                 if ((! test -e ${fatdest}) || test ${src} -nt ${fatdest} ); then
169                     vlc_install_object "$src" "$tmp_dest_dir" "$type" "$5" "" ".$arch"
170                     local dest="$tmp_dest_dir/$src.$arch"
171                     if test -e ${dest}; then
172                         if ! test "$dest_dir/$src" -nt "${dest}"; then
173                             shouldUpdateFat="yes"
174                         fi
175                         objects="${dest} $objects"
176                     else
177                         echo "Warning: building $src without $arch"
178                     fi
179                 fi
180             done;
181
182             if test "$shouldUpdateFat" = "yes"; then
183                 echo "Creating fat $type $fatdest"
184                 lipo $objects -output "$fatdest" -create
185             fi
186         fi
187     fi
188 }
189 # @function vlc_install
190 ##########################
191
192 ##########################
193 # Create a symbolic link in the root of the framework
194 mkdir -p ${target_lib}
195 mkdir -p ${target_plugins}
196 mkdir -p ${target_bin}
197
198 if [ "$RELEASE_MAKEFILE" != "yes" ] ; then
199     pushd `pwd` > /dev/null
200     cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
201
202     ln -sf Versions/Current/${lib} .
203     ln -sf Versions/Current/${plugins} .
204     ln -sf Versions/Current/${include} .
205     ln -sf Versions/Current/${share} .
206     ln -sf Versions/Current/bin .
207     ln -sf ../plugins Versions/Current/bin
208     ln -sf ../share Versions/Current/bin
209
210     popd > /dev/null
211 fi
212
213 ##########################
214 # Hack for VLC-release.app
215 if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
216     vlc_install "bin/${prefix}" "vlc" "${target}" "bin" "@loader_path/lib"
217     mv ${target}/vlc ${target}/VLC
218     chmod +x ${target}/VLC
219 elif [ "$FULL_PRODUCT_NAME" = "VLC-Plugin.plugin" ] ; then
220     # install Safari webplugin
221     vlc_install "projects/mozilla/${prefix}" "npvlc.${suffix}" "${target}" "lib" "@loader_path/lib"
222     mv ${target}/npvlc.${suffix} "${target}/VLC Plugin"
223     chmod +x "${target}/VLC Plugin"
224 else
225     vlc_install "bin/${prefix}" "vlc" "${target}/bin" "bin" "@loader_path/../lib"
226 fi
227
228
229 ##########################
230 # Build the plugins folder (Same as VLCKit.framework/plugins in Makefile)
231 echo "Building plugins folder..."
232 # Figure out what plugins are available to install
233 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
234     # Check to see that the reported module actually exists
235     if test -n ${module}; then
236         vlc_install `dirname ${module}` `basename ${module}` ${target_plugins} "module"
237     fi
238 done
239
240 # Install the module cache
241 cache=`ls ${main_build_dir}/modules/plugins-*.dat | sed -e s:${main_build_dir}/::`
242 vlc_install `dirname ${cache}` `basename ${cache}` ${target_plugins} "data"
243
244 # Build the lib folder
245 ##########################
246
247 vlc_install "src/${prefix}" "libvlc.5.dylib" "${target_lib}" "lib"
248 vlc_install "src/${prefix}" "libvlccore.4.dylib" "${target_lib}" "lib"
249 pushd `pwd` > /dev/null
250 cd ${target_lib}
251 ln -sf libvlc.5.dylib libvlc.dylib
252 ln -sf libvlccore.4.dylib libvlccore.dylib
253 popd > /dev/null
254
255 ##########################
256 # Build the share folder
257 echo "Building share folder..."
258 pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks"
259 mkdir -p ${target_share}
260 $pbxcp ${main_build_dir}/share/lua ${target_share}
261
262
263 ##########################
264 # Exporting headers
265 if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
266     echo "Exporting headers..."
267     mkdir -p ${target_include}/vlc
268     $pbxcp ${VLC_SRC_DIR}/include/vlc/*.h ${target_include}/vlc
269 else
270     echo "Headers not needed for this product"
271 fi