]> git.sesse.net Git - vlc/blob - extras/MacOSX/Framework/Pre-Compile.sh
MacOSX/Framework/VLCMediaList.m: Implement -isReadOnly.
[vlc] / extras / MacOSX / Framework / Pre-Compile.sh
1 if test "${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     ACTION="build"
9     rm -fr ${FULL_PRODUCT_NAME}
10     # Debug --
11 fi
12
13 if test "${ACTION}" = "build"; then    
14     vlc_config="${VLC_SRC_DIR}/vlc-config"
15     lib="lib"
16     modules="modules"
17     target="${TARGET_BUILD_DIR}/${CONTENTS_FOLDER_PATH}"
18     target_lib="${target}/${lib}"            # Should we consider using a different well-known folder like shared resources?
19     target_modules="${target}/${modules}"    # Should we consider using a different well-known folder like shared resources?
20     linked_libs=" "
21     
22     ##########################
23     # @function install_library(src_lib, dest_dir)
24     # @description Installs the specified library into the destination folder, automatically changes the references to dependencies
25     # @param src_lib     source library to copy to the destination directory
26     # @param dest_dir    destination directory where the src_lib should be copied to
27     install_library() {    
28         if [ ${3} = "library" ]; then
29             install_name="@loader_path/lib"
30         else
31             install_name="@loader_path/modules"
32         fi
33         
34         if [ "${4}" != "" ]; then
35             lib_dest="${2}/${4}"
36         else
37             lib_dest="${2}/`basename ${1}`"
38         fi
39         
40         if test -e ${1} && ((! test -e ${lib_dest}) || test ${1} -nt ${lib_dest} ); then
41             mkdir -p ${2}
42             
43             # Lets copy the library from the source folder to our new destination folder
44             cp ${1} ${lib_dest}
45
46             # Update the dynamic library so it will know where to look for the other libraries
47             echo "Installing ${3} `basename ${lib_dest}`"
48
49             # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
50             install_name_tool -change /usr/local/lib/libvlc.1.dylib @loader_path/../lib/libvlc.dylib ${lib_dest}
51             install_name_tool -change @executable_path/lib/vlc_libintl.dylib @loader_path/../lib/vlc_libintl.dylib ${lib_dest}
52             install_name_tool -id "${install_name}/`basename ${lib_dest}`" ${lib_dest}
53
54             # Iterate through each installed library and modify the references to other dynamic libraries to match the framework's library directory
55             for linked_lib in `otool -L ${lib_dest}  | grep '(' | sed 's/\((.*)\)//'`; do
56                 ref_lib=`echo "${linked_lib}" | sed 's:executable_path/:loader_path/../:'`
57                 
58                 if test "${ref_lib}" != "${linked_lib}"; then
59                     install_name_tool -change ${linked_lib} ${ref_lib} ${lib_dest}
60                 fi
61                 if test `echo "${ref_lib}" | grep "^@loader_path"`; then
62                     linked_libs="${linked_libs} ${ref_lib}"
63                 fi;
64             done
65         fi
66     }
67     # @function install_library
68     ##########################
69
70     ##########################
71     # Build the modules folder (Same as VLC.framework/modules in Makefile)
72     echo "Building modules folder..."
73     # Figure out what modules are available to install
74     for module in `top_builddir="${VLC_BUILD_DIR}" ${vlc_config} --target plugin` ; do
75         # Check to see that the reported module actually exists
76         if test -n ${module}; then
77             module_src="`dirname ${module}`/.libs/`basename ${module}`.dylib"
78             install_library ${module_src} ${target_modules} "module"
79         fi
80     done
81     # Build the modules folder
82     ##########################
83
84     ##########################
85     # Create a symbolic link in the root of the framework
86     mkdir -p ${target_lib}
87     mkdir -p ${target_modules}
88     
89     pushd `pwd` > /dev/null 
90     cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
91     
92     ln -sf Versions/Current/${lib} .
93     ln -sf Versions/Current/${modules} .
94     
95     popd > /dev/null 
96     # Create a symbolic link in the root of the framework
97     ##########################
98     
99     ##########################
100     # Build the library folder (Same as VLC.framework/lib in Makefile)
101     echo "Building library folder..."
102     for linked_lib in ${linked_libs} ; do
103         case "${linked_lib}" in
104             @loader_path/../lib/*)
105                 ref_lib=`echo ${linked_lib} | sed 's:@loader_path/../lib/::'`
106                 if test -e ${VLC_BUILD_DIR}/extras/contrib/vlc-lib/${ref_lib}; then
107                     src_lib=${VLC_BUILD_DIR}/extras/contrib/vlc-lib/${ref_lib}
108                 elif test -e ${VLC_BUILD_DIR}/src/.libs/${ref_lib}; then
109                     src_lib=${VLC_BUILD_DIR}/src/.libs/${ref_lib}
110                 fi
111                 install_library ${src_lib} ${target_lib} "library"
112                 ;;
113         esac
114     done
115     # Build the library folder
116     ##########################
117     install_library "${VLC_BUILD_DIR}/src/.libs/libvlc-control.dylib" ${target_lib} "library"
118 fi