macosx: fix release bundle size by reverting [71c633a876550b6bb3178ee5e7ae5d737359d3f3]
[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 # 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             install -m 644 ${1} ${lib_dest}
70
71             # Update the dynamic library so it will know where to look for the other libraries
72             echo "Installing ${3} `basename ${lib_dest}`"
73
74             if [ "${3}" != "bin" ]; then
75                 # Change the reference of libvlc.1 stored in the usr directory to libvlc.dylib in the framework's library directory
76                 install_name_tool -id "${install_name}/`basename ${lib_dest}`" ${lib_dest} > /dev/null
77             fi
78     
79             # Iterate through each installed library and modify the references to other dynamic libraries to match the framework's library directory
80             for linked_lib in `otool -L ${lib_dest}  | grep '(' | sed 's/\((.*)\)//'`; do
81                 local name=`basename ${linked_lib}`
82                 case "${linked_lib}" in
83                     */vlc_build_dir/* | */vlc_install_dir/* | *vlc* | */extras/contrib/lib/*)
84                         if test -e ${linked_lib}; then
85                             install_name_tool -change "$linked_lib" "${lib_install_prefix}/${name}" "${lib_dest}"
86                             linked_libs="${linked_libs} ${ref_lib}"
87                             install_library ${linked_lib} ${target_lib} "library"
88                         fi
89                         ;;
90                 esac
91             done
92          fi
93     }
94     # @function install_library
95     ##########################
96
97     prefix=".libs/"
98     suffix="dylib"
99
100     ##########################
101     # Hack for VLC-release.app
102     if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
103         install_library "${VLC_BUILD_DIR}/bin/${prefix}vlc" "${target}" "bin" "@loader_path/lib"
104         mv ${target}/vlc ${target}/VLC
105         chmod +x ${target}/VLC
106     elif [ "$FULL_PRODUCT_NAME" = "VLC-Plugin.plugin" ] ; then
107         # install Safari webplugin
108         install_library "${VLC_BUILD_DIR}/projects/mozilla/${prefix}npvlc.${suffix}" "${target}" "library" "@loader_path/lib"
109         mv ${target}/npvlc.${suffix} "${target}/VLC Plugin"
110         chmod +x "${target}/VLC Plugin"
111     fi
112
113     ##########################
114     # Build the modules folder (Same as VLCKit.framework/modules in Makefile)
115     echo "Building modules folder..."
116     # Figure out what modules are available to install
117     for module in `find ${VLC_BUILD_DIR}/modules -name *.${suffix}` ; do
118         # Check to see that the reported module actually exists
119         if test -n ${module}; then
120             install_library ${module} ${target_modules} "module"
121         fi
122     done
123     # Build the modules folder
124     ##########################
125
126     ##########################
127     # Create a symbolic link in the root of the framework
128     mkdir -p ${target_lib}
129     mkdir -p ${target_modules}
130
131     if [ "$RELEASE_MAKEFILE" != "yes" ] ; then
132         pushd `pwd` > /dev/null
133         cd ${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}
134
135         ln -sf Versions/Current/${lib} .
136         ln -sf Versions/Current/${modules} .
137         ln -sf Versions/Current/${include} .
138         ln -sf Versions/Current/${share} .
139
140         popd > /dev/null
141     fi
142
143     ##########################
144     # Build the library folder
145     echo "Building library folder... ${linked_libs}"
146     for linked_lib in ${linked_libs} ; do
147         case "${linked_lib}" in
148             */extras/contrib/lib/*.dylib|*/vlc_install_dir/lib/*.dylib)
149                 if test -e ${linked_lib}; then
150                     install_library ${linked_lib} ${target_lib} "library"
151                 fi
152                 ;;
153         esac
154     done
155
156     install_library "${VLC_BUILD_DIR}/src/${prefix}libvlc.dylib" "${target_lib}" "library"
157
158     ##########################
159     # Build the share folder
160     if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
161         echo "Building share folder..."
162         pbxcp="/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -resolve-src-symlinks"
163         mkdir -p ${target_share}
164         $pbxcp ${VLC_SRC_DIR}/share/lua ${target_share}
165     else
166         echo "Share folder not needed for this product"
167     fi 
168     
169
170     ##########################
171     # Exporting headers
172     if [ "$FULL_PRODUCT_NAME" = "VLC-release.app" ] ; then
173         echo "Exporting headers..."
174         mkdir -p ${target_include}/vlc
175         $pbxcp ${VLC_SRC_DIR}/include/vlc/*.h ${target_include}/vlc
176     else
177         echo "Headers not needed for this product"
178     fi
179
180 fi