1 | #!/bin/sh -f |
---|
2 | |
---|
3 | if [ `uname` != Darwin ] ; then |
---|
4 | exit |
---|
5 | fi |
---|
6 | |
---|
7 | #set -x |
---|
8 | |
---|
9 | if test $# -lt 1 ; then |
---|
10 | echo "Give the name of an application." |
---|
11 | exit |
---|
12 | fi |
---|
13 | |
---|
14 | obuild_app=$1 |
---|
15 | shift |
---|
16 | |
---|
17 | if [ "${OBUILD_PLATFORM}" = "" ] ; then |
---|
18 | obuild_platform=`uname` |
---|
19 | else |
---|
20 | obuild_platform=${OBUILD_PLATFORM} |
---|
21 | fi |
---|
22 | |
---|
23 | if [ "${obuild_platform}" = "" ] ; then |
---|
24 | echo "obuild_platform variable not defined." |
---|
25 | exit |
---|
26 | fi |
---|
27 | |
---|
28 | if [ "${OBUILD_DIR_BIN}" = "" ] ; then |
---|
29 | obuild_dir_bin=bin_obuild |
---|
30 | else |
---|
31 | obuild_dir_bin=${OBUILD_DIR_BIN} |
---|
32 | fi |
---|
33 | |
---|
34 | if [ "${obuild_dir_bin}" = "" ] ; then |
---|
35 | echo "obuild_dir_bin variable not defined." |
---|
36 | exit |
---|
37 | fi |
---|
38 | |
---|
39 | obuild_pwd=`pwd` |
---|
40 | obuild_snovis_path=`dirname "${obuild_pwd}"` |
---|
41 | |
---|
42 | obuild_path_app="${obuild_snovis_path}/${obuild_dir_bin}/${obuild_app}" |
---|
43 | |
---|
44 | if [ ! -e "${obuild_path_app}" ] ; then |
---|
45 | echo "${obuild_path_app} does not exists." |
---|
46 | exit |
---|
47 | fi |
---|
48 | |
---|
49 | if [ ! -x "${obuild_path_app}" ] ; then |
---|
50 | echo "${obuild_path_app} is not an appliction." |
---|
51 | exit |
---|
52 | fi |
---|
53 | |
---|
54 | obuild_dir_app="${obuild_snovis_path}/${obuild_dir_bin}/${obuild_app}.app" |
---|
55 | |
---|
56 | # Create the .app structure : |
---|
57 | /bin/rm -R -f "${obuild_dir_app}" |
---|
58 | /bin/mkdir -p "${obuild_dir_app}/Contents/MacOS" |
---|
59 | obuild_dir_lib="${obuild_dir_app}/Contents/lib" |
---|
60 | /bin/mkdir -p "${obuild_dir_lib}" |
---|
61 | obuild_dir_dll="${obuild_dir_app}/Contents/bin" |
---|
62 | /bin/mkdir -p "${obuild_dir_dll}" |
---|
63 | |
---|
64 | # Copy the application : |
---|
65 | /bin/cp "${obuild_path_app}" "${obuild_dir_app}/Contents/MacOS/${obuild_app}" |
---|
66 | |
---|
67 | # Copy dlls (libs) in Contents/bin (/lib) of the .app : |
---|
68 | while test $# -ge 1 ; do |
---|
69 | if [ -e "$1" ] ; then |
---|
70 | name=`basename "$1"` |
---|
71 | if [ "`basename ${name} .dylib`" = "${name}" ] ; then |
---|
72 | # .bundle |
---|
73 | #echo "debug : bundle : $1" |
---|
74 | eval /bin/cp "\"$1\"" "\"${obuild_dir_dll}\""/. |
---|
75 | else |
---|
76 | # .dylib |
---|
77 | #echo "debug : dylib : $1" |
---|
78 | eval /bin/cp "\"$1\"" "\"${obuild_dir_lib}\""/. |
---|
79 | fi |
---|
80 | # else |
---|
81 | # echo "$1 not found." |
---|
82 | fi |
---|
83 | shift |
---|
84 | done |
---|
85 | cd "${obuild_pwd}" |
---|
86 | |
---|
87 | s_awk='{i=index($0," (compatibility");if(i==0){print $0;} else { print substr($0,0,i-1);}}' |
---|
88 | |
---|
89 | # Get application linked libraries : |
---|
90 | /bin/rm -f obuild_tmp obuild_tmp1 obuild_tmp2 |
---|
91 | otool -X -L "${obuild_dir_app}/Contents/MacOS/${obuild_app}" > obuild_tmp |
---|
92 | /usr/bin/awk -s "${s_awk}" obuild_tmp > obuild_tmp1 |
---|
93 | grep -v '/usr/lib' obuild_tmp1 | grep -v '/System/Library' > obuild_tmp2 |
---|
94 | sed -e 's# #@@#g' obuild_tmp2 > obuild_tmp3 |
---|
95 | obuild_app_libs=`cat obuild_tmp3` |
---|
96 | /bin/rm -f obuild_tmp obuild_tmp1 obuild_tmp2 obuild_tmp3 |
---|
97 | for libi in ${obuild_app_libs} |
---|
98 | do |
---|
99 | libi=`echo ${libi} | sed -e 's#@@# #g'` |
---|
100 | if [ -e "${libi}" ] ; then |
---|
101 | eval /bin/cp "\"${libi}\"" "\"${obuild_dir_lib}/.\"" |
---|
102 | else |
---|
103 | echo "${libi} not found." |
---|
104 | fi |
---|
105 | done |
---|
106 | unset libi |
---|
107 | |
---|
108 | # Get dlls linked libraries : |
---|
109 | cd "${obuild_dir_dll}" |
---|
110 | obuild_app_dlls=`find . -name "*" -type f -print` |
---|
111 | for dlla in ${obuild_app_dlls} |
---|
112 | do |
---|
113 | /bin/rm -f obuild_tmp obuild_tmp1 obuild_tmp2 |
---|
114 | otool -X -L "${dlla}" > obuild_tmp |
---|
115 | /usr/bin/awk -s "${s_awk}" obuild_tmp > obuild_tmp1 |
---|
116 | grep -v '/usr/lib' obuild_tmp1 | grep -v '/System/Library' > obuild_tmp2 |
---|
117 | sed -e 's# #@@#g' obuild_tmp2 > obuild_tmp3 |
---|
118 | libs=`cat obuild_tmp3` |
---|
119 | /bin/rm -f obuild_tmp obuild_tmp1 obuild_tmp2 obuild_tmp3 |
---|
120 | for libi in ${libs} |
---|
121 | do |
---|
122 | libi=`echo ${libi} | sed -e 's#@@# #g'` |
---|
123 | if [ -e "${libi}" ] ; then |
---|
124 | eval /bin/cp "\"${libi}\"" "\"${obuild_dir_lib}/.\"" |
---|
125 | else |
---|
126 | echo "${libi} not found." |
---|
127 | fi |
---|
128 | done |
---|
129 | unset libi |
---|
130 | unset libs |
---|
131 | done |
---|
132 | unset dlla |
---|
133 | cd "${obuild_pwd}" |
---|
134 | |
---|
135 | # Change the install names of the application : |
---|
136 | # Get linked libraries : |
---|
137 | /bin/rm -f obuild_tmp obuild_tmp1 obuild_tmp2 |
---|
138 | otool -X -L "${obuild_dir_app}/Contents/MacOS/${obuild_app}" > obuild_tmp |
---|
139 | /usr/bin/awk -s "${s_awk}" obuild_tmp > obuild_tmp1 |
---|
140 | grep -v '/usr/lib' obuild_tmp1 | grep -v '/System/Library' > obuild_tmp2 |
---|
141 | sed -e 's# #@@#g' obuild_tmp2 > obuild_tmp3 |
---|
142 | libs=`cat obuild_tmp3` |
---|
143 | /bin/rm -f obuild_tmp obuild_tmp1 obuild_tmp2 obuild_tmp3 |
---|
144 | for libi in ${libs} |
---|
145 | do |
---|
146 | libi=`echo ${libi} | sed -e 's#@@# #g'` |
---|
147 | new_install_name=`basename "${libi}"` |
---|
148 | if [ -f "${obuild_dir_lib}/${new_install_name}" ] ; then |
---|
149 | new_install_name=@executable_path/../lib/${new_install_name} |
---|
150 | install_name_tool -change "${libi}" ${new_install_name} "${obuild_dir_app}/Contents/MacOS/${obuild_app}" |
---|
151 | fi |
---|
152 | unset new_install_name |
---|
153 | done |
---|
154 | unset libi |
---|
155 | unset libs |
---|
156 | |
---|
157 | # Change the install names of the libraries : |
---|
158 | cd "${obuild_dir_lib}" |
---|
159 | obuild_app_libs=`find . -name "*" -type f -print` |
---|
160 | for liba in ${obuild_app_libs} |
---|
161 | do |
---|
162 | #echo "----> ${liba}" |
---|
163 | |
---|
164 | new_install_name=`basename "${liba}"` |
---|
165 | new_install_name=@executable_path/../lib/${new_install_name} |
---|
166 | install_name_tool -id ${new_install_name} "${liba}" |
---|
167 | unset new_install_name |
---|
168 | |
---|
169 | # Get linked libraries : |
---|
170 | /bin/rm -f obuild_tmp obuild_tmp1 obuild_tmp2 |
---|
171 | otool -X -L "${liba}" > obuild_tmp |
---|
172 | /usr/bin/awk -s "${s_awk}" obuild_tmp > obuild_tmp1 |
---|
173 | grep -v '/usr/lib' obuild_tmp1 | grep -v '/System/Library' > obuild_tmp2 |
---|
174 | sed -e 's# #@@#g' obuild_tmp2 > obuild_tmp3 |
---|
175 | libs=`cat obuild_tmp3` |
---|
176 | /bin/rm -f obuild_tmp obuild_tmp1 obuild_tmp2 obuild_tmp3 |
---|
177 | for libi in ${libs} |
---|
178 | do |
---|
179 | libi=`echo ${libi} | sed -e 's#@@# #g'` |
---|
180 | #echo "${libi}" |
---|
181 | new_install_name=`basename "${libi}"` |
---|
182 | if [ -f "${obuild_dir_lib}/${new_install_name}" ] ; then |
---|
183 | new_install_name=@executable_path/../lib/${new_install_name} |
---|
184 | #echo "${new_install_name}" |
---|
185 | install_name_tool -change "${libi}" ${new_install_name} "${liba}" |
---|
186 | fi |
---|
187 | unset new_install_name |
---|
188 | done |
---|
189 | unset libi |
---|
190 | unset libs |
---|
191 | done |
---|
192 | unset liba |
---|
193 | cd "${obuild_pwd}" |
---|
194 | |
---|
195 | # Change the install names of the dlls : |
---|
196 | cd "${obuild_dir_dll}" |
---|
197 | obuild_app_dlls=`find . -name "*" -type f -print` |
---|
198 | for dlla in ${obuild_app_dlls} |
---|
199 | do |
---|
200 | #echo "----> ${dlla}" |
---|
201 | |
---|
202 | # Get linked libraries : |
---|
203 | /bin/rm -f obuild_tmp obuild_tmp1 obuild_tmp2 |
---|
204 | otool -X -L "${dlla}" > obuild_tmp |
---|
205 | /usr/bin/awk -s "${s_awk}" obuild_tmp > obuild_tmp1 |
---|
206 | grep -v '/usr/lib' obuild_tmp1 | grep -v '/System/Library' > obuild_tmp2 |
---|
207 | sed -e 's# #@@#g' obuild_tmp2 > obuild_tmp3 |
---|
208 | libs=`cat obuild_tmp3` |
---|
209 | /bin/rm -f obuild_tmp obuild_tmp1 obuild_tmp2 obuild_tmp3 |
---|
210 | for libi in ${libs} |
---|
211 | do |
---|
212 | libi=`echo ${libi} | sed -e 's#@@# #g'` |
---|
213 | #echo "${libi}" |
---|
214 | new_install_name=`basename "${libi}"` |
---|
215 | if [ -f "${obuild_dir_lib}/${new_install_name}" ] ; then |
---|
216 | new_install_name=@executable_path/../lib/${new_install_name} |
---|
217 | #echo "${new_install_name}" |
---|
218 | install_name_tool -change "${libi}" ${new_install_name} "${dlla}" |
---|
219 | fi |
---|
220 | unset new_install_name |
---|
221 | done |
---|
222 | unset libi |
---|
223 | unset libs |
---|
224 | done |
---|
225 | unset dlla |
---|
226 | cd "${obuild_pwd}" |
---|
227 | |
---|
228 | unset obuild_app_dlls |
---|
229 | unset obuild_dir_dll |
---|
230 | |
---|
231 | unset obuild_app_libs |
---|
232 | unset obuild_dir_lib |
---|
233 | |
---|
234 | unset obuild_path_app |
---|
235 | unset obuild_dir_app |
---|
236 | |
---|
237 | unset obuild_pwd |
---|