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