INIT.2014-12-24
[INIT.git] / src / cmd / INIT / crossexec.sh
blob67c72ab43b0cffa9321faa479142b34ac24fdd81
1 ########################################################################
2 # #
3 # This software is part of the ast package #
4 # Copyright (c) 1994-2016 AT&T Intellectual Property #
5 # and is licensed under the #
6 # Eclipse Public License, Version 1.0 #
7 # by AT&T Intellectual Property #
8 # #
9 # A copy of the License is available at #
10 # http://www.eclipse.org/org/documents/epl-v10.html #
11 # (with md5 checksum b35adb5213ca9657e911e9befb180842) #
12 # #
13 # Information and Software Systems Research #
14 # AT&T Research #
15 # Florham Park NJ #
16 # #
17 # Glenn Fowler <glenn.s.fowler@gmail.com> #
18 # #
19 ########################################################################
20 ########################################################################
21 # #
22 # This software is part of the ast package #
23 # Copyright (c) 1994-2011 AT&T Intellectual Property #
24 # and is licensed under the #
25 # Eclipse Public License, Version 1.0 #
26 # by AT&T Intellectual Property #
27 # #
28 # A copy of the License is available at #
29 # http://www.eclipse.org/org/documents/epl-v10.html #
30 # (with md5 checksum b35adb5213ca9657e911e9befb180842) #
31 # #
32 # Information and Software Systems Research #
33 # AT&T Research #
34 # Florham Park NJ #
35 # #
36 # Glenn Fowler <glenn.s.fowler@gmail.com> #
37 # #
38 ########################################################################
39 : cross compiler a.out execution
41 command=crossexec
43 tmp=/tmp/cross$$
45 case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in
46 0123) ARGV0="-a $command"
47 USAGE=$'
48 [-?
49 @(#)$Id: crossexec (AT&T Labs Research) 2004-01-04 $
51 '$USAGE_LICENSE$'
52 [+NAME?crossexec - cross compiler a.out execution]
53 [+DESCRIPTION?\bcrossexec\b runs a cross-compiled \acommand\a in an environment
54 that supports a cross-compilation architecture different from the
55 current host. The cross environment is determined by \acrosstype\a,
56 usually a host type name produced by \bpackage\b(1). \acrosstype\a
57 is used to find an entry in \b$HOME/.crossexec\b that specifies
58 the cross compiler host and access details.]
59 [+?The exit status of \bcrossexec\b is the exit status of \acommand\a.]
60 [+CROSS ENVIRONMENT FILE?\b$HOME/.crossexec\b contains one line for each
61 supported \acrosstype\a. Each line contains 5 tab separated fields.
62 Field default values are specified as \b-\b. The fields are:]{
63 [+crosstype?The host type produced by \bpackage\b(1).]
64 [+host?The host name.]
65 [+user?The user name on \ahost\a. The default is the current user.]
66 [+dir?The directory to copy \acommand\a and execute it. The default
67 is the \auser\a \b$HOME\b on \ahost\a.]
68 [+shell?The command used to get shell access to \ahost\a. Currently
69 only \brsh\b and \bssh\b are supported.]
70 [+copy?The command used to copy \acommand\a to \ahost\a. Currently
71 only \brcp\b and \bscp\b are supported.]
73 [n:show?Show the underlying commands but do not execute.]
75 crosstype command [ option ... ] [ file ... ]
77 [+SEE ALSO?\brcp\b(1), \brsh\b(1), \bscp\b(1), \bssh\b(1)]
80 *) ARGV0=""
81 USAGE="crosstype command [ option ... ] [ file ... ]"
83 esac
85 usage()
87 OPTIND=0
88 getopts $ARGV0 "$USAGE" OPT '-?'
89 exit 2
92 exec=
94 # get the options and operands
96 while getopts $ARGV0 "$USAGE" OPT
97 do case $OPT in
98 n) exec=echo ;;
99 *) usage ;;
100 esac
101 done
102 shift $OPTIND-1
103 case $# in
104 [01]) usage ;;
105 esac
107 type=$1
108 shift
109 cmd=$1
110 shift
112 # get the host info
114 info=$HOME/.$command
115 if test ! -r $info
116 then echo "$command: $info: not found" >&2
117 exit 1
119 ifs=${IFS-'
121 while :
122 do IFS=' '
123 read hosttype hostname usr dir sh cp
124 code=$?
125 IFS=$ifs
126 case $code in
127 0) ;;
128 *) echo "$command: $type: unknown cross compiler host type" >&2
129 exit 1
131 esac
132 case $hosttype in
133 $type) break ;;
134 esac
135 done < $info
137 # fill in the defaults
139 case $usr in
140 -) cpu= shu= ;;
141 *) cpu=${usr}@ shu="-l $usr" ;;
142 esac
143 case $dir in
144 -) dir= ;;
145 esac
146 case $sh in
147 ''|-) sh=ssh ;;
148 esac
149 case $cp in
150 ''|-) cp=scp ;;
151 scp) cp="$cp -q" ;;
152 esac
154 trap "rm -f $tmp" 0 1 2 3 15
155 $exec $cp $cmd $cpu$hostname:$dir </dev/null || exit 1
156 cmd=./${cmd##*/}
157 $exec $sh $shu $hostname "cd $dir; LD_LIBRARY_PATH=: $cmd $@ </dev/null 2>/dev/null; code=\$?; rm -f $cmd; echo $command: exit \$code >&2" </dev/null 2>$tmp
158 exit `sed -e '/^'$command': exit [0-9][0-9]*$/!d' -e 's/.* //' $tmp`