]> git.sesse.net Git - vlc/blob - projects/macosx/framework/Pre-Compile.sh
Blind attempt to fix the OS X builds
[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 # Hack to use that script with the current VLC-release.app
12 elif test "${ACTION}" = "release-makefile"; then
13     TARGET_BUILD_DIR="${build_dir}"
14     FULL_PRODUCT_NAME="${PRODUCT}"
15     CONTENTS_FOLDER_PATH="${FULL_PRODUCT_NAME}/Contents/MacOS"
16     VLC_BUILD_DIR="${build_dir}"
17     VLC_SRC_DIR="${src_dir}"
18     ACTION="build"
19     RELEASE_MAKEFILE="yes"
20 fi
21
22 if test "${ACTION}" = "build"; then    
23     lib="lib"
24     modules="modules"
25     share="share"
26     include="include"
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     target_include="${target}/${include}"    # 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    
41         if [ ${3} = "library" ]; then
42             local install_name="@loader_path/lib"
43         elif [ ${3} = "module" ]; then
44             local install_name="@loader_path/modules"
45         fi
46         if [ "${5}" != "" ]; then
47             local lib_dest="${2}/${5}"
48         else
49             local lib_dest="${2}/`basename ${1}`"
50         fi
51
52         if [ "${4}" != "" ]; then
53             local lib_install_prefix="${4}"
54         else
55             local 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                 local name=`basename ${linked_lib}`
76                 case "${linked_lib}" in
77                     */vlc_build_dir/*  | *vlc* | */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                             install_library ${linked_lib} ${target_lib} "library"
82                         fi
83                         ;;
84                 esac
85             done
86          fi
87     }
88     # @function install_library
89     ##########################
90
91     prefix=".libs/"
92     suffix="dylib"
93
94     ##########################
95     # Hack for VLC-release.app
96     if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
97         install_library "${VLC_BUILD_DIR}/bin/${prefix}vlc" "${target}" "bin" "@loader_path/lib"
98         mv ${target}/vlc ${target}/VLC
99         chmod +x ${target}/VLC
100     elif [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
101         install_library "${VLC_BUILD_DIR}/src/${prefix}npvlc.${suffix}" "${target}" "bin" "@loader_path/lib"
102         mv ${target}/npvlc.${suffix} "${target}/VLC Plugin.plugin"
103         chmod +x "${target}/VLC Plugin.plugin"
104     fi
105
106     ##########################
107     # Build the modules folder (Same as VLCKit.framework/modules in Makefile)
108     echo "Building modules folder..."
109     # Figure out what modules are available to install
110     for module in `find ${VLC_BUILD_DIR}/modules -name *.${suffix}` ; do
111         # Check to see that the reported module actually exists
112         if test -n ${module}; then
113             install_library ${module} ${target_modules} "module"
114         fi
115     done
116     # Build the modules folder
117     ##########################
118
119     ##########################
120     # Create a symbolic link in the root of the framework
121     mkdir -p ${target_lib}
122     mkdir -p ${target_modules}
123
124     if [ "$RELEASE_MAKEFILE" != "yes" ] ; then
125         pushd `pwd` > /dev/null
126         cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
127
128         ln -sf Versions/Current/${lib} .
129         ln -sf Versions/Current/${modules} .
130         ln -sf Versions/Current/${include} .
131         ln -sf Versions/Current/${share} .
132
133         popd > /dev/null
134     fi
135
136     ##########################
137     # Build the library folder
138     echo "Building library folder... ${linked_libs}"
139     for linked_lib in ${linked_libs} ; do
140         case "${linked_lib}" in
141             */extras/contrib/lib/*.dylib|*/vlc_install_dir/lib/*.dylib)
142                 if test -e ${linked_lib}; then
143                     install_library ${linked_lib} ${target_lib} "library"
144                 fi
145                 ;;
146         esac
147     done
148
149     install_library "${VLC_BUILD_DIR}/src/${prefix}libvlc.dylib" ${target_lib} "library"
150
151     ##########################
152     # Build the share folder
153     echo "Building share folder..."
154     pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks"
155     mkdir -p ${target_share}
156     $pbxcp ${VLC_SRC_DIR}/share/lua ${target_share}
157
158     ##########################
159     # Exporting headers
160     echo "Exporting headers..."
161     mkdir -p ${target_include}/vlc
162     $pbxcp ${VLC_SRC_DIR}/include/vlc/*.h ${target_include}/vlc
163
164 fi