]> err.no Git - sope/blob - opentool.in
5b7f9d33a28bf493c805782190e0672e8f613cf1
[sope] / opentool.in
1 #! /bin/sh
2 #
3 # @configure_input@
4 #
5 # Copyright (C) 1997, 1999 Free Software Foundation, Inc.
6 #
7 # Author: Scott Predescu <ovidiu@net-community.com>
8 # Author: Ovidiu Predescu <ovidiu@net-community.com>
9 # Date: February 1999
10
11 # This file is part of the GNUstep Makefile Package.
12 #
13 # This library is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; either version 2
16 # of the License, or (at your option) any later version.
17
18 # You should have received a copy of the GNU General Public
19 # License along with this library; see the file COPYING.LIB.
20 # If not, write to the Free Software Foundation,
21 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23 # Try to execute the GNUstep tool passed as argument. The tool is
24 # searched through the GNUstep directories if a complete or relative path name
25 # is not specified. The arguments passed after the tool name are passed
26 # unmodified to the tool.
27
28 if [ -z "$GNUSTEP_PATHLIST" ]; then
29   echo "The GNUSTEP_PATHLIST environment variable is missing."
30   echo "Did you forget to set up your environment using GNUstep.sh ?"
31   exit 1
32 fi
33
34 if [ -z "$1" ]; then
35   echo usage: `basename "$0"` [--library-combo=...] tool [arguments...]
36   echo `basename "$0"` --help for help
37   exit 1
38 fi
39
40 if [ -z "$EXEEXT" ]; then
41   EXEEXT=@EXEEXT@
42 fi
43
44 # traps the parameters
45 while true
46 do 
47   case "$1" in
48     --library-combo=*)
49         tmp_root="$GNUSTEP_SYSTEM_ROOT"
50         . "$tmp_root/@MAKEFILES_SUFFIX@/GNUstep-reset.sh"
51         LIBRARY_COMBO=`echo "$1" | sed 's/--library-combo=//'`
52         . "$tmp_root/@MAKEFILES_SUFFIX@/GNUstep.sh"
53         echo "Switched to library combo $LIBRARY_COMBO"
54         shift
55         ;;
56     --help)
57       echo usage: `basename "$0"` [--library-combo=...] tool [arguments...]
58       echo
59       echo tool is the complete or relative name of the tool executable
60       echo without any extension, like defaults
61       echo
62       echo [arguments...] are the arguments to the tool.
63       exit 0
64       ;;
65     *)
66       break;;
67   esac
68 done
69
70 tool="$1";
71 shift;
72
73 if [ -n "$EXEEXT" ]; then
74   tool="$tool$EXEEXT"
75 fi
76
77 case "$tool" in
78   /*)   # An absolute path.
79         full_toolname="$tool";;
80   */*)  # A relative path
81         tool_dir="`dirname \"$tool\"`"; 
82         tool_dir="`(cd \"$tool_dir\"; pwd)`"; 
83         tool_name="`basename \"$tool\"`";
84         full_toolname="${tool_dir}/${tool_name}";;
85   *)    # A path that should be searched into GNUstep tool paths
86
87         # Search for a local tool
88
89         # We used to scan all ./*/$(GNUSTEP_HOST_LDIR)/ directories,
90         # but this facility was removed (GNUSTEP_HOST_LDIR is no
91         # longer even defined in this file), now we perform a much
92         # simpler search.
93
94         # The really important one is looking into ./obj, anyway here
95         # is the order in which we search local directories - 
96         # First, we search in ./
97         # Second, we search in ./obj
98         # Third, we search in ./Tools/
99         # Fourth, we search in ./Tools/obj
100         for dir in . obj Tools Tools/obj; do
101           # echo "$dir/$tool";
102           if [ -x "$dir/$tool" ]; then
103             full_toolname="$dir/$tool"
104             # echo "Found: $dir/$tool";
105             break;
106           fi
107         done
108
109         if [ -z "$full_toolname" ]; then 
110           
111           # Local tool not found - Search for an installed one
112           # we search in GNUSTEP_PATHLIST, which means we
113           # search in the order in:
114           # GNUSTEP_USER_ROOT
115           # GNUSTEP_LOCAL_ROOT
116           # GNUSTEP_NETWORK_ROOT
117           # GNUSTEP_SYSTEM_ROOT
118           #
119           # We look in the GNUSTEP_HOST_CPU/GNUSTEP_HOST_OS/LIBRARY_COMBO
120           # subdirectory first, then the GNUSTEP_HOST_CPU/GNUSTEP_HOST_OS
121           # subdirectory, then the top-level directory.
122           # (For flattened systems we skip the first two options.
123           #
124           if [ -n "$GNUSTEP_PATHLIST" ]; then
125             SPATH="$GNUSTEP_PATHLIST"
126             IFS=:
127             for dir in $SPATH; do
128               tmpdir="$dir/Tools"
129               if [ -z "$GNUSTEP_FLATTENED" ]; then
130                 tmpgnudir="$dir/Tools/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS"
131                 tmplibdir="$tmpgnudir/$LIBRARY_COMBO"
132                 # echo "$tmplibdir/$tool";
133                 if [ -x "$tmplibdir/$tool" ]; then
134                   # echo "Found: $tmplibdir/$tool";
135                   full_toolname="$tmplibdir/$tool"
136                   break;
137                 fi
138                 if [ -x "$tmpgnudir/$tool" ]; then
139                   # echo "Found: $tmpgnudir/$tool";
140                   full_toolname="$tmpgnudir/$tool"
141                   break;
142                 fi
143               fi
144               # echo "$tmpdir/$tool";
145               if [ -x "$tmpdir/$tool" ]; then
146                 # echo "Found: $tmpdir/$tool";
147                 full_toolname="$tmpdir/$tool"
148                 break;
149               fi
150             done
151             unset tmpdir
152             unset tmpgnudir
153             unset tmplibdir
154             IFS=" "
155           fi
156         fi
157         ;;
158 esac
159
160 if [ -z "$full_toolname" ]; then
161   echo "Can't find the required tool: $tool!"
162   exit 1
163 fi
164
165 IFS=" "
166 exec "$full_toolname" "$@"