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