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