This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Bring more dist in line with dist-git
[metaconfig.git] / dist / U / Cross.U
CommitLineData
33a01fd2 1?RCS: $Id$
d8875586
MBT
2?RCS:
3?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
4?RCS:
33a01fd2 5?RCS: You may redistribute only under the terms of the Artistic License,
d8875586
MBT
6?RCS: as specified in the README file that comes with the distribution.
7?RCS: You may reuse parts of this distribution only within the terms of
33a01fd2 8?RCS: that same Artistic License; a copy of which may be found at the root
d8875586
MBT
9?RCS: of the source tree for dist 4.0.
10?RCS:
11?RCS: Copyright (c) 2001 Jarkko Hietaniemi
12?RCS:
13?MAKE:run to from targetarch usecrosscompile: src awk cat grep test rm \
14 echo sed mkdir cp touch chmod
15?MAKE: -pick add $@ %<
16?Y:TOP
17?S:usecrosscompile:
18?S: This variable conditionally defines the USE_CROSS_COMPILE symbol,
19?S: and indicates that our package has been cross-compiled.
20?S:.
21?S:run:
22?S: This variable contains the command used by Configure
23?S: to copy and execute a cross-compiled executable in the
24?S: target host. Useful and available only during the build.
25?S: Empty string '' if not cross-compiling.
26?S:.
27?S:from:
28?S: This variable contains the command used by Configure
29?S: to copy files from the target host. Useful and available
30?S: only during the build.
31?S: The string ':' if not cross-compiling.
32?S:.
33?S:to:
34?S: This variable contains the command used by Configure
35?S: to copy to from the target host. Useful and available
36?S: only during the build.
37?S: The string ':' if not cross-compiling.
38?S:.
39?S:targetarch:
40?S: If cross-compiling, this variable contains the target architecture.
41?S: If not, this will be empty.
42?S:.
43?C:USE_CROSS_COMPILE:
44?C: This symbol, if defined, indicates that the package is being
45?C: cross-compiled.
46?C:.
47?C:CROSS_TARGET_ARCH:
48?C: This symbol, if defined, indicates the target architecture
49?C: the package has been cross-compiled to.
50?C: Undefined if not a cross-compile.
51?C:.
52?H:?usecrosscompile:#ifndef USE_CROSS_COMPILE
53?H:?usecrosscompile:#$usecrosscompile USE_CROSS_COMPILE /**/
54?H:?usecrosscompile:#define CROSS_TARGET_ARCH "$targetarch" /**/
55?H:?usecrosscompile:#endif
56?H:.
57?T:croak pwd exe f q i j cwd
58?LINT:extern usecrosscompile
59?LINT:extern cc
60?LINT:extern usrinc
61?LINT:change usrinc
62?LINT:change ar
63?LINT:change nm
64?LINT:change ranlib
65?LINT:extern targethost
66?LINT:extern targetdir
67?LINT:change targetdir
68?LINT:extern targetuser
69?LINT:change targetuser
70?LINT:extern targetrun
71?LINT:extern targetfrom
72?LINT:extern targetto
73?LINT:extern targetmkdir
74?LINT:change targetrun
75?LINT:change targetfrom
76?LINT:change targetto
77?LINT:change targetmkdir
78?LINT:extern incpth
79?LINT:extern libpth
80?LINT:change incpth
81?LINT:change libpth
82?LINT:extern locincpth
83?LINT:extern loclibpth
84?LINT:change locincpth
85?LINT:change loclibpth
7bfb7bd7 86?LINT:extern TMPDIR
d8875586
MBT
87: setup for possible cross-compilation
88run=''
89to=:
90from=:
91usecrosscompile='undef'
92targetarch=''
93case "$usecrosscompile" in
94$define|true|[yY]*)
95@if { test -d ../Cross }
96?X:
97?X: Cross-compilation is enabled when there is a 'Cross' directory found
98?X: at the root of the package. This directory must contain the following
99?X: entries for defining the cross-compilation process:
100?X:
101?X: FIXME FIXME
102?X: WE MUST DISTINGUISH BETWEEN LOCAL cross-compiling AND REMOTE ONE
103?X: ACTUALLY, REMOTE COMPILATION SHOULD BE CONFIGURED INTERACTIVELY
104?X: IT WILL COPY ALL THE FILES FROM THE MANIFEST DOWN TO THE REMOTE DIR...
105?X: (and copy things like 'mkdep', etc...)
106?X:
107 $echo "Cross-compiling..."
108 croak=''
109 case "$cc" in
110 *-*-gcc)
111?X: A cross-compiling gcc, probably.
112 targetarch=`$echo $cc|$sed 's/-gcc$//'`
113 ar=$targetarch-ar
114?X: leave out ld, choosing it is more complex
115 nm=$targetarch-nm
116 ranlib=$targetarch-ranlib
117 $echo 'extern int foo;' > try.c
118 set X `$cc -v -E try.c 2>&1 | \
119 $awk '/^#include </,/^End of search /'|$grep '/include'`
120 shift
121 if $test $# -gt 0; then
122 incpth="$incpth $*"
123 incpth="`$echo $incpth|$sed 's/^ //'`"
124 echo "Guessing incpth '$incpth'." >&4
125 for i in $*; do
126 j="`$echo $i|$sed 's,/include$,/lib,'`"
127 if $test -d $j; then
128 libpth="$libpth $j"
129 fi
130 done
131 libpth="`$echo $libpth|$sed 's/^ //'`"
132 echo "Guessing libpth '$libpth'." >&4
133 fi
134 $rm -f try.c
135 ;;
136 esac
137 case "$targetarch" in
138 '') echo "Targetarch not defined." >&4; croak=y ;;
139 *) echo "Using targetarch $targetarch." >&4 ;;
140 esac
141 case "$incpth" in
142 '') echo "Incpth not defined." >&4; croak=y ;;
143 *) echo "Using incpth '$incpth'." >&4 ;;
144 esac
145 case "$libpth" in
146 '') echo "Libpth not defined." >&4; croak=y ;;
147 *) echo "Using libpth '$libpth'." >&4 ;;
148 esac
149 case "$usrinc" in
150 '')
151 for i in $incpth; do
152 if $test -f $i/errno.h -a -f $i/stdio.h -a -f $i/time.h; then
153 usrinc=$i
154 echo "Guessing usrinc $usrinc." >&4
155 break
156 fi
157 done
158 case "$usrinc" in
159 '') echo "Usrinc not defined." >&4; croak=y ;;
160 esac
161 ;;
162 *) echo "Using usrinc $usrinc." >&4 ;;
163 esac
164 case "$targethost" in
165 '') echo "Targethost not defined." >&4; croak=y ;;
166 *) echo "Using targethost $targethost." >&4
167 esac
168 locincpth=' '
169 loclibpth=' '
170 case "$croak" in
171 y) echo "Cannot continue, aborting." >&4; exit 1 ;;
172 esac
173 case "$src" in
174 /*) run=$src/Cross/run
175 targetmkdir=$src/Cross/mkdir
176 to=$src/Cross/to
177 from=$src/Cross/from
178 ;;
179 *) pwd=`$test -f ../Configure & cd ..; pwd`
180 run=$pwd/Cross/run
181 targetmkdir=$pwd/Cross/mkdir
182 to=$pwd/Cross/to
183 from=$pwd/Cross/from
184 ;;
185 esac
186 case "$targetrun" in
187 '') targetrun=ssh ;;
188 esac
189 case "$targetto" in
190 '') targetto=scp ;;
191 esac
192 case "$targetfrom" in
193 '') targetfrom=scp ;;
194 esac
195 run=$run-$targetrun
196 to=$to-$targetto
197 from=$from-$targetfrom
198 case "$targetdir" in
199 '')
7bfb7bd7 200 targetdir="${TMPDIR:-/tmp}"
d8875586
MBT
201 echo "Guessing targetdir $targetdir." >&4
202 ;;
203 esac
204 case "$targetuser" in
205 '')
206 targetuser=root
207 echo "Guessing targetuser $targetuser." >&4
208 ;;
209 esac
210 case "$targetfrom" in
211 scp) q=-q ;;
212 *) q='' ;;
213 esac
214 case "$targetrun" in
215 ssh|rsh)
216 $cat >$run <<EOF
217#!/bin/sh
218case "\$1" in
219-cwd)
220 shift
221 cwd=\$1
222 shift
223 ;;
224esac
225case "\$cwd" in
226'') cwd=$targetdir ;;
227esac
228exe=\$1
229shift
230if $test ! -f \$exe.xok; then
231 $to \$exe
232 $touch \$exe.xok
233fi
234$targetrun -l $targetuser $targethost "cd \$cwd && ./\$exe \$@"
235EOF
236 ;;
237 *) echo "Unknown targetrun '$targetrun'" >&4
238 exit 1
239 ;;
240 esac
241 case "$targetmkdir" in
242 */Cross/mkdir)
243 $cat >$targetmkdir <<EOF
244#!/bin/sh
245$targetrun -l $targetuser $targethost "mkdir -p \$@"
246EOF
247 $chmod a+rx $targetmkdir
248 ;;
249 *) echo "Unknown targetmkdir '$targetmkdir'" >&4
250 exit 1
251 ;;
252 esac
253 case "$targetto" in
254 scp|rcp)
255 $cat >$to <<EOF
256#!/bin/sh
257for f in \$@
258do
259 case "\$f" in
260 /*)
261 $targetmkdir \`dirname \$f\`
262 $targetto $q \$f $targetuser@$targethost:\$f || exit 1
263 ;;
264 *)
265 $targetmkdir $targetdir/\`dirname \$f\`
266 $targetto $q \$f $targetuser@$targethost:$targetdir/\$f || exit 1
267 ;;
268 esac
269done
270exit 0
271EOF
272 ;;
273 cp) $cat >$to <<EOF
274#!/bin/sh
275for f in \$@
276do
277 case "\$f" in
278 /*)
279 $mkdir -p $targetdir/\`dirname \$f\`
280 $cp \$f $targetdir/\$f || exit 1
281 ;;
282 *)
283 $targetmkdir $targetdir/\`dirname \$f\`
284 $cp \$f $targetdir/\$f || exit 1
285 ;;
286 esac
287done
288exit 0
289EOF
290 ;;
291 *) echo "Unknown targetto '$targetto'" >&4
292 exit 1
293 ;;
294 esac
295 case "$targetfrom" in
296 scp|rcp)
297 $cat >$from <<EOF
298#!/bin/sh
299for f in \$@
300do
301 $rm -f \$f
302 $targetfrom $q $targetuser@$targethost:$targetdir/\$f . || exit 1
303done
304exit 0
305EOF
306 ;;
307 cp) $cat >$from <<EOF
308#!/bin/sh
309for f in \$@
310do
311 $rm -f \$f
312 cp $targetdir/\$f . || exit 1
313done
314exit 0
315EOF
316 ;;
317 *) echo "Unknown targetfrom '$targetfrom'" >&4
318 exit 1
319 ;;
320 esac
321 if $test ! -f $run; then
322 echo "Target 'run' script '$run' not found." >&4
323 else
324 $chmod a+rx $run
325 fi
326 if $test ! -f $to; then
327 echo "Target 'to' script '$to' not found." >&4
328 else
329 $chmod a+rx $to
330 fi
331 if $test ! -f $from; then
332 echo "Target 'from' script '$from' not found." >&4
333 else
334 $chmod a+rx $from
335 fi
336 if $test ! -f $run -o ! -f $to -o ! -f $from; then
337 exit 1
338 fi
339 $cat >&4 <<EOF
340Using '$run' for remote execution,
341and '$from' and '$to'
342for remote file transfer.
343EOF
344@else
345 echo "Cross-compilation is not supported for this package." >&4
346 exit 1
347@end
348 ;;
349esac
350