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