]> err.no Git - sope/blob - executable.template.in
68303f1ecd6dc392a4dc7b0a482122134bb9dc1b
[sope] / executable.template.in
1 #!/bin/sh
2 #
3 # @configure_input@
4 #
5 # Copyright (C) 1999-2002 Free Software Foundation, Inc.
6 #
7 # Author: Adam Fedor <fedor@gnu.org>
8 # Date: May 1999
9 #
10 # Author: Nicola Pero <n.pero@mi.flashnet.it>
11 # Date: 2001, 2002
12
13 # This file is part of the GNUstep Makefile Package.
14 #
15 # This library is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License
17 # as published by the Free Software Foundation; either version 2
18 # of the License, or (at your option) any later version.
19
20 # You should have received a copy of the GNU General Public
21 # License along with this library; see the file COPYING.LIB.
22 # If not, write to the Free Software Foundation,
23 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25 # This is a shell script which attempts to find the GNUstep executable
26 # of the same name based on the current host and library_combo.
27
28 #--------------------------------------------------------------------------
29 # Main body
30 #--------------------------------------------------------------------------
31 if [ -z "$EXEEXT" ]; then
32   EXEEXT=@EXEEXT@
33 fi
34 if [ -z "$LIBRARY_COMBO" ]; then
35   LIBRARY_COMBO=@ac_cv_library_combo@
36 fi
37
38 # Process arguments
39 app="$0"
40 show_available_platforms=0
41 show_relative_path=0
42 show_full_path=0
43 while true
44 do 
45   case "$1" in
46
47     --script-help)
48         echo usage: `basename "$0"` [--library-combo=...]
49         echo "       [--available-platforms][--full-executable-path]"
50         echo "       [--relative-executable-path] [arguments...]"
51         echo
52         echo "   --library-combo=... specifies a GNUstep backend to use."
53         echo "   It overrides the default LIBRARY_COMBO environment variable."
54         echo
55         echo "   --available-platforms displays a list of valid exec hosts"
56         echo "   --full-executable-path displays full path to executable"
57         echo "   --relative-executable-path displays subdirectory path"
58         echo "   arguments... are the arguments to the application."
59         exit 0
60         ;;
61     --library-combo=*)
62         tmp_root="$GNUSTEP_SYSTEM_ROOT"
63         . "$tmp_root/@MAKEFILES_SUFFIX@/GNUstep-reset.sh"
64         LIBRARY_COMBO=`echo "$1" | sed 's/--library-combo=//'`
65         . "$tmp_root/@MAKEFILES_SUFFIX@/GNUstep.sh"
66         shift
67         ;;
68     --available-platforms)
69         show_available_platforms=1
70         exit 0
71         ;;
72     --full-executable-path)
73         show_full_path=1
74         break
75         ;;
76     --relative-executable-path)
77         show_relative_path=1
78         break
79         ;;
80     *)
81         break;;
82     esac
83 done
84
85 if [ "$LIBRARY_COMBO" = nx ]; then
86   LIBRARY_COMBO=nx-nx-nx
87 elif [ "$LIBRARY_COMBO" = gnu ]; then
88   LIBRARY_COMBO=gnu-gnu-gnu
89 elif [ "$LIBRARY_COMBO" = fd ]; then
90   LIBRARY_COMBO=gnu-fd-gnu
91 elif [ "$LIBRARY_COMBO" = apple ]; then
92   LIBRARY_COMBO=apple-apple-apple
93 fi
94 export LIBRARY_COMBO
95
96 # Find path to ourself
97 dir="`dirname \"$app\"`"
98
99 case "$app" in
100   /*)   # An absolute path.
101         full_appname="$dir";;
102   */*)  # A relative path
103         full_appname="`(cd \"$dir\"; pwd)`";;
104   *)    # A path that needs to be searched
105         if [ -n "$GNUSTEP_PATHLIST" ]; then
106             SPATH="$GNUSTEP_PATHLIST"
107         else
108             SPATH="$PATH"
109         fi
110         SPATH=".:$SPATH"
111         IFS=:
112         for path_dir in $SPATH; do
113           if [ -d "$path_dir/$dir" ]; then
114             full_appname="`(cd \"$path_dir/$dir\"; pwd)`"
115             break;
116           fi
117           if [ -d "$path_dir/Applications/$dir" ]; then
118             full_appname="`(cd \"$path_dir/Applications/$dir\"; pwd)`"
119             break;
120           fi
121         done;;
122 esac
123
124 if [ -z "$full_appname" ]; then
125   echo "Can't find absolute path for $app! Please specify full path when"
126   echo "invoking executable"
127   exit 1
128 fi
129
130 #
131 # get base app name
132 #
133 appname=
134 if [ -f "$full_appname/Resources/Info-gnustep.plist" ]; then
135 # -n disable auto-print (for portability reasons)
136 #   /^ *NSExecutable *=/ matches every line beginning with 
137 #        zero or more spaces, followed by 'NSExecutable', followed by zero or
138 #        more spaces, followed by '='
139 #   to this line we apply the following commands:
140 #   s/"//g; which deletes all " in the line.
141 #   s/^ *NSExecutable *= *\([^ ;]*\) *;.*/\1/p;
142 #     which replaces 'NSExecutable = Gorm; ' with 'Gorm', then, because
143 #     of the 'p' at the end, prints out the result 
144 #   q; which quits sed since we know there must be only a single line 
145 #      to replace.
146   appname=`sed -n -e '/^ *NSExecutable *=/ \
147            {s/"//g; s/^ *NSExecutable *= *\([^ ;]*\) *;.*/\1/p; q;}' \
148                 "$full_appname/Resources/Info-gnustep.plist"`
149 fi
150 if [ -z "$appname" ]; then
151   appname="`basename \"$app\"`"
152 fi
153
154 appname="$appname$EXEEXT"
155
156 if [ $show_available_platforms = 1 ]; then
157   cd "$full_appname"
158   #available_platforms
159   exit 0
160 fi
161
162 #
163 # Determine the host information
164 #
165 if [ -z "$GNUSTEP_HOST" ]; then
166   GNUSTEP_HOST=`(cd /tmp; $GNUSTEP_SYSTEM_ROOT/@MAKEFILES_SUFFIX@/config.guess)`
167   GNUSTEP_HOST=`(cd /tmp; $GNUSTEP_SYSTEM_ROOT/@MAKEFILES_SUFFIX@/config.sub $GNUSTEP_HOST)`
168   export GNUSTEP_HOST
169 fi
170 if [ -z "$GNUSTEP_HOST_CPU" ]; then
171   GNUSTEP_HOST_CPU=`$GNUSTEP_SYSTEM_ROOT/@MAKEFILES_SUFFIX@/cpu.sh $GNUSTEP_HOST`
172   GNUSTEP_HOST_CPU=`$GNUSTEP_SYSTEM_ROOT/@MAKEFILES_SUFFIX@/clean_cpu.sh $GNUSTEP_HOST_CPU`
173   export GNUSTEP_HOST_CPU
174 fi
175 if [ -z "$GNUSTEP_HOST_VENDOR" ]; then
176   GNUSTEP_HOST_VENDOR=`$GNUSTEP_SYSTEM_ROOT/@MAKEFILES_SUFFIX@/vendor.sh $GNUSTEP_HOST`
177   GNUSTEP_HOST_VENDOR=`$GNUSTEP_SYSTEM_ROOT/@MAKEFILES_SUFFIX@/clean_vendor.sh $GNUSTEP_HOST_VENDOR`
178   export GNUSTEP_HOST_VENDOR
179 fi
180 if [ -z "$GNUSTEP_HOST_OS" ]; then
181   GNUSTEP_HOST_OS=`$GNUSTEP_SYSTEM_ROOT/@MAKEFILES_SUFFIX@/os.sh $GNUSTEP_HOST`
182   GNUSTEP_HOST_OS=`$GNUSTEP_SYSTEM_ROOT/@MAKEFILES_SUFFIX@/clean_os.sh $GNUSTEP_HOST_OS`
183   export GNUSTEP_HOST_OS
184 fi
185
186 #
187 # Make sure the executable is there
188 #
189 if [ -x "$full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/$appname" ]; then
190   relative_path="$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/$appname"
191 elif [ -x "$full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$appname" ]; then
192   relative_path="$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$appname"
193 elif [ -x "$full_appname/$GNUSTEP_HOST_CPU/$appname" ]; then
194   relative_path="$GNUSTEP_HOST_CPU/$appname"
195 elif [ "$full_appname/$appname" != "$0" -a -x "$full_appname/$appname" ]; then
196   relative_path="$appname"
197 else
198   # Search for a binary for this machine but a different library combo
199   if [ -d "$full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS" ]; then
200     tmp_path="`pwd`"
201     cd "$full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS";
202     found=no
203     for lib_combo in * ; do
204       if [ "$lib_combo" != '*' ]; then
205         if [ -x "$lib_combo/$appname" ]; then
206           # Switch LIBRARY_COMBO on the fly
207           tmp_root="$GNUSTEP_SYSTEM_ROOT"
208           . "$tmp_root/@MAKEFILES_SUFFIX@/GNUstep-reset.sh"
209           LIBRARY_COMBO="$lib_combo"
210           . "$tmp_root/@MAKEFILES_SUFFIX@/GNUstep.sh"
211           # Use the found executable
212           relative_path="$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/$appname"
213           found=yes
214           break
215         fi
216       fi
217     done
218     cd "$tmp_path"
219     if [ "$found" != yes ]; then
220       echo "$full_appname application does not have a binary for this kind of machine/operating system ($GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS)."
221       exit 1
222     fi
223   fi
224 fi
225
226 if [ $show_relative_path = 1 ]; then
227   echo "$relative_path"
228   exit 0
229 fi
230 if [ $show_full_path = 1 ]; then
231   echo "$full_appname/$relative_path"
232   exit 0
233 fi
234
235 if [ "$LIBRARY_COMBO" = nx-nx-nx -a "$GNUSTEP_HOST_OS" = nextstep4 ]; then
236   if [ -f "$full_appname/library_paths.openapp" ]; then
237     additional_library_paths="`cat $full_appname/library_paths.openapp`"
238   fi
239 else
240   if [ -f "$full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/library_paths.openapp" ]; then
241     additional_library_paths="`cat \"$full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/library_paths.openapp\"`"
242   fi
243 fi
244
245 # Load up LD_LIBRARY_PATH
246 . "$GNUSTEP_SYSTEM_ROOT/@MAKEFILES_SUFFIX@/ld_lib_path.sh"
247
248 exec "$full_appname/$relative_path" "$@"
249