MacOSX/Framework: Merge Enrique Osuna's work on the Framework.
[vlc.git] / extras / MacOSX / Framework / Pre-Compile.sh
1 if [ ${ACTION} = "" ]; then
2         # Debug --
3         TARGET_BUILD_DIR="."
4         FULL_PRODUCT_NAME="VLC.framework"
5         CONTENTS_FOLDER_PATH="${FULL_PRODUCT_NAME}/Versions/A"
6         VLC_BUILD_DIR="../../.."
7         VLC_SRC_DIR="../../.."
8         # Debug --
9 fi
10
11 if [ ${ACTION} = "build" ]; then        
12         vlc_config="${VLC_SRC_DIR}/vlc-config"
13         lib="lib"
14         modules="modules"
15         target="${TARGET_BUILD_DIR}/${CONTENTS_FOLDER_PATH}"
16         target_lib="${target}/${lib}"                   # Should we consider using a different well-known folder like shared resources?
17         target_modules="${target}/${modules}"   # Should we consider using a different well-known folder like shared resources?
18         
19     ##########################
20     # @function install_library(src_lib, dest_dir)
21         # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
22         # @param src_lib        source library to copy to the destination directory
23         # @param dest_dir       destination directory where the src_lib should be copied to
24         install_library() {     
25                 if [ ${3} = "library" ]; then
26                         install_name="@loader_path/lib"
27                 else
28                         install_name="@loader_path/modules"
29                 fi
30                 
31                 if [ "${4}" != "" ]; then
32                         lib_dest="${2}/${4}"
33                 else
34                         lib_dest="${2}/`basename ${1}`"
35                 fi
36                 
37                 if test -e ${1} && ! test -e ${lib_dest}; then
38                         mkdir -p ${2}
39                         
40                         # Lets copy the library from the source folder to our new destination folder
41                         cp ${1} ${lib_dest}
42
43                         # Update the dynamic library so it will know where to look for the other libraries
44                         echo "Installing ${3} `basename ${lib_dest}`"
45
46                         # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
47                         install_name_tool -change /usr/local/lib/libvlc.1.dylib @loader_path/../lib/libvlc.dylib ${lib_dest}
48                         install_name_tool -change @executable_path/lib/vlc_libintl.dylib @loader_path/../lib/vlc_libintl.dylib ${lib_dest}
49                         install_name_tool -id "${install_name}/`basename ${lib_dest}`" ${lib_dest}
50
51                         # Iterate through each installed library and modify the references to other dynamic libraries to match the framework's library directory
52                         for linked_lib in `otool -L "${lib_dest}" | grep @executable_path | sed 's/(\([0-z]*\ *\.*\,*\)*)//g'` ; do
53                                 ref_lib=`echo "${linked_lib}" | sed 's:executable_path/:loader_path/../:'`
54                                 install_name_tool -change ${linked_lib} ${ref_lib} ${lib_dest}
55                         done
56                 fi
57         }
58         # @function install_library
59     ##########################
60
61     ##########################
62         # Create a symbolic link in the root of the framework
63         mkdir -p ${target_lib}
64         mkdir -p ${target_modules}
65         
66         pushd `pwd` > /dev/null 
67         cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
68         
69         ln -sf Versions/Current/${lib} .
70         ln -sf Versions/Current/${modules} .
71         
72         popd > /dev/null 
73         # Create a symbolic link in the root of the framework
74     ##########################
75         
76     ##########################
77     # Build the library folder (Same as VLC.framework/lib in Makefile)
78         echo "Building library folder..."
79
80         # Check to see if there are any vlc libraries available
81         echo "Copying VLC libraries..."
82         if test -d ${VLC_BUILD_DIR}/extras/contrib/vlc-lib; then
83                 # Iterate through the dyanmic libraries available
84                 for lib_src in ${VLC_BUILD_DIR}/extras/contrib/vlc-lib/*.dylib ; do
85                         install_library ${lib_src} ${target_lib} "library"
86                 done
87         fi
88
89         # Check to see if there are any core libraries available
90         echo "Copying core libraries..."
91 #       if test -d ${VLC_BUILD_DIR}/src/.libs; then
92 #               # Iterate through all the core libraries
93 #               for lib_src = ${VLC_BUILD_DIR}/src/.libs/*.dylib; do
94 #                       # Only install the library if it is not a symbolic link
95 #                       if ! test -L ${lib_src}; then
96 #                               echo "install_library ${lib_src} ${target_lib} `echo "${lib_src}" | sed 's:(.\d+)+.dylib:.dylib:'`"
97 #                       fi
98 #               done
99 #       fi
100
101         install_library "${VLC_BUILD_DIR}/src/.libs/libvlc.dylib" ${target_lib} "library"
102         install_library "${VLC_BUILD_DIR}/src/.libs/libvlc-control.dylib" ${target_lib} "library"
103         install_library "${VLC_BUILD_DIR}/extras/contrib/vlc-lib/vlc_libintl.dylib" ${target_lib} "library"
104     # Build the library folder
105     ##########################
106
107     ##########################
108     # Build the modules folder (Same as VLC.framework/modules in Makefile)
109         echo "Building modules folder..."
110         # Figure out what modules are available to install
111         for module in `top_builddir="${VLC_BUILD_DIR}" ${vlc_config} --target plugin` ; do
112                 # Check to see that the reported module actually exists
113                 if test -n ${module}; then
114                         module_src="`dirname ${module}`/.libs/`basename ${module}`.dylib"
115                         install_library ${module_src} ${target_modules} "module"
116                 fi
117     done
118         
119     # Build the modules folder
120     ##########################
121 fi
122 if [ ${ACTION} = "" ]; then
123         # Debug --
124         TARGET_BUILD_DIR="."
125         FULL_PRODUCT_NAME="VLC.framework"
126         CONTENTS_FOLDER_PATH="${FULL_PRODUCT_NAME}/Versions/A"
127         VLC_BUILD_DIR="../../.."
128         VLC_SRC_DIR="../../.."
129         # Debug --
130 fi
131
132 if [ ${ACTION} = "build" ]; then        
133         vlc_config="${VLC_SRC_DIR}/vlc-config"
134         lib="lib"
135         modules="modules"
136         target="${TARGET_BUILD_DIR}/${CONTENTS_FOLDER_PATH}"
137         target_lib="${target}/${lib}"                   # Should we consider using a different well-known folder like shared resources?
138         target_modules="${target}/${modules}"   # Should we consider using a different well-known folder like shared resources?
139         
140     ##########################
141     # @function install_library(src_lib, dest_dir)
142         # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
143         # @param src_lib        source library to copy to the destination directory
144         # @param dest_dir       destination directory where the src_lib should be copied to
145         install_library() {     
146                 if [ ${3} = "library" ]; then
147                         install_name="@loader_path/lib"
148                 else
149                         install_name="@loader_path/modules"
150                 fi
151                 
152                 if [ "${4}" != "" ]; then
153                         lib_dest="${2}/${4}"
154                 else
155                         lib_dest="${2}/`basename ${1}`"
156                 fi
157                 
158                 if test -e ${1} && ! test -e ${lib_dest}; then
159                         mkdir -p ${2}
160                         
161                         # Lets copy the library from the source folder to our new destination folder
162                         cp ${1} ${lib_dest}
163
164                         # Update the dynamic library so it will know where to look for the other libraries
165                         echo "Installing ${3} `basename ${lib_dest}`"
166
167                         # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
168                         install_name_tool -change /usr/local/lib/libvlc.1.dylib @loader_path/../lib/libvlc.dylib ${lib_dest}
169                         install_name_tool -change @executable_path/lib/vlc_libintl.dylib @loader_path/../lib/vlc_libintl.dylib ${lib_dest}
170                         install_name_tool -id "${install_name}/`basename ${lib_dest}`" ${lib_dest}
171
172                         # Iterate through each installed library and modify the references to other dynamic libraries to match the framework's library directory
173                         for linked_lib in `otool -L "${lib_dest}" | grep @executable_path | sed 's/(\([0-z]*\ *\.*\,*\)*)//g'` ; do
174                                 ref_lib=`echo "${linked_lib}" | sed 's:executable_path/:loader_path/../:'`
175                                 install_name_tool -change ${linked_lib} ${ref_lib} ${lib_dest}
176                         done
177                 fi
178         }
179         # @function install_library
180     ##########################
181
182     ##########################
183         # Create a symbolic link in the root of the framework
184         mkdir -p ${target_lib}
185         mkdir -p ${target_modules}
186         
187         pushd `pwd` > /dev/null 
188         cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
189         
190         ln -sf Versions/Current/${lib} .
191         ln -sf Versions/Current/${modules} .
192         
193         popd > /dev/null 
194         # Create a symbolic link in the root of the framework
195     ##########################
196         
197     ##########################
198     # Build the library folder (Same as VLC.framework/lib in Makefile)
199         echo "Building library folder..."
200
201         # Check to see if there are any vlc libraries available
202         echo "Copying VLC libraries..."
203         if test -d ${VLC_BUILD_DIR}/extras/contrib/vlc-lib; then
204                 # Iterate through the dyanmic libraries available
205                 for lib_src in ${VLC_BUILD_DIR}/extras/contrib/vlc-lib/*.dylib ; do
206                         install_library ${lib_src} ${target_lib} "library"
207                 done
208         fi
209
210         # Check to see if there are any core libraries available
211         echo "Copying core libraries..."
212 #       if test -d ${VLC_BUILD_DIR}/src/.libs; then
213 #               # Iterate through all the core libraries
214 #               for lib_src = ${VLC_BUILD_DIR}/src/.libs/*.dylib; do
215 #                       # Only install the library if it is not a symbolic link
216 #                       if ! test -L ${lib_src}; then
217 #                               echo "install_library ${lib_src} ${target_lib} `echo "${lib_src}" | sed 's:(.\d+)+.dylib:.dylib:'`"
218 #                       fi
219 #               done
220 #       fi
221
222         install_library "${VLC_BUILD_DIR}/src/.libs/libvlc.dylib" ${target_lib} "library"
223         install_library "${VLC_BUILD_DIR}/src/.libs/libvlc-control.dylib" ${target_lib} "library"
224         install_library "${VLC_BUILD_DIR}/extras/contrib/vlc-lib/vlc_libintl.dylib" ${target_lib} "library"
225     # Build the library folder
226     ##########################
227
228     ##########################
229     # Build the modules folder (Same as VLC.framework/modules in Makefile)
230         echo "Building modules folder..."
231         # Figure out what modules are available to install
232         for module in `top_builddir="${VLC_BUILD_DIR}" ${vlc_config} --target plugin` ; do
233                 # Check to see that the reported module actually exists
234                 if test -n ${module}; then
235                         module_src="`dirname ${module}`/.libs/`basename ${module}`.dylib"
236                         install_library ${module_src} ${target_modules} "module"
237                 fi
238     done
239         
240     # Build the modules folder
241     ##########################
242 fi