]> git.sesse.net Git - vlc/blob - projects/macosx/framework/Pre-Compile.sh
macosx/framework: Build a fat framework (x86_64 and i386) in Release mode.
[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}" != "build"; then
37     echo "This script is supposed to run from xcodebuild or Xcode"
38     exit 1
39 fi
40
41 lib="lib"
42 modules="modules"
43 share="share"
44 include="include"
45 target="${TARGET_BUILD_DIR}/${CONTENTS_FOLDER_PATH}"
46 target_lib="${target}/${lib}"            # Should we consider using a different well-known folder like shared resources?
47 target_modules="${target}/${modules}"    # Should we consider using a different well-known folder like shared resources?
48 target_share="${target}/${share}"    # Should we consider using a different well-known folder like shared resources?
49 target_include="${target}/${include}"    # Should we consider using a different well-known folder like shared resources?
50 linked_libs=""
51 prefix=".libs/"
52 suffix="dylib"
53
54
55 ##########################
56 # @function vlc_install_object(src_lib, dest_dir, type, lib_install_prefix, destination_name)
57 # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
58 # @param src_lib     source library to copy to the destination directory
59 # @param dest_dir    destination directory where the src_lib should be copied to
60 vlc_install_object() {
61
62     local src_lib=${1}
63     local dest_dir=${2}
64     local type=${3}
65     local lib_install_prefix=${4}
66     local destination_name=${5}
67     local suffix=${6}
68
69     if [ $type = "library" ]; then
70         local install_name="@loader_path/lib"
71     elif [ $type = "module" ]; then
72         local install_name="@loader_path/modules"
73     fi
74     if [ "$destination_name" != "" ]; then
75         local lib_dest="$dest_dir/$destination_name$suffix"
76     else
77         local lib_dest="$dest_dir/`basename $src_lib`$suffix"
78     fi
79
80     if [ "$lib_install_prefix" != "" ]; then
81         local lib_install_prefix="$lib_install_prefix"
82     else
83         local lib_install_prefix="@loader_path/../lib"
84     fi
85
86     if ! test -e ${src_lib}; then
87         return
88     fi
89     if ((! test -e ${lib_dest}) || test ${src_lib} -nt ${lib_dest} ); then
90
91         mkdir -p ${dest_dir}
92
93         # Lets copy the library from the source folder to our new destination folder
94         if [ "${type}" = "bin" ]; then
95             install -m 755 ${src_lib} ${lib_dest}
96         else
97             install -m 644 ${src_lib} ${lib_dest}
98         fi
99
100         # Update the dynamic library so it will know where to look for the other libraries
101         echo "Installing ${type} `basename ${lib_dest}`"
102
103         if [ "${type}" = "lib" ]; then
104             # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
105             install_name_tool -id "${install_name}/`basename ${lib_dest}`" ${lib_dest} > /dev/null
106         fi
107
108         if [ "${type}" != "data" ]; then
109             # Iterate through each installed library and modify the references to other dynamic libraries to match the framework's library directory
110             for linked_lib in `otool -L ${lib_dest}  | grep '(' | sed 's/\((.*)\)//'`; do
111                 local name=`basename ${linked_lib}`
112                 case "${linked_lib}" in
113                     */vlc_build_dir/* | */vlc_install_dir/* | *vlc* | */extras/contrib/lib/*)
114                         if test -e ${linked_lib}; then
115                             install_name_tool -change "$linked_lib" "${lib_install_prefix}/${name}" "${lib_dest}"
116                             linked_libs="${linked_libs} ${ref_lib}"
117                             vlc_install_object ${linked_lib} ${target_lib} "library"
118                         fi
119                         ;;
120                 esac
121             done
122         fi
123      fi
124 }
125 # @function vlc_install
126 ##########################
127
128 ##########################
129 # @function vlc_install(src_lib_dir, src_lib_name, dest_dir, type, lib_install_prefix)
130 # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
131 # @param src_lib     source library to copy to the destination directory
132 # @param dest_dir    destination directory where the src_lib should be copied to
133 vlc_install() {
134     local dest_dir=$3
135     local type=$4
136
137     if test "$use_archs" = "no"; then
138         vlc_install_object "$VLC_BUILD_DIR/$1/$2" "$dest_dir" "$type" $5
139     else
140         if test $type = "data"; then
141             vlc_install_object "$main_build_dir/$1/$2" "$dest_dir" "$type" $5
142         else
143             objects=""
144             mkdir -p "tmp/$1"
145             newinstall="no"
146             for arch in $ARCHS; do
147                 vlc_install_object "$VLC_BUILD_DIR/$arch/$1/$2" "tmp/$1" "$type" "$5" "$2.$arch"
148                 local dest="tmp/$1/$2.$arch"
149                 if test -e ${dest}; then
150                     if test "$VLC_BUILD_DIR/$arch/$1/$2" -nt "${dest}"; then
151                         echo "$VLC_BUILD_DIR/$arch/$1/$2 newer than ${dest}"
152                         newinstall="yes"
153                     fi
154                     objects="${dest} $objects"
155                 else
156                     echo "Warning: building $2 without $arch"
157                 fi
158             done;
159             if test "$newinstall" = "yes"; then
160                 echo "Creating fat $type $2"
161                 lipo $objects -output "${dest}" -create
162             fi
163         fi
164     fi
165 }
166 # @function vlc_install
167 ##########################
168
169 ##########################
170 # Hack for VLC-release.app
171 if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
172     vlc_install "bin/${prefix}" "vlc" "${target}" "bin" "@loader_path/lib"
173     mv ${target}/vlc ${target}/VLC
174     chmod +x ${target}/VLC
175 elif [ "$FULL_PRODUCT_NAME" = "VLC-Plugin.plugin" ] ; then
176     # install Safari webplugin
177     vlc_install "projects/mozilla/${prefix}" "npvlc.${suffix}" "${target}" "library" "@loader_path/lib"
178     mv ${target}/npvlc.${suffix} "${target}/VLC Plugin"
179     chmod +x "${target}/VLC Plugin"
180 else
181     vlc_install "bin/${prefix}" "vlc" "${target}/bin" "bin" "@loader_path/../lib"
182 fi
183
184 ##########################
185 # Build the modules folder (Same as VLCKit.framework/modules in Makefile)
186 echo "Building modules folder..."
187 # Figure out what modules are available to install
188 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
189     # Check to see that the reported module actually exists
190     if test -n ${module}; then
191         vlc_install `dirname ${module}` `basename ${module}` ${target_modules} "module"
192     fi
193 done
194
195 # Install the module cache
196 cache=`ls ${main_build_dir}/modules/plugins-*.dat | sed -e s:${main_build_dir}/::`
197 vlc_install `dirname ${cache}` `basename ${cache}` ${target_modules} "data"
198
199 # Build the modules folder
200 ##########################
201
202 ##########################
203 # Create a symbolic link in the root of the framework
204 mkdir -p ${target_lib}
205 mkdir -p ${target_modules}
206
207 if [ "$RELEASE_MAKEFILE" != "yes" ] ; then
208     pushd `pwd` > /dev/null
209     cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
210
211     ln -sf Versions/Current/${lib} .
212     ln -sf Versions/Current/${modules} .
213     ln -sf Versions/Current/${include} .
214     ln -sf Versions/Current/${share} .
215     ln -sf Versions/Current/bin .
216     ln -sf ../modules Versions/Current/bin
217     ln -sf ../share Versions/Current/bin
218
219     popd > /dev/null
220 fi
221
222 vlc_install "src/${prefix}" "libvlc.5.dylib" "${target_lib}" "library"
223 vlc_install "src/${prefix}" "libvlccore.4.dylib" "${target_lib}" "library"
224 pushd `pwd` > /dev/null
225 cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}/lib
226 ln -sf libvlc.5.dylib libvlc.dylib
227 ln -sf libvlccore.4.dylib libvlccore.dylib
228 popd > /dev/null
229
230 ##########################
231 # Build the share folder
232 echo "Building share folder..."
233 pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks"
234 mkdir -p ${target_share}
235 $pbxcp ${main_build_dir}/share/lua ${target_share}
236
237
238 ##########################
239 # Exporting headers
240 if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
241     echo "Exporting headers..."
242     mkdir -p ${target_include}/vlc
243     $pbxcp ${main_build_dir}/include/vlc/*.h ${target_include}/vlc
244 else
245     echo "Headers not needed for this product"
246 fi