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

Last change on this file since 268 was 268, checked in by barrand, 16 years ago
  • Property svn:executable set to *
File size: 6.4 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 (libs) in Contents/bin (/lib) of the .app :
68while 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
84done
85cd "${obuild_pwd}"
86
87s_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
91otool -X -L  "${obuild_dir_app}/Contents/MacOS/${obuild_app}" > obuild_tmp
92/usr/bin/awk -s "${s_awk}" obuild_tmp > obuild_tmp1
93grep -v '/usr/lib' obuild_tmp1 | grep -v '/System/Library' > obuild_tmp2
94sed -e 's# #@@#g' obuild_tmp2 > obuild_tmp3
95obuild_app_libs=`cat obuild_tmp3`
96/bin/rm -f obuild_tmp obuild_tmp1 obuild_tmp2 obuild_tmp3
97for libi in ${obuild_app_libs}
98do 
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
105done
106unset libi
107
108# Get dlls linked libraries :
109cd "${obuild_dir_dll}"
110obuild_app_dlls=`find . -name "*" -type f -print`
111for dlla in ${obuild_app_dlls}
112do 
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
131done
132unset dlla
133cd "${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
138otool -X -L "${obuild_dir_app}/Contents/MacOS/${obuild_app}" > obuild_tmp
139/usr/bin/awk -s "${s_awk}" obuild_tmp > obuild_tmp1
140grep -v '/usr/lib' obuild_tmp1 | grep -v '/System/Library' > obuild_tmp2
141sed -e 's# #@@#g' obuild_tmp2 > obuild_tmp3
142libs=`cat obuild_tmp3`
143/bin/rm -f obuild_tmp obuild_tmp1 obuild_tmp2 obuild_tmp3
144for libi in ${libs}
145do 
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
153done
154unset libi
155unset libs
156
157# Change the install names of the libraries :
158cd "${obuild_dir_lib}"
159obuild_app_libs=`find . -name "*" -type f -print`
160for liba in ${obuild_app_libs}
161do 
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
191done
192unset liba
193cd "${obuild_pwd}"
194
195# Change the install names of the dlls :
196cd "${obuild_dir_dll}"
197obuild_app_dlls=`find . -name "*" -type f -print`
198for dlla in ${obuild_app_dlls}
199do 
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
224done
225unset dlla
226cd "${obuild_pwd}"
227
228unset obuild_app_dlls
229unset obuild_dir_dll
230
231unset obuild_app_libs
232unset obuild_dir_lib
233
234unset obuild_path_app
235unset obuild_dir_app
236
237unset obuild_pwd
Note: See TracBrowser for help on using the repository browser.