This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix .gitignore: only ignore 'perl' in root of repo, not U/perl subdir
[metaconfig.git] / U / perl / Cross.U
CommitLineData
0f00356b
JH
1?RCS: $Id$
2?RCS:
3?RCS: Copyright (c) 2001 Jarkko Hietaniemi
4?RCS:
5?RCS: You may distribute under the terms of either the GNU General Public
6?RCS: License or the Artistic License, as specified in the README file.
7?RCS:
76d1bd01
MBT
8?MAKE:run to from targetarch targetdir targetmkdir targethost targetport \
9 usecrosscompile hostperl hostgenerate hostosname targetenv: \
10 src test rm echo sed mkdir cp chmod make touch
0f00356b
JH
11?MAKE: -pick add $@ %<
12?Y:TOP
13?S:usecrosscompile:
14?S: This variable conditionally defines the USE_CROSS_COMPILE symbol,
15?S: and indicates that Perl has been cross-compiled.
16?S:.
17?S:run:
18?S: This variable contains the command used by Configure
19?S: to copy and execute a cross-compiled executable in the
20?S: target host. Useful and available only during Perl build.
21?S: Empty string '' if not cross-compiling.
22?S:.
23?S:from:
24?S: This variable contains the command used by Configure
25?S: to copy files from the target host. Useful and available
26?S: only during Perl build.
27?S: The string ':' if not cross-compiling.
28?S:.
29?S:to:
30?S: This variable contains the command used by Configure
31?S: to copy to from the target host. Useful and available
32?S: only during Perl build.
33?S: The string ':' if not cross-compiling.
34?S:.
35?S:targetarch:
36?S: If cross-compiling, this variable contains the target architecture.
37?S: If not, this will be empty.
38?S:.
9c11722e
MB
39?S:targetdir:
40?S: This variable contains a path that will be created on the target
41?S: host using targetmkdir, and then used to copy the cross-compiled
42?S: executables to. Defaults to '/tmp' if not set.
43?S:.
44?S:targetmkdir:
45?S: This variable contains the command used by Configure to create a
46?S: new directory on the target host.
47?S:.
48?S:targethost:
49?S: This variable contains the name of a separate host machine that
50?S: can be used to run compiled test programs and perl tests on.
51?S: Set to empty string if not in use.
52?S:.
53?S:targetport:
54?S: This variable contains the number of a network port to be used to
55?S: connect to the host in targethost, if unset defaults to 22 for ssh.
56?S:.
76d1bd01
MBT
57?S:hostperl:
58?S: This variable contains the path to a miniperl binary that can be
59?S: run on the host OS when cross-compiling. Useful and available only
60?S: during Perl build.
61?S: Empty string '' if not cross-compiling.
62?S:.
63?S:hostgenerate:
64?S: This variable contains the path to a generate_uudmap binary that
65?S: can be run on the host OS when cross-compiling. Useful and
66?S: available only during Perl build.
67?S: Empty string '' if not cross-compiling.
68?S:.
69?S:hostosname:
70?S: This variable contains the original value of '$^O' for hostperl
71?S: when cross-compiling. This is useful to pick the proper tools
72?S: when running build code in the host.
73?S: Empty string '' if not cross-compiling.
74?S:.
75?S:targetenv:
76?S: If cross-compiling, this variable can be used to modify the
77?S: environment on the target system.
78?S: However, how and where it's used, and even if it's used at all, is
79?S: entirely dependent on both the transport mechanism (targetrun) and
80?S: what the target system is. Unless the relevant documentation says
81?S: otherwise, it is genereally not useful.
82?S:.
0f00356b
JH
83?C:USE_CROSS_COMPILE:
84?C: This symbol, if defined, indicates that Perl is being cross-compiled.
85?C:.
86?C:PERL_TARGETARCH:
87?C: This symbol, if defined, indicates the target architecture
88?C: Perl has been cross-compiled to. Undefined if not a cross-compile.
89?C:.
0f00356b
JH
90?H:?%<:#ifndef USE_CROSS_COMPILE
91?H:?%<:#$usecrosscompile USE_CROSS_COMPILE /**/
92?H:?%<:#define PERL_TARGETARCH "$targetarch" /**/
93?H:?%<:#endif
94?H:.
76d1bd01 95?D:targetenv=''
9c11722e
MB
96?D:targethost=''
97?D:targetmkdir=''
76d1bd01 98?T:croak pwd exe f q cwd file xxx env
0f00356b
JH
99?LINT:extern usecrosscompile
100?LINT:extern cc
101?LINT:extern usrinc
0f00356b
JH
102?LINT:change ar
103?LINT:change nm
104?LINT:change ranlib
76d1bd01 105?LINT:change src
5f6c99a5 106?LINT:extern targetenv
9c11722e 107?LINT:extern targetport
0f00356b
JH
108?LINT:extern targetdir
109?LINT:extern targetuser
110?LINT:change targetuser
111?LINT:extern targetrun
112?LINT:extern targetfrom
113?LINT:extern targetto
114?LINT:change targetrun
115?LINT:change targetfrom
116?LINT:change targetto
04c4183c
JH
117?LINT:extern incpth
118?LINT:extern libpth
0f00356b
JH
119?LINT:extern locincpth
120?LINT:extern loclibpth
121?LINT:change locincpth
122?LINT:change loclibpth
9c11722e
MB
123?LINT:extern hostperl
124?LINT:extern hostgenerate
76d1bd01
MBT
125?LINT:extern before_host
126?LINT:change before_host
127?LINT:extern hostosname
128?LINT:extern multiarch
d7a2632b 129: Check for Cross-Compilation
5f6c99a5 130?X: targethost and targetenv mainly set to allow ?S: documentation
9c11722e
MB
131?X:otherwise it could have been declared extern
132if $test "X$targethost" = "X"; then
133 targethost=""
134fi
5f6c99a5
MBT
135if $test "X$targetenv" = "X"; then
136 targetenv=""
137fi
0f00356b
JH
138case "$usecrosscompile" in
139$define|true|[yY]*)
04c4183c 140 $echo "Cross-compiling..."
9c11722e
MB
141 croak=''
142 case "$cc" in
143 *-gcc*|*-g++*) # A cross-compiling gcc, probably.
144 # arm-linux-androideabi-gcc -> arm-linux-androideabi
145 # x86_64-w64-mingw32-gcc.exe -> x86_64-w64-mingw32
146 targetarch=`$echo $cc|$sed 's/-g[c\+][c\+].*$//'`
147 ar=`$echo $cc|$sed 's/-g[c\+][c\+]/-ar/'`
0f00356b 148 # leave out ld, choosing it is more complex
9c11722e
MB
149 nm=`$echo $cc|$sed 's/-g[c\+][c\+]/-nm/'`
150 ranlib=`$echo $cc|$sed 's/-g[c\+][c\+]/-ranlib/'`
151 # We are in a weird spot. Just before us, some values
152 # were 'saved', to be restored after the hints are
153 # run. This means that the changes we made to ar,
154 # nm and ranlib will get reverted.
155 # To avoid that, we hijack the saving mechanism and
156 # have it save our new values.
157 for file in ar nm ranlib; do
158 eval xxx=\$$file
159 eval $file=$xxx$_exe
160 eval _$file=$xxx
161 done
162 ;;
0f00356b
JH
163 esac
164 case "$targetarch" in
04c4183c 165 '') echo "Targetarch not defined." >&4; croak=y ;;
9c11722e 166 *) echo "Using targetarch $targetarch." >&4 ;;
0f00356b 167 esac
04c4183c 168 case "$targethost" in
38a802f7 169 '') echo "Targethost not defined." >&4; croak=n ;;
9c11722e 170 *) echo "Using targethost $targethost." >&4
0f00356b 171 esac
04c4183c
JH
172 locincpth=' '
173 loclibpth=' '
0f00356b 174 case "$croak" in
04c4183c 175 y) echo "Cannot continue, aborting." >&4; exit 1 ;;
0f00356b 176 esac
76d1bd01
MBT
177 : compile a host miniperl and generate_uudmap, unless we got passed them
178 if $test "X$hostperl" = X; then
179 echo "Building host miniperl and generate_uudmap binaries" >&4
180 before_host=`pwd`
181 cd ..
182 cd $src
183 src=`pwd`
184 rm -rf $src/host
185 mkdir $src/host
186 cd $src/host
187 $src/Configure -des -Dusedevel -Dmksymlinks
188 $make miniperl
189 case "$hostgenerate" in
190 '') $make generate_uudmap
191 hostgenerate=$src/host/generate_uudmap
192 ;;
193 "$undef") hostgenerate=''
194 ;;
195 esac
196 hostperl=$src/host/miniperl
197 cd $before_host
198 fi
199 hostosname=`$hostperl -le 'print $^O'`
200 ;;
201*)
202 usecrosscompile="$undef"
203 ;;
204esac
205
206: Define -Dtargethost=somecomputer to run compiled tests on another machine
207case "$targethost" in
208 '') echo "Checking for cross-compile" >&4
209 case "$usecrosscompile$multiarch" in
210 *$define*) echo "Skipping the try tests in the rest of Configure as no targethost was defined when cross-compiling" >&4
211 if [ -f Makefile ]; then
212 echo " "
213 echo "Now you must ensure config.sh, config.h and the generated headers exist and run a $make."
214 else
215 echo "Configure done."
216 fi
217 exit 0
218 ;;
219 *) echo "No targethost for running compiler tests against defined, running locally" >&4
220 run=''
221 to=:
222 from=:
223 ;;
224 esac
225 ;;
226 *) echo "Using targethost $targethost." >&4
0f00356b
JH
227 case "$src" in
228 /*) run=$src/Cross/run
ba8b1086 229 targetmkdir=$src/Cross/mkdir
0f00356b
JH
230 to=$src/Cross/to
231 from=$src/Cross/from
232 ;;
04c4183c 233 *) pwd=`$test -f ../Configure & cd ..; pwd`
0f00356b 234 run=$pwd/Cross/run
a65d8156 235 targetmkdir=$pwd/Cross/mkdir
0f00356b
JH
236 to=$pwd/Cross/to
237 from=$pwd/Cross/from
238 ;;
239 esac
240 case "$targetrun" in
241 '') targetrun=ssh ;;
242 esac
243 case "$targetto" in
244 '') targetto=scp ;;
245 esac
246 case "$targetfrom" in
247 '') targetfrom=scp ;;
248 esac
9c11722e
MB
249 run=$run-$targetrun
250 to=$to-$targetto
251 from=$from-$targetfrom
04c4183c
JH
252 case "$targetdir" in
253 '') targetdir=/tmp
9c11722e
MB
254 echo "Guessing targetdir $targetdir." >&4
255 ;;
04c4183c 256 esac
0f00356b 257 case "$targetuser" in
04c4183c 258 '') targetuser=root
9c11722e
MB
259 echo "Guessing targetuser $targetuser." >&4
260 ;;
261 esac
262 case "$targetport" in
263 '') targetport=22
264 echo "Guessing targetport $targetport." >&4
265 ;;
0f00356b
JH
266 esac
267 case "$targetfrom" in
268 scp) q=-q ;;
269 *) q='' ;;
270 esac
271 case "$targetrun" in
272 ssh|rsh)
273 cat >$run <<EOF
274#!/bin/sh
76d1bd01 275env=''
ba8b1086
JH
276case "\$1" in
277-cwd)
278 shift
279 cwd=\$1
280 shift
281 ;;
282esac
76d1bd01
MBT
283case "\$1" in
284-env)
285 shift
286 env=\$1
287 shift
288 ;;
289esac
ba8b1086
JH
290case "\$cwd" in
291'') cwd=$targetdir ;;
292esac
0f00356b
JH
293exe=\$1
294shift
9c11722e 295$to \$exe
76d1bd01 296$targetrun -p $targetport -l $targetuser $targethost "cd \$cwd && \$env \$exe \$@"
0f00356b
JH
297EOF
298 ;;
76d1bd01
MBT
299 adb)
300 $touch $run
301 ;;
04c4183c 302 *) echo "Unknown targetrun '$targetrun'" >&4
0f00356b
JH
303 exit 1
304 ;;
305 esac
ba8b1086
JH
306 case "$targetmkdir" in
307 */Cross/mkdir)
308 cat >$targetmkdir <<EOF
309#!/bin/sh
9c11722e 310$targetrun -p $targetport -l $targetuser $targethost "mkdir -p \$@"
ba8b1086 311EOF
a65d8156 312 $chmod a+rx $targetmkdir
ba8b1086
JH
313 ;;
314 *) echo "Unknown targetmkdir '$targetmkdir'" >&4
315 exit 1
316 ;;
317 esac
0f00356b
JH
318 case "$targetto" in
319 scp|rcp)
320 cat >$to <<EOF
321#!/bin/sh
322for f in \$@
323do
ba8b1086
JH
324 case "\$f" in
325 /*)
326 $targetmkdir \`dirname \$f\`
76d1bd01 327 $targetto -P $targetport -r $q \$f $targetuser@$targethost:\$f 2>/dev/null || exit 1
ba8b1086
JH
328 ;;
329 *)
330 $targetmkdir $targetdir/\`dirname \$f\`
76d1bd01 331 $targetto -P $targetport -r $q \$f $targetuser@$targethost:$targetdir/\$f 2>/dev/null || exit 1
ba8b1086
JH
332 ;;
333 esac
0f00356b
JH
334done
335exit 0
336EOF
337 ;;
338 cp) cat >$to <<EOF
339#!/bin/sh
ba8b1086
JH
340for f in \$@
341do
342 case "\$f" in
343 /*)
344 $mkdir -p $targetdir/\`dirname \$f\`
345 $cp \$f $targetdir/\$f || exit 1
346 ;;
347 *)
348 $targetmkdir $targetdir/\`dirname \$f\`
349 $cp \$f $targetdir/\$f || exit 1
350 ;;
351 esac
352done
353exit 0
0f00356b
JH
354EOF
355 ;;
04c4183c 356 *) echo "Unknown targetto '$targetto'" >&4
0f00356b
JH
357 exit 1
358 ;;
359 esac
360 case "$targetfrom" in
361 scp|rcp)
362 cat >$from <<EOF
363#!/bin/sh
364for f in \$@
365do
ba8b1086 366 $rm -f \$f
9c11722e 367 $targetfrom -P $targetport $q $targetuser@$targethost:$targetdir/\$f . || exit 1
0f00356b
JH
368done
369exit 0
370EOF
371 ;;
372 cp) cat >$from <<EOF
373#!/bin/sh
374for f in \$@
375do
ba8b1086 376 $rm -f \$f
0f00356b
JH
377 cp $targetdir/\$f . || exit 1
378done
379exit 0
380EOF
381 ;;
04c4183c 382 *) echo "Unknown targetfrom '$targetfrom'" >&4
0f00356b
JH
383 exit 1
384 ;;
385 esac
04c4183c
JH
386 if $test ! -f $run; then
387 echo "Target 'run' script '$run' not found." >&4
0f00356b 388 else
a65d8156 389 $chmod a+rx $run
0f00356b 390 fi
04c4183c
JH
391 if $test ! -f $to; then
392 echo "Target 'to' script '$to' not found." >&4
0f00356b 393 else
a65d8156 394 $chmod a+rx $to
0f00356b 395 fi
04c4183c
JH
396 if $test ! -f $from; then
397 echo "Target 'from' script '$from' not found." >&4
0f00356b 398 else
a65d8156 399 $chmod a+rx $from
0f00356b 400 fi
04c4183c 401 if $test ! -f $run -o ! -f $to -o ! -f $from; then
0f00356b
JH
402 exit 1
403 fi
404 cat >&4 <<EOF
a65d8156
JH
405Using '$run' for remote execution,
406and '$from' and '$to'
04c4183c 407for remote file transfer.
0f00356b
JH
408EOF
409 ;;
410*) run=''
411 to=:
412 from=:
76d1bd01 413 usecrosscompile="$undef"
0f00356b
JH
414 targetarch=''
415 ;;
416esac
417