source: snovis/trunk/obuild/sh/build_Darwin_app @ 136

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