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