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