]> err.no Git - sope/blob - gnustep-make/openapp.in
replaced usage of getCString on MacOS >= 10.4
[sope] / gnustep-make / openapp.in
1 #!/bin/sh
2 #
3 # @configure_input@
4 #
5 # Copyright (C) 1997 Free Software Foundation, Inc.
6 #
7 # Author: Ovidiu Predescu <ovidiu@net-community.com>
8 # Date: October 1997
9 # Author: Nicola Pero <n.pero@mi.flashnet.it>
10 # Date: 2002
11 #
12 # This file is part of the GNUstep Makefile Package.
13 #
14 # This library is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
18
19 # You should have received a copy of the GNU General Public
20 # License along with this library; see the file COPYING.LIB.
21 # If not, write to the Free Software Foundation,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
24 # Try to execute the application passed as argument. The application is
25 # searched through the GNUstep directories if a complete or relative path name
26 # is not specified. The arguments passed after the application name are passed
27 # unmodified to the application.
28
29 if [ -z "$1" ]; then
30   echo usage: openapp [--find] application [arguments...]
31   echo openapp --help for more help
32   exit 1
33 fi
34
35 if [ -z "$GNUSTEP_CONFIG_FILE" ]; then
36   GNUSTEP_CONFIG_FILE=@GNUSTEP_CONFIG_FILE@
37 fi
38 . $GNUSTEP_CONFIG_FILE
39
40 . $GNUSTEP_SYSTEM_ROOT/Library/Makefiles/GNUstep.sh
41
42 if [ -z "$GNUSTEP_FLATTENED" ]; then
43   GNUSTEP_FLATTENED=@GNUSTEP_FLATTENED@
44 fi
45
46 only_find=
47
48 # TODO: implement a --library-combo parameter
49 case "$1" in
50   --help)
51     echo usage: openapp [--find] application [arguments...]
52     echo
53     echo application is the complete or relative name of the application
54     echo program with or without the .app extension, like Ink.app.
55     echo
56     echo [arguments...] are the arguments to the application.     
57     echo 
58     echo If --find is used as first argument, openapp prints out
59     echo the full path of the application executable which would be 
60     echo executed, without actually executing it as it would normally do.
61     echo 
62     exit 0
63     ;;
64   --find)
65     only_find=yes;
66     if [ -z "$2" ]; then
67       echo Missing application name.  Please try openapp --help for more help.
68       exit 1
69     fi
70     app="$2"; shift; shift;;
71   *)
72     app="$1"; shift;;
73 esac
74
75 # Remove leading slashes at the end of the application name
76 app="`echo \"$app\" | sed 's%/*$%%'`"
77
78 # Now form the set of directory names we look for.  If the user has
79 # given us a full application directory name (for example, Gorm.app)
80 # then we only search for the given directory name; if instead the
81 # user has given us the application name without the suffix (for
82 # example, 'Gorm') we want to search for Gorm.app, then for
83 # Gorm.debug, then for Gorm.profile (in that order).
84 # If the appname is known, save it to avoid running a grep later to get it.
85 case "$app" in
86   *.app)     a1="$app"; a2=""; a3=""; appname="";;
87   *.debug)   a1="$app"; a2=""; a3=""; appname="";;
88   *.profile) a1="$app"; a2=""; a3=""; appname="";;
89   *)         a1="$app.app"; a2="$app.debug" a3="$app.profile"; appname="$app";
90 esac
91
92 case "$app" in
93     /*) # An absolute path.
94       for appdir in "$a1" "$a2" "$a3"; do
95         if [ \( "" != "$appdir" \) -a \( -d "$appdir" \) ]; then
96            full_appname="$appdir"
97            break
98         fi
99       done
100       ;;
101     */*) # A relative path
102       for appdir in "$a1" "$a2" "$a3"; do
103         if [ \( "" != "$appdir" \) -a \( -d "$appdir" \) ]; then
104           full_appname="`(cd \"$appdir\"; pwd)`"
105           break
106         fi
107       done
108       ;;
109     *)
110       # We should first search the standard GNUstep locations.
111       for dir in "$GNUSTEP_USER_ROOT" "$GNUSTEP_LOCAL_ROOT" "$GNUSTEP_NETWORK_ROOT" "$GNUSTEP_SYSTEM_ROOT"; do
112         for appdir in "$a1" "$a2" "$a3"; do
113           # Standard locations ... in $dir/Applications/$appdir
114           if [ \( "" != "$appdir" \) -a \( -d "$dir/Applications/$appdir" \) ]; then
115             full_appname="`(cd \"$dir/Applications/$appdir\"; pwd)`"
116             break 2
117           fi
118         done
119       done
120       if [ -z "$full_appname" ]; then
121         # And now search the standard PATH (may include '.')
122         old_IFS="$IFS"
123         IFS=:
124         for dir in $PATH; do
125           for appdir in "$a1" "$a2" "$a3"; do
126             if [ \( "" != "$appdir" \) -a \( -d "$dir/$appdir" \) ]; then
127               full_appname="`(cd \"$dir/$appdir\"; pwd)`"
128               break 2
129             fi
130           done
131         done
132         IFS="$old_IFS"
133       fi
134     ;;
135 esac
136 unset app_list
137 unset appdir
138
139 if [ -z "$full_appname" ]; then
140   echo "Can't find the required application: $app!"
141   exit 1
142 fi
143
144 #echo "found: $full_appname"
145
146 # get base app name
147 if [ -z "$appname" ]; then
148   appname="`echo \"$app\" | sed 's/\.[a-z]*$//'`"
149 fi
150 appname="`basename \"$appname\"`"
151
152 if [ -n "$GNUSTEP_FLATTENED" ]; then
153
154   if [ -z "$EXEEXT" ]; then
155     EXEEXT=@EXEEXT@
156   fi
157
158   if [ -n "$EXEEXT" ]; then
159     appname="$appname$EXEEXT"
160   fi
161
162 fi
163
164 case "$LIBRARY_COMBO" in
165   apple-*) app_executable="$full_appname/Contents/MacOS/$appname";;
166   *)       app_executable="$full_appname/$appname";;
167 esac
168
169 if [ ! -f "$app_executable" ]; then
170   echo "Could not find $app_executable executable/script"
171   exit 1
172 fi
173
174 if [ -n "$only_find" ]; then
175   echo "$app_executable"
176   exit 0
177 fi
178
179 exec "$app_executable" "$@"