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,2007
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 3
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.
22# If not, write to the Free Software Foundation,
23# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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# This is installed inside the application directory in the
29# non-flattened case.  In the flattened case, we install the binary
30# directly in the application directory and no wrappers are used.
31
32if [ -z "$EXEEXT" ]; then
33  EXEEXT=@EXEEXT@
34fi
35if [ -z "$LIBRARY_COMBO" ]; then
36  LIBRARY_COMBO=@ac_cv_library_combo@
37fi
38
39
40# Try to determine GNUSTEP_MAKEFILES to source GNUstep.sh
41if [ -z "$GNUSTEP_CONFIG_FILE" ]; then
42  GNUSTEP_CONFIG_FILE=@GNUSTEP_CONFIG_FILE@
43fi
44
45if [ -z "$GNUSTEP_USER_CONFIG_FILE" ]; then
46  GNUSTEP_USER_CONFIG_FILE=@GNUSTEP_USER_CONFIG_FILE@
47fi
48
49if [ -f "$GNUSTEP_CONFIG_FILE" ]; then
50  . "$GNUSTEP_CONFIG_FILE"
51fi
52
53GNUSTEP_HOME=~
54
55if [ -n "$GNUSTEP_USER_CONFIG_FILE" ]; then
56  case "$GNUSTEP_USER_CONFIG_FILE" in
57    /*) # An absolute path
58        if [ -f "$GNUSTEP_USER_CONFIG_FILE" ]; then
59          . "$GNUSTEP_USER_CONFIG_FILE"
60        fi;;
61     *) # Something else
62        if [ -f "$GNUSTEP_HOME/$GNUSTEP_USER_CONFIG_FILE" ]; then
63          . "$GNUSTEP_HOME/$GNUSTEP_USER_CONFIG_FILE"
64        fi;;
65  esac
66fi
67
68if [ -z "$GNUSTEP_MAKEFILES" ]; then
69  GNUSTEP_MAKEFILES=@GNUSTEP_MAKEFILES@
70fi
71# OK, we now have GNUSTEP_MAKEFILES, we later can source GNUstep.sh.
72
73# Process arguments
74this_script="$0"
75show_available_platforms=0
76show_relative_path=0
77show_full_path=0
78while true
79do
80  case "$1" in
81
82    --script-help)
83	echo usage: `basename "$0"` [--library-combo=...]
84	echo "       [--available-platforms][--full-executable-path]"
85	echo "       [--relative-executable-path] [arguments...]"
86	echo
87	echo "   --library-combo=... specifies a GNUstep backend to use."
88	echo "   It overrides the default LIBRARY_COMBO environment variable."
89	echo
90	echo "   --available-platforms displays a list of valid exec hosts"
91	echo "   --full-executable-path displays full path to executable"
92	echo "   --relative-executable-path displays subdirectory path"
93	echo "   arguments... are the arguments to the application."
94	exit 0
95	;;
96    --library-combo=*)
97        tmp_makefiles="$GNUSTEP_MAKEFILES"
98        . "$tmp_makefiles/GNUstep-reset.sh"
99        LIBRARY_COMBO=`echo "$1" | sed 's/--library-combo=//'`
100        GNUSTEP_MAKEFILES="$tmp_makefiles"
101	shift
102	;;
103    --available-platforms)
104        show_available_platforms=1
105        exit 0
106	;;
107    --full-executable-path)
108	show_full_path=1
109        break
110	;;
111    --relative-executable-path)
112	show_relative_path=1
113        break
114	;;
115    *)
116        break;;
117    esac
118done
119
120if [ "$LIBRARY_COMBO" = nx ]; then
121  LIBRARY_COMBO=nx-nx-nx
122elif [ "$LIBRARY_COMBO" = gnu ]; then
123  LIBRARY_COMBO=gnu-gnu-gnu
124elif [ "$LIBRARY_COMBO" = fd ]; then
125  LIBRARY_COMBO=gnu-fd-gnu
126elif [ "$LIBRARY_COMBO" = apple ]; then
127  LIBRARY_COMBO=apple-apple-apple
128fi
129export LIBRARY_COMBO
130
131# We now have determined both GNUSTEP_MAKEFILES and LIBRARY_COMBO.
132# Source GNUstep.sh to make sure all the environment is setup
133# to work in this LIBRARY_COMBO.
134. "$GNUSTEP_MAKEFILES/GNUstep.sh"
135
136# Find path to directory containing ourselves.  This directory is
137# the .app directory.
138dir="`dirname \"$this_script\"`"
139
140# Find the absolute path of the directory.  This will be something like
141# /home/nicola/testing/Applications/Gorm.app
142full_appname="`(cd \"$dir\"; pwd)`"
143
144if [ -z "$full_appname" ]; then
145  echo "Can't find absolute path for $this_script! Please specify full path when"
146  echo "invoking executable"
147  exit 1
148fi
149
150#
151# Get base app name (eg, Gorm in the case of Gorm.app, but crazy people might
152# configure it differently by using a different NSExecutable setting in
153# Info-gnustep.plist).
154#
155appname=
156if [ -f "$full_appname/Resources/Info-gnustep.plist" ]; then
157# -n disable auto-print (for portability reasons)
158#   /^ *NSExecutable *=/ matches every line beginning with
159#        zero or more spaces, followed by 'NSExecutable', followed by zero or
160#        more spaces, followed by '='
161#   to this line we apply the following commands:
162#   s/"//g; which deletes all " in the line.
163#   s/^ *NSExecutable *= *\([^ ;]*\) *;.*/\1/p;
164#     which replaces 'NSExecutable = Gorm; ' with 'Gorm', then, because
165#     of the 'p' at the end, prints out the result
166#   q; which quits sed since we know there must be only a single line
167#      to replace.
168  appname=`sed -n -e '/^ *NSExecutable *=/ \
169           {s/"//g; s/^ *NSExecutable *= *\([^ ;]*\) *;.*/\1/p; q;}' \
170                "$full_appname/Resources/Info-gnustep.plist"`
171fi
172if [ -z "$appname" ]; then
173  appname="`basename \"$this_script\"`"
174fi
175
176appname="$appname$EXEEXT"
177
178if [ $show_available_platforms = 1 ]; then
179  cd "$full_appname"
180  #TODO: show available_platforms
181  exit 0
182fi
183
184#
185# Make sure the executable is there
186#
187if [ -x "$full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/$appname" ]; then
188  relative_path="$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/$appname"
189elif [ -x "$full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$appname" ]; then
190  relative_path="$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$appname"
191elif [ -x "$full_appname/$GNUSTEP_HOST_CPU/$appname" ]; then
192  relative_path="$GNUSTEP_HOST_CPU/$appname"
193elif [ "$full_appname/$appname" != "$0" -a -x "$full_appname/$appname" ]; then
194  relative_path="$appname"
195else
196  # Search for a binary for this machine but a different library combo
197  if [ -d "$full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS" ]; then
198    tmp_path="`pwd`"
199    cd "$full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS";
200    found=no
201    for lib_combo in * ; do
202      if [ "$lib_combo" != '*' ]; then
203        if [ -x "$lib_combo/$appname" ]; then
204          # Switch LIBRARY_COMBO on the fly
205          tmp_makefiles="$GNUSTEP_MAKEFILES"
206          . "$tmp_makefiles/GNUstep-reset.sh"
207          LIBRARY_COMBO="$lib_combo"
208          . "$tmp_makefiles/GNUstep.sh"
209          # Use the found executable
210          relative_path="$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/$appname"
211          found=yes
212          break
213        fi
214      fi
215    done
216    cd "$tmp_path"
217    if [ "$found" != yes ]; then
218      echo "$full_appname application does not have a binary for this kind of machine/operating system ($GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS)."
219      exit 1
220    fi
221  fi
222fi
223
224if [ $show_relative_path = 1 ]; then
225  echo "$relative_path"
226  exit 0
227fi
228if [ $show_full_path = 1 ]; then
229  echo "$full_appname/$relative_path"
230  exit 0
231fi
232
233exec "$full_appname/$relative_path" "$@"
234
235