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