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