]> git.sesse.net Git - vlc/blob - projects/macosx/framework/Pre-Compile.sh
15c33699bc94cb51c7885f8ec72d1ee8cf411b73
[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 fi
12
13 # Hack to use that script with the current VLC-release.app
14 if test "${ACTION}" = "VLC-release.app"; then
15     TARGET_BUILD_DIR="${build_dir}"
16     FULL_PRODUCT_NAME="VLC-release.app"
17     CONTENTS_FOLDER_PATH="${FULL_PRODUCT_NAME}/Contents/MacOS"
18     VLC_BUILD_DIR="${build_dir}"
19     VLC_SRC_DIR="${src_dir}"
20     ACTION="build"
21 fi
22
23 if test "${ACTION}" = "build"; then    
24     lib="lib"
25     modules="modules"
26     share="share"
27     target="${TARGET_BUILD_DIR}/${CONTENTS_FOLDER_PATH}"
28     target_lib="${target}/${lib}"            # Should we consider using a different well-known folder like shared resources?
29     target_modules="${target}/${modules}"    # Should we consider using a different well-known folder like shared resources?
30     target_share="${target}/${share}"    # Should we consider using a different well-known folder like shared resources?
31     linked_libs=" "
32     
33     ##########################
34     # @function install_library(src_lib, dest_dir, type, lib_install_prefix, destination_name)
35     # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
36     # @param src_lib     source library to copy to the destination directory
37     # @param dest_dir    destination directory where the src_lib should be copied to
38     install_library() { 
39    
40         if [ ${3} = "library" ]; then
41             local install_name="@loader_path/lib"
42         elif [ ${3} = "module" ]; then
43             local install_name="@loader_path/modules"
44         fi
45         if [ "${5}" != "" ]; then
46             local lib_dest="${2}/${5}"
47         else
48             local lib_dest="${2}/`basename ${1}`"
49         fi
50
51         if [ "${4}" != "" ]; then
52             local lib_install_prefix="${4}"
53         else
54             local lib_install_prefix="@loader_path/../lib"
55         fi
56         
57         if test -e ${1} && ((! test -e ${lib_dest}) || test ${1} -nt ${lib_dest} ); then
58             
59             mkdir -p ${2}
60
61             # Lets copy the library from the source folder to our new destination folder
62             install -m 644 ${1} ${lib_dest}
63
64             # Update the dynamic library so it will know where to look for the other libraries
65             echo "Installing ${3} `basename ${lib_dest}`"
66
67             if [ "${3}" != "bin" ]; then
68                 # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
69                 install_name_tool -id "${install_name}/`basename ${lib_dest}`" ${lib_dest} > /dev/null
70             fi
71     
72             # Iterate through each installed library and modify the references to other dynamic libraries to match the framework's library directory
73             for linked_lib in `otool -L ${lib_dest}  | grep '(' | sed 's/\((.*)\)//'`; do
74                 local name=`basename ${linked_lib}`
75                 case "${linked_lib}" in
76                     */vlc_build_dir/*  | *vlc* | */extras/contrib/lib/*)
77                         if test -e ${linked_lib}; then
78                             install_name_tool -change "$linked_lib" "${lib_install_prefix}/${name}" "${lib_dest}"
79                             linked_libs="${linked_libs} ${ref_lib}"
80                             install_library ${linked_lib} ${target_lib} "library"
81                         fi
82                         ;;
83                 esac
84             done
85          fi
86     }
87     # @function install_library
88     ##########################
89
90     ##########################
91     # Hack for VLC-release.app
92     if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
93         prefix=".libs/"
94         install_library "${VLC_BUILD_DIR}/src/${prefix}vlc" "${target}" "bin" "@loader_path/lib"
95         mv ${target}/vlc ${target}/VLC
96         chmod +x ${target}/VLC
97     else
98         prefix=""
99     fi
100
101     ##########################
102     # Build the modules folder (Same as VLCKit.framework/modules in Makefile)
103     echo "Building modules folder..."
104     # Figure out what modules are available to install
105     for module in `find ${VLC_BUILD_DIR}/modules -name *.so` ; do
106         # Check to see that the reported module actually exists
107         if test -n ${module}; then
108             install_library ${module} ${target_modules} "module"
109         fi
110     done
111     # Build the modules folder
112     ##########################
113
114     ##########################
115     # Create a symbolic link in the root of the framework
116     mkdir -p ${target_lib}
117     mkdir -p ${target_modules}
118     
119     pushd `pwd` > /dev/null 
120     cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
121     
122     ln -sf Versions/Current/${lib} .
123     ln -sf Versions/Current/${modules} .
124     
125     popd > /dev/null 
126     # Create a symbolic link in the root of the framework
127     ##########################
128     
129     ##########################
130     # Build the library folder
131     echo "Building library folder... ${linked_libs}"
132     for linked_lib in ${linked_libs} ; do
133         case "${linked_lib}" in
134             */extras/contrib/lib/*.dylib)
135                 if test -e ${linked_lib}; then
136                     install_library ${linked_lib} ${target_lib} "library"
137                 fi
138                 ;;
139             */vlc_install_dir/lib/*.dylib)
140                 if test -e ${linked_lib}; then
141                     install_library ${linked_lib} ${target_lib} "library"
142                 fi
143                 ;;
144         esac
145     done
146
147
148     install_library "${VLC_BUILD_DIR}/src/${prefix}libvlc-control.dylib" ${target_lib} "library"
149     install_library "${VLC_BUILD_DIR}/src/${prefix}libvlc.dylib" ${target_lib} "library"
150
151     ##########################
152     # Build the share folder
153     echo "Building share folder..."
154     pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks"
155     mkdir -p ${target_share}
156     $pbxcp ${VLC_SRC_DIR}/share/lua ${target_share}
157 fi