]> git.sesse.net Git - vlc/blob - projects/macosx/framework/Pre-Compile.sh
833225d4d98d378f348a718775b9fb1da38efab5
[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 modules="modules"
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_modules="${target}/${modules}"    # 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/modules"
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     if ((! test -e ${lib_dest}) || test ${src_lib} -nt ${lib_dest} ); then
98
99         mkdir -p ${dest_dir}
100
101         # Lets copy the library from the source folder to our new destination folder
102         if [ "${type}" = "bin" ]; then
103             install -m 755 ${src_lib} ${lib_dest}
104         else
105             install -m 644 ${src_lib} ${lib_dest}
106         fi
107
108         # Update the dynamic library so it will know where to look for the other libraries
109         echo "Installing ${type} `basename ${lib_dest}`"
110
111         if [ "${type}" = "lib" ]; then
112             # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
113             install_name_tool -id "${install_name}/${lib_name}" ${lib_dest} > /dev/null
114             echo "ID=${install_name}/${lib_name}"
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             objects=""
153             tmp_dest_dir="$VLC_BUILD_DIR/tmp/$type"
154             mkdir -p "$tmp_dest_dir"
155             newinstall="no"
156             for arch in $ARCHS; do
157                 vlc_install_object "$VLC_BUILD_DIR/$arch/$1/$2" "$tmp_dest_dir" "$type" "$5" "" ".$arch"
158                 local dest="$tmp_dest_dir/$2.$arch"
159                 if test -e ${dest}; then
160                     if ! test "$dest_dir/$2" -nt "${dest}"; then
161                         newinstall="yes"
162                     fi
163                     objects="${dest} $objects"
164                 else
165                     echo "Warning: building $2 without $arch"
166                 fi
167             done;
168             if test "$newinstall" = "yes"; then
169                 echo "Creating fat $type $dest_dir/$2"
170                 lipo $objects -output "$dest_dir/$2" -create
171             fi
172         fi
173     fi
174 }
175 # @function vlc_install
176 ##########################
177
178 ##########################
179 # Create a symbolic link in the root of the framework
180 mkdir -p ${target_lib}
181 mkdir -p ${target_modules}
182 mkdir -p ${target_bin}
183
184 if [ "$RELEASE_MAKEFILE" != "yes" ] ; then
185     pushd `pwd` > /dev/null
186     cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
187
188     ln -sf Versions/Current/${lib} .
189     ln -sf Versions/Current/${modules} .
190     ln -sf Versions/Current/${include} .
191     ln -sf Versions/Current/${share} .
192     ln -sf Versions/Current/bin .
193     ln -sf ../modules Versions/Current/bin
194     ln -sf ../share Versions/Current/bin
195
196     popd > /dev/null
197 fi
198
199 ##########################
200 # Hack for VLC-release.app
201 if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
202     vlc_install "bin/${prefix}" "vlc" "${target}" "bin" "@loader_path/lib"
203     mv ${target}/vlc ${target}/VLC
204     chmod +x ${target}/VLC
205 elif [ "$FULL_PRODUCT_NAME" = "VLC-Plugin.plugin" ] ; then
206     # install Safari webplugin
207     vlc_install "projects/mozilla/${prefix}" "npvlc.${suffix}" "${target}" "lib" "@loader_path/lib"
208     mv ${target}/npvlc.${suffix} "${target}/VLC Plugin"
209     chmod +x "${target}/VLC Plugin"
210 else
211     vlc_install "bin/${prefix}" "vlc" "${target}/bin" "bin" "@loader_path/../lib"
212 fi
213
214
215 ##########################
216 # Build the modules folder (Same as VLCKit.framework/modules in Makefile)
217 echo "Building modules folder..."
218 # Figure out what modules are available to install
219 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
220     # Check to see that the reported module actually exists
221     if test -n ${module}; then
222         vlc_install `dirname ${module}` `basename ${module}` ${target_modules} "module"
223     fi
224 done
225
226 # Install the module cache
227 cache=`ls ${main_build_dir}/modules/plugins-*.dat | sed -e s:${main_build_dir}/::`
228 vlc_install `dirname ${cache}` `basename ${cache}` ${target_modules} "data"
229
230 # Build the lib folder
231 ##########################
232
233 vlc_install "src/${prefix}" "libvlc.5.dylib" "${target_lib}" "lib"
234 vlc_install "src/${prefix}" "libvlccore.4.dylib" "${target_lib}" "lib"
235 pushd `pwd` > /dev/null
236 cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}/lib
237 ln -sf libvlc.5.dylib libvlc.dylib
238 ln -sf libvlccore.4.dylib libvlccore.dylib
239 popd > /dev/null
240
241 ##########################
242 # Build the share folder
243 echo "Building share folder..."
244 pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks"
245 mkdir -p ${target_share}
246 $pbxcp ${main_build_dir}/share/lua ${target_share}
247
248
249 ##########################
250 # Exporting headers
251 if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
252     echo "Exporting headers..."
253     mkdir -p ${target_include}/vlc
254     $pbxcp ${main_build_dir}/include/vlc/*.h ${target_include}/vlc
255 else
256     echo "Headers not needed for this product"
257 fi