]> err.no Git - sope/blob - gnustep-make/openapp.in
added scriptaculous
[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 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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_FLATTENED" ]; then
36   GNUSTEP_FLATTENED=@GNUSTEP_FLATTENED@
37 fi
38
39 only_find=
40
41 # TODO: implement a --library-combo parameter
42 case "$1" in
43   --help)
44     echo usage: openapp [--find] application [arguments...]
45     echo
46     echo application is the complete or relative name of the application
47     echo program with or without the .app extension, like Ink.app.
48     echo
49     echo [arguments...] are the arguments to the application.     
50     echo 
51     echo If --find is used as first argument, openapp prints out
52     echo the full path of the application executable which would be 
53     echo executed, without actually executing it as it would normally do.
54     echo 
55     exit 0
56     ;;
57   --find)
58     only_find=yes;
59     if [ -z "$2" ]; then
60       echo Missing application name.  Please try openapp --help for more help.
61       exit 1
62     fi
63     app="$2"; shift; shift;;
64   *)
65     app="$1"; shift;;
66 esac
67
68 # Remove leading slashes at the end of the application name
69 app="`echo \"$app\" | sed 's%/*$%%'`"
70
71 # Now build the list of directory names we look for.  If the user has
72 # given us a full application directory name (for example, Gorm.app)
73 # then we only search for the given directory name; if instead the
74 # user has given us the application name without the suffix (for
75 # example, 'Gorm') we want to search for Gorm.app, then for
76 # Gorm.debug, then for Gorm.profile (in that order).
77 # If the appname is known, save it to avoid running a grep later to get it.
78 case "$app" in
79   *.app)     app_list="$app"; appname="";;
80   *.debug)   app_list="$app"; appname="";;
81   *.profile) app_list="$app"; appname="";;
82   *)         app_list="$app.app:$app.debug:$app.profile"; appname="$app";
83 esac
84
85 old_IFS="$IFS"
86 IFS=:
87 case "$app" in
88   /*) # An absolute path.
89       for appdir in $app_list; do
90         #echo "$appdir"
91         if [ -d "$appdir" ]; then
92            full_appname="$appdir"
93            break
94         fi
95       done;;
96     */*) # A relative path
97       for appdir in $app_list; do
98         #echo "$appdir"
99          if [ -d "$appdir" ]; then
100            full_appname="`(cd \"$appdir\"; pwd)`"
101            break
102          fi
103       done;;
104     *)  # A path that should be searched into the GNUstep paths
105       if [ -n "$GNUSTEP_PATHLIST" ]; then
106         SPATH="$GNUSTEP_PATHLIST"
107       else
108         SPATH="$PATH"
109       fi
110         SPATH=".:$SPATH"
111
112       for dir in $SPATH; do
113         for appdir in $app_list; do
114           # First, search in $dir/Applications/any_path_here/$appdir
115           #echo "$dir/Applications/"'*'"/$appdir"
116           for d in $dir/Applications/*/$appdir ; do
117             # If nothing is found, * expands to '*'.  Check that it's
118             # not the case, and that we have a real match.
119             if [ "$d" != "$dir/Applications/"'*'"/$appdir" ]; then
120               #echo "  $d"
121               if [ -d "$d" ]; then
122                 full_appname="`(cd \"$d\"; pwd)`"
123                 break 3
124               fi
125             fi
126           done
127           # Now, in $dir/Applications/$appdir
128           #echo "$dir/Applications/$appdir"
129           if [ -d "$dir/Applications/$appdir" ]; then
130             full_appname="`(cd \"$dir/Applications/$appdir\"; pwd)`"
131             break 2
132           fi
133           # Finally, in $dir/$appdir
134           #echo "$dir/$appdir"
135           if [ -d "$dir/$appdir" ]; then
136             full_appname="`(cd \"$dir/$appdir\"; pwd)`"
137             break 2
138           fi
139         done
140       done;;
141 esac
142 IFS="$old_IFS"
143 unset app_list
144 unset appdir
145
146 if [ -z "$full_appname" ]; then
147   echo "Can't find the required application: $app!"
148   exit 1
149 fi
150
151 #echo "found: $full_appname"
152
153 # get base app name
154 if [ -z "$appname" ]; then
155   appname="`echo \"$app\" | sed 's/\.[a-z]*$//'`"
156 fi
157 appname="`basename \"$appname\"`"
158
159 if [ -n "$GNUSTEP_FLATTENED" ]; then
160
161   if [ -z "$EXEEXT" ]; then
162     EXEEXT=@EXEEXT@
163   fi
164
165   if [ -n "$EXEEXT" ]; then
166     appname="$appname$EXEEXT"
167   fi
168
169 fi
170
171 case "$LIBRARY_COMBO" in
172   apple-*) app_executable="$full_appname/Contents/MacOS/$appname";;
173   *)       app_executable="$full_appname/$appname";;
174 esac
175
176 if [ ! -f "$app_executable" ]; then
177   echo "Could not find $app_executable executable/script"
178   exit 1
179 fi
180
181 if [ -n "$only_find" ]; then
182   echo "$app_executable"
183   exit 0
184 fi
185
186 exec "$app_executable" "$@"