]> err.no Git - sope/blob - debugapp.in
9b77756025d5aa26711833c7a5e2bdd04a23ba86
[sope] / debugapp.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
10 # This file is part of the GNUstep Makefile Package.
11 #
12 # This library is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 2
15 # of the License, or (at your option) any later version.
16
17 # You should have received a copy of the GNU General Public
18 # License along with this library; see the file COPYING.LIB.
19 # If not, write to the Free Software Foundation,
20 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22 # Execute gdb for the application passed as argument. The application is
23 # searched through the GNUstep directories if a complete or relative path name
24 # is not specified. The arguments passed after the application name are passed
25 # unmodified to the application.
26
27 if [ -z "$1" ]; then
28   echo usage: `basename "$0"` [--library-combo=...] [--gdb=...] application [arguments...]
29   echo `basename "$0"` --help for help
30   exit 1
31 fi
32
33 if [ -z "$EXEEXT" ]; then
34   EXEEXT=@EXEEXT@
35 fi
36 if [ -z "$LIBRARY_COMBO" ]; then
37   LIBRARY_COMBO=@ac_cv_library_combo@
38 fi
39 if [ -z "$GDB" ]; then
40   GDB=gdb
41 fi
42
43 # Read command line arguments now
44 while [ x"$1" != x ]; do
45   case "$1" in
46     --help)
47       echo usage: `basename "$0"` [--library-combo=...] [--gbd=...] application [arguments...]
48       echo
49       echo [--library-combo=...] specifies a GNUstep backend to use.
50       echo It overrides the default LIBRARY_COMBO environment variable.
51       echo --library-combo=gnu for GNUstep 
52       echo --library-combo=nx for NeXT OPENSTEP
53       echo --library-combo=apple for Apple OSX
54       echo
55       echo [--gdb=...] specifies the debugger to use.
56       echo It overrides the default GDB environment variable.  If the --gdb=...
57       echo flag is not used, and the GDB variable is not set, then the program
58       echo called \"gdb\" is invoked.
59       echo
60       echo application is the complete or relative name of the application
61       echo program with the .app or .debug extension, like Edit.debug.
62       echo
63       echo [arguments...] are the arguments to the application.
64       exit 0
65       ;;
66
67     --library-combo=*)
68       LIBRARY_COMBO=`echo "$1" | sed 's/--library-combo=//'`
69       shift;;
70
71     --gdb=*)
72       GDB=`echo "$1" | sed 's/--gdb=//'`
73       shift;;
74
75     *)
76       app="$1";
77       shift;;
78   esac
79 done
80
81 if [ "$LIBRARY_COMBO" = nx ]; then
82   LIBRARY_COMBO=nx-nx-nx
83 elif [ "$LIBRARY_COMBO" = gnu ]; then
84   LIBRARY_COMBO=gnu-gnu-gnu
85 elif [ "$LIBRARY_COMBO" = fd ]; then
86   LIBRARY_COMBO=gnu-fd
87 elif [ "$LIBRARY_COMBO" = apple ]; then
88   LIBRARY_COMBO=apple-apple-apple
89 fi
90
91 # Remove leading slashes at the end of the application name
92 app="`echo \"$app\" | sed 's%/*$%%'`"
93
94 case "$app" in
95   /*)   # An absolute path.
96         full_appname="$app";;
97   */*)  # A relative path
98         full_appname="`(cd \"$app\"; pwd)`";;
99   *)    # A path that should be searched into the GNUstep paths
100         if [ -n "$GNUSTEP_PATHLIST" ]; then
101             SPATH="$GNUSTEP_PATHLIST"
102         else
103             SPATH="$PATH"
104         fi
105         SPATH=".:$SPATH"
106         IFS=:
107         for dir in $SPATH; do
108           if [ -d "$dir/Applications/$app" ]; then
109             full_appname="`(cd \"$dir/Applications/$app\"; pwd)`"
110             break;
111           fi
112           if [ -d "$dir/$app" ]; then
113             full_appname="`(cd \"$dir/$app\"; pwd)`"
114             break;
115           fi
116         done;;
117 esac
118
119 # Search for a core file in the current directory.
120 corearg=
121 corefiles="core*"
122 for corefile in $corefiles; do
123   if [ -f "$corefile" ]; then
124     echo -e "Core image ($corefile) has been found in working directory. Use it (y/n)? ";
125     # Need an argument here for Solaris
126     read REPLY;
127     if [ $REPLY = y ]; then
128       echo -e "Using it.";
129       corearg="--core=$corefile";
130       break;
131     else
132       echo -e "Ignoring it.";
133     fi
134   fi
135 done
136 unset corefile
137 unset corefiles
138
139 if [ -z "$full_appname" ]; then
140   echo "Can't find the required application: $app!"
141   exit 1
142 fi
143
144 if [ -z "$GNUSTEP_FLATTENED" ]; then
145         #
146         # Determine the host information
147         #
148         if [ -z "$GNUSTEP_HOST" ]; then
149             GNUSTEP_HOST=`$GNUSTEP_SYSTEM_ROOT/@MAKEFILES_SUFFIX@/config.guess`
150             GNUSTEP_HOST=`$GNUSTEP_SYSTEM_ROOT/@MAKEFILES_SUFFIX@/config.sub $GNUSTEP_HOST`
151             export GNUSTEP_HOST
152         fi
153         if [ -z "$GNUSTEP_HOST_CPU" ]; then
154             GNUSTEP_HOST_CPU=`$GNUSTEP_SYSTEM_ROOT/@MAKEFILES_SUFFIX@/cpu.sh $GNUSTEP_HOST`
155             GNUSTEP_HOST_CPU=`$GNUSTEP_SYSTEM_ROOT/@MAKEFILES_SUFFIX@/clean_cpu.sh $GNUSTEP_HOST_CPU`
156             export GNUSTEP_HOST_CPU
157         fi
158         if [ -z "$GNUSTEP_HOST_VENDOR" ]; then
159             GNUSTEP_HOST_VENDOR=`$GNUSTEP_SYSTEM_ROOT/@MAKEFILES_SUFFIX@/vendor.sh $GNUSTEP_HOST`
160             GNUSTEP_HOST_VENDOR=`$GNUSTEP_SYSTEM_ROOT/@MAKEFILES_SUFFIX@/clean_vendor.sh $GNUSTEP_HOST_VENDOR`
161             export GNUSTEP_HOST_VENDOR
162         fi
163         if [ -z "$GNUSTEP_HOST_OS" ]; then
164             GNUSTEP_HOST_OS=`$GNUSTEP_SYSTEM_ROOT/@MAKEFILES_SUFFIX@/os.sh $GNUSTEP_HOST`
165             GNUSTEP_HOST_OS=`$GNUSTEP_SYSTEM_ROOT/@MAKEFILES_SUFFIX@/clean_os.sh $GNUSTEP_HOST_OS`
166            export GNUSTEP_HOST_OS
167         fi
168         
169         if [ "$LIBRARY_COMBO" = nx-nx-nx -a "$GNUSTEP_HOST_OS" = nextstep4 ]; then
170           if [ -f "$full_appname/library_paths.openapp" ]; then
171             additional_library_paths="`cat \"$full_appname/library_paths.openapp\"`"
172           fi
173         fi
174 else
175   if [ -f "$full_appname/library_paths.openapp" ]; then
176     additional_library_paths="`cat \"$full_appname/library_paths.openapp\"`"
177   fi
178 fi
179
180 appname="`echo \"$app\" | sed 's/\.[a-z]*$//'`"
181 appname="`basename \"$appname\"`"
182 appname="$appname$EXEEXT"
183 . "$GNUSTEP_SYSTEM_ROOT/@MAKEFILES_SUFFIX@/ld_lib_path.sh"
184
185
186 if [ "$LIBRARY_COMBO" = "apple-apple-apple" ]; then
187   if [ ! -f "$full_appname/Contents/MacOS/$appname" ]; then
188     echo "$full_appname application does not have a binary for this kind of machine and operating system."
189     exit 1
190   fi
191
192   if [ -z "$corearg" ]; then
193     "$GDB" "$full_appname/Contents/MacOS/$appname"
194   else
195     "$GDB" "$full_appname/Contents/MacOS/$appname" "$corearg"
196   fi
197
198 else
199   # Determine if the application has a binary for this operating system
200   if [ -z "$GNUSTEP_FLATTENED" -a ! -d "$full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS" ]; then
201     echo "$full_appname application does not have a binary for this kind of machine and operating system."
202     exit 1
203   fi
204
205   if [ -z "$GNUSTEP_FLATTENED" -a ! -d "$full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO" ]; then
206     echo "$full_appname application does not have a binary for this combination of libraries: $LIBRARY_COMBO."
207     exit 1
208   fi
209
210   if [ -z "$GNUSTEP_FLATTENED" ]; then
211     file_appname="$full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/$appname"
212   else
213     file_appname="$full_appname/$appname"
214   fi
215
216   # Old versions of gdb don't support --args, so we only use it if
217   # 'gdb --help' lists it.
218   args=
219   if (gdb --help | grep -e '\-\-args' > /dev/null); then
220     args="--args"
221   fi
222
223   if [ -z "$corearg" ]; then
224
225     # Arguments passed to debugapp are passed over to the
226     # application, in the same way as it happens for openapp.
227     "$GDB" $args "$file_appname" "$@"
228   else
229     "$GDB" "$file_appname" "$corearg"
230   fi
231 fi