Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/INIT/crossexec.sh
1808 views
1
########################################################################
2
# #
3
# This software is part of the ast package #
4
# Copyright (c) 1994-2011 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 <[email protected]> #
18
# #
19
########################################################################
20
: cross compiler a.out execution
21
22
command=crossexec
23
24
tmp=/tmp/cross$$
25
26
case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in
27
0123) ARGV0="-a $command"
28
USAGE=$'
29
[-?
30
@(#)$Id: crossexec (AT&T Labs Research) 2004-01-04 $
31
]
32
'$USAGE_LICENSE$'
33
[+NAME?crossexec - cross compiler a.out execution]
34
[+DESCRIPTION?\bcrossexec\b runs a cross-compiled \acommand\a in an environment
35
that supports a cross-compilation architecture different from the
36
current host. The cross environment is determined by \acrosstype\a,
37
usually a host type name produced by \bpackage\b(1). \acrosstype\a
38
is used to find an entry in \b$HOME/.crossexec\b that specifies
39
the cross compiler host and access details.]
40
[+?The exit status of \bcrossexec\b is the exit status of \acommand\a.]
41
[+CROSS ENVIRONMENT FILE?\b$HOME/.crossexec\b contains one line for each
42
supported \acrosstype\a. Each line contains 5 tab separated fields.
43
Field default values are specified as \b-\b. The fields are:]{
44
[+crosstype?The host type produced by \bpackage\b(1).]
45
[+host?The host name.]
46
[+user?The user name on \ahost\a. The default is the current user.]
47
[+dir?The directory to copy \acommand\a and execute it. The default
48
is the \auser\a \b$HOME\b on \ahost\a.]
49
[+shell?The command used to get shell access to \ahost\a. Currently
50
only \brsh\b and \bssh\b are supported.]
51
[+copy?The command used to copy \acommand\a to \ahost\a. Currently
52
only \brcp\b and \bscp\b are supported.]
53
}
54
[n:show?Show the underlying commands but do not execute.]
55
56
crosstype command [ option ... ] [ file ... ]
57
58
[+SEE ALSO?\brcp\b(1), \brsh\b(1), \bscp\b(1), \bssh\b(1)]
59
'
60
;;
61
*) ARGV0=""
62
USAGE="crosstype command [ option ... ] [ file ... ]"
63
;;
64
esac
65
66
usage()
67
{
68
OPTIND=0
69
getopts $ARGV0 "$USAGE" OPT '-?'
70
exit 2
71
}
72
73
exec=
74
75
# get the options and operands
76
77
while getopts $ARGV0 "$USAGE" OPT
78
do case $OPT in
79
n) exec=echo ;;
80
*) usage ;;
81
esac
82
done
83
shift $OPTIND-1
84
case $# in
85
[01]) usage ;;
86
esac
87
88
type=$1
89
shift
90
cmd=$1
91
shift
92
93
# get the host info
94
95
info=$HOME/.$command
96
if test ! -r $info
97
then echo "$command: $info: not found" >&2
98
exit 1
99
fi
100
ifs=${IFS-'
101
'}
102
while :
103
do IFS=' '
104
read hosttype hostname usr dir sh cp
105
code=$?
106
IFS=$ifs
107
case $code in
108
0) ;;
109
*) echo "$command: $type: unknown cross compiler host type" >&2
110
exit 1
111
;;
112
esac
113
case $hosttype in
114
$type) break ;;
115
esac
116
done < $info
117
118
# fill in the defaults
119
120
case $usr in
121
-) cpu= shu= ;;
122
*) cpu=${usr}@ shu="-l $usr" ;;
123
esac
124
case $dir in
125
-) dir= ;;
126
esac
127
case $sh in
128
''|-) sh=ssh ;;
129
esac
130
case $cp in
131
''|-) cp=scp ;;
132
scp) cp="$cp -q" ;;
133
esac
134
135
trap "rm -f $tmp" 0 1 2 3 15
136
$exec $cp $cmd $cpu$hostname:$dir </dev/null || exit 1
137
cmd=./${cmd##*/}
138
$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
139
exit `sed -e '/^'$command': exit [0-9][0-9]*$/!d' -e 's/.* //' $tmp`
140
141