]> git.sesse.net Git - vlc/blob - extras/package/macosx/build-package.sh
addon manager: fix compilation with older xcode releases
[vlc] / extras / package / macosx / build-package.sh
1 #!/bin/sh
2 #
3 # build-package.sh
4 #
5 # Script that installs libvlc to VLC.app
6
7 # We are building VLC.app
8 #
9 if test "${ACTION}" = "release-makefile"; then
10     echo "running build-package.sh in release-makefile mode"
11
12     FULL_PRODUCT_NAME="${PRODUCT}"
13     TARGET_BUILD_DIR="${build_dir}"
14     CONTENTS_FOLDER_PATH="${FULL_PRODUCT_NAME}/Contents/MacOS"
15     VLC_BUILD_DIR="${build_dir}"
16     VLC_SRC_DIR="${src_dir}"
17     ACTION="build"
18     RELEASE_MAKEFILE="yes"
19     use_archs="no"
20     main_build_dir="${VLC_BUILD_DIR}"
21 else
22     use_archs="yes"
23     main_build_dir="${VLC_BUILD_DIR}/${ARCHS%% *}"
24     echo "Building for $ARCHS"
25 fi
26
27 if test "${ACTION}" = "clean"; then
28     rm -Rf "${VLC_BUILD_DIR}/tmp"
29     exit 0
30 fi
31
32 if test "${ACTION}" != "build"; then
33     echo "This script is supposed to run from xcodebuild or Xcode"
34     exit 1
35 fi
36
37 lib="lib"
38 plugins="plugins"
39 share="share"
40 include="include"
41 target="${TARGET_BUILD_DIR}/${CONTENTS_FOLDER_PATH}"
42 target_bin="${target}/bin"
43 target_lib="${target}/${lib}"            # Should we consider using a different well-known folder like shared resources?
44 target_plugins="${target}/${plugins}"    # Should we consider using a different well-known folder like shared resources?
45 target_share="${target}/${share}"        # Should we consider using a different well-known folder like shared resources?
46 linked_libs=""
47 prefix=".libs"
48 suffix="dylib"
49 num_archs=$(echo `echo $ARCHS | wc -w`)
50
51 ##########################
52 # @function vlc_install_object(src_lib, dest_dir, type, lib_install_prefix, destination_name, suffix)
53 # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
54 # @param src_lib     source library to copy to the destination directory
55 # @param dest_dir    destination directory where the src_lib should be copied to
56 vlc_install_object() {
57     local src_lib=${1}
58     local dest_dir=${2}
59     local type=${3}
60     local lib_install_prefix=${4}
61     local destination_name=${5}
62     local suffix=${6}
63
64     if [ $type = "library" ]; then
65         local install_name="@loader_path/lib"
66     elif [ $type = "module" ]; then
67         local install_name="@loader_path/plugins"
68     fi
69     if [ "$destination_name" != "" ]; then
70         local lib_dest="$dest_dir/$destination_name$suffix"
71         local lib_name=`basename $destination_name`
72     else
73         local lib_dest="$dest_dir/`basename $src_lib`$suffix"
74         local lib_name=`basename $src_lib`
75     fi
76
77     if [ "x$lib_install_prefix" != "x" ]; then
78         local lib_install_prefix="$lib_install_prefix"
79     else
80         local lib_install_prefix="@loader_path/../lib"
81     fi
82
83     if test ! -e ${src_lib}; then
84         return
85     fi
86
87     if ( (test ! -e ${lib_dest}) || test ${src_lib} -nt ${lib_dest} ); then
88
89         mkdir -p ${dest_dir}
90
91         # Lets copy the library from the source folder to our new destination folder
92         if [ "${type}" = "bin" ]; then
93             install -m 755 ${src_lib} ${lib_dest}
94         else
95             install -m 644 ${src_lib} ${lib_dest}
96         fi
97
98         # Update the dynamic library so it will know where to look for the other libraries
99         echo "Installing ${type} `basename ${lib_dest}`"
100
101         if [ "${type}" = "library" ]; then
102             # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
103             install_name_tool -id "${install_name}/${lib_name}" ${lib_dest} > /dev/null
104         fi
105
106         if [ "${type}" != "data" ]; then
107             # Iterate through each installed library and modify the references to other dynamic libraries to match the framework's library directory
108             for linked_lib in `otool -L ${lib_dest}  | grep '(' | sed 's/\((.*)\)//'`; do
109                 local name=`basename ${linked_lib}`
110                 case "${linked_lib}" in
111                     */vlc_build_dir/* | */vlc_install_dir/* | *vlc* | */extras/contrib/*)
112                         if test -e ${linked_lib}; then
113                             install_name_tool -change "$linked_lib" "${lib_install_prefix}/${name}" "${lib_dest}"
114                             linked_libs="${linked_libs} ${ref_lib}"
115                             vlc_install_object ${linked_lib} ${target_lib} "library"
116                         fi
117                         ;;
118                 esac
119             done
120         fi
121      fi
122 }
123 # @function vlc_install_object
124 ##########################
125
126 ##########################
127 # @function vlc_install(src_lib_dir, src_lib_name, dest_dir, type, lib_install_prefix)
128 # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
129 # @param src_lib     source library to copy to the destination directory
130 # @param dest_dir    destination directory where the src_lib should be copied to
131 vlc_install() {
132     local src_dir=$1
133     local src=$2
134     local dest_dir=$3
135     local type=$4
136
137     if test "$use_archs" = "no"; then
138         vlc_install_object "$VLC_BUILD_DIR/$src_dir/$src" "$dest_dir" "$type" $5
139     else
140         if test $type = "data"; then
141             vlc_install_object "$main_build_dir/$src_dir/$src" "$dest_dir" "$type" $5
142         else
143             local fatdest="$dest_dir/$2"
144             local shouldUpdate="no"
145
146             # Determine what architectures are available in the destination image
147             local fatdest_archs=""
148             if [ -e ${fatdest} ]; then
149                 fatdest_archs=`lipo -info "${fatdest}" 2> /dev/null | sed -E -e 's/[[:space:]]+$//' -e 's/.+:[[:space:]]*//' -e 's/[^[:space:]]+/(&)/g'`
150
151                 # Check to see if the destination image needs to be reconstructed
152                 for arch in $ARCHS; do
153                     # Only install if the new image is newer than the one we have installed or the required arch is missing.
154                     if test $shouldUpdate = "no"  && (! [[ "$fatdest_archs" =~ \($arch\) ]] || test "$VLC_BUILD_DIR/$arch/$src_dir/$src" -nt "${fatdest}"); then
155                         shouldUpdate="yes"
156                     fi
157                     fatdest_archs=${fatdest_archs//\($arch\)/}
158                 done
159
160                 # Reconstruct the destination image, if the update flag is set or if there are more archs in the desintation then we need
161                 fatdest_archs=${fatdest_archs// /}
162             else
163                 # If the destination image does not exist, then we have to reconstruct it
164                 shouldUpdate="yes"
165             fi
166
167             # If we should update the destination image or if there were unexpected archs in the destination image, then reconstruct it
168             if test "$shouldUpdate" = "yes" || test -n "${fatdest_archs}"; then
169                 # If the destination image exists, get rid of it so we can copy over the newly constructed image
170                 if test -e ${fatdest}; then
171                     rm "$fatdest"
172                 fi
173
174                 if test "$num_archs" = "1"; then
175                     echo "Copying $ARCHS $type $fatdest"
176                     local arch_src="$VLC_BUILD_DIR/$ARCHS/$src_dir/$src"
177                     vlc_install_object "$arch_src" "$dest_dir" "$type" "$5" ""
178                 else
179                     # Create a temporary destination dir to store each ARCH object file
180                     local tmp_dest_dir="$VLC_BUILD_DIR/tmp/$type"
181                     rm -Rf "${tmp_dest_dir}/*"
182                     mkdir -p "$tmp_dest_dir"
183
184                     # Search for each ARCH object file used to construct a fat image
185                     local objects=""
186                     for arch in $ARCHS; do
187                         local arch_src="$VLC_BUILD_DIR/$arch/$src_dir/$src"
188                         vlc_install_object "$arch_src" "$tmp_dest_dir" "$type" "$5" "" ".$arch"
189                         local dest="$tmp_dest_dir/$src.$arch"
190                         if [ -e ${dest} ]; then
191                             objects="${dest} $objects"
192                         else
193                             echo "Warning: building $arch_src without $arch"
194                         fi
195                     done;
196
197                     echo "Creating fat $type $fatdest"
198                     lipo $objects -output "$fatdest" -create
199                 fi
200             fi
201         fi
202     fi
203 }
204 # @function vlc_install
205 ##########################
206
207 ##########################
208 # Create a symbolic link in the root of the framework
209 mkdir -p ${target_lib}
210 mkdir -p ${target_plugins}
211 mkdir -p ${target_bin}
212
213 if [ "$RELEASE_MAKEFILE" != "yes" ] ; then
214     pushd `pwd` > /dev/null
215     cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
216
217     ln -sf Versions/Current/${lib} .
218     ln -sf Versions/Current/${plugins} .
219     ln -sf Versions/Current/${include} .
220     ln -sf Versions/Current/${share} .
221     ln -sf Versions/Current/bin .
222     ln -sf ../plugins Versions/Current/bin
223     ln -sf ../share Versions/Current/bin
224
225     popd > /dev/null
226 fi
227
228 ##########################
229 # Hack for VLC.app
230 if [ "$FULL_PRODUCT_NAME" = "VLC.app" ] ; then
231     vlc_install "bin/${prefix}" "vlc" "${target}" "bin" "@loader_path/lib"
232     mv ${target}/vlc ${target}/VLC
233     chmod +x ${target}/VLC
234 else
235     vlc_install "bin/${prefix}" "vlc" "${target}/bin" "bin" "@loader_path/../lib"
236 fi
237
238 ##########################
239 # Build the plugins folder
240 echo "Building plugins folder..."
241 # Figure out what plugins are available to install
242 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
243     # Check to see that the reported module actually exists
244     if test -n ${module}; then
245         vlc_install `dirname ${module}` `basename ${module}` ${target_plugins} "module"
246     fi
247 done
248
249 ##########################
250 # Build the lib folder
251 vlc_install "lib/${prefix}" "libvlc.5.dylib" "${target_lib}" "library"
252 vlc_install "src/${prefix}" "libvlccore.7.dylib" "${target_lib}" "library"
253 pushd `pwd` > /dev/null
254 cd ${target_lib}
255 ln -sf libvlc.5.dylib libvlc.dylib
256 ln -sf libvlccore.7.dylib libvlccore.dylib
257 popd > /dev/null
258
259 ##########################
260 # Build the share folder
261 if [ $PRODUCT != "VLC.app" ]; then
262     echo "Building share folder..."
263     pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks -v -V"
264     mkdir -p ${target_share}
265     if test "$use_archs" = "no"; then
266         $pbxcp ${VLC_BUILD_DIR}/share/lua ${target_share}
267     else
268         $pbxcp ${main_build_dir}/share/lua ${target_share}
269     fi
270 fi