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
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:
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
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:.
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:.
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:.
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:.
90 ?H:?%<:#ifndef USE_CROSS_COMPILE
91 ?H:?%<:#$usecrosscompile        USE_CROSS_COMPILE       /**/
92 ?H:?%<:#define  PERL_TARGETARCH "$targetarch"   /**/
93 ?H:?%<:#endif
94 ?H:.
95 ?D:targetenv=''
96 ?D:targethost=''
97 ?D:targetmkdir=''
98 ?T:croak pwd exe f q cwd file xxx env
99 ?LINT:extern usecrosscompile
100 ?LINT:extern cc
101 ?LINT:extern usrinc
102 ?LINT:change ar
103 ?LINT:change nm
104 ?LINT:change ranlib
105 ?LINT:change src
106 ?LINT:extern targetenv
107 ?LINT:extern targetport
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
117 ?LINT:extern incpth
118 ?LINT:extern libpth
119 ?LINT:extern locincpth
120 ?LINT:extern loclibpth
121 ?LINT:change locincpth
122 ?LINT:change loclibpth
123 ?LINT:extern hostperl
124 ?LINT:extern hostgenerate
125 ?LINT:extern before_host
126 ?LINT:change before_host
127 ?LINT:extern hostosname
128 ?LINT:extern multiarch
129 : Check for Cross-Compilation
130 ?X: targethost and targetenv mainly set to allow ?S: documentation
131 ?X:otherwise it could have been declared extern
132 if $test "X$targethost" = "X"; then
133     targethost=""
134 fi
135 if $test "X$targetenv" = "X"; then
136     targetenv=""
137 fi
138 case "$usecrosscompile" in
139 $define|true|[yY]*)
140         $echo "Cross-compiling..."
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/'`
148             # leave out ld, choosing it is more complex
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         ;;
163         esac
164         case "$targetarch" in
165         '') echo "Targetarch not defined." >&4; croak=y ;;
166         *)  echo "Using targetarch $targetarch." >&4 ;;
167         esac
168         case "$targethost" in
169         '') echo "Targethost not defined." >&4; croak=n ;;
170         *)  echo "Using targethost $targethost." >&4
171         esac
172         locincpth=' '
173         loclibpth=' '
174         case "$croak" in
175         y) echo "Cannot continue, aborting." >&4; exit 1 ;;
176         esac
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     ;;
204 esac
205
206 : Define -Dtargethost=somecomputer to run compiled tests on another machine
207 case "$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
227         case "$src" in
228         /*) run=$src/Cross/run
229             targetmkdir=$src/Cross/mkdir
230             to=$src/Cross/to
231             from=$src/Cross/from
232             ;;
233         *)  pwd=`$test -f ../Configure & cd ..; pwd`
234             run=$pwd/Cross/run
235             targetmkdir=$pwd/Cross/mkdir
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
249         run=$run-$targetrun
250         to=$to-$targetto
251         from=$from-$targetfrom
252         case "$targetdir" in
253         '')  targetdir=/tmp
254              echo "Guessing targetdir $targetdir." >&4
255              ;;
256         esac
257         case "$targetuser" in
258         '')  targetuser=root
259              echo "Guessing targetuser $targetuser." >&4
260              ;;
261         esac
262         case "$targetport" in
263         '')  targetport=22
264              echo "Guessing targetport $targetport." >&4
265              ;;
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
275 env=''
276 case "\$1" in
277 -cwd)
278   shift
279   cwd=\$1
280   shift
281   ;;
282 esac
283 case "\$1" in
284 -env)
285   shift
286   env=\$1
287   shift
288   ;;
289 esac
290 case "\$cwd" in
291 '') cwd=$targetdir ;;
292 esac
293 exe=\$1
294 shift
295 $to \$exe
296 $targetrun -p $targetport -l $targetuser $targethost "cd \$cwd && \$env \$exe \$@"
297 EOF
298             ;;
299         adb)
300             $touch $run
301             ;;
302         *)  echo "Unknown targetrun '$targetrun'" >&4
303             exit 1
304             ;;
305         esac
306         case "$targetmkdir" in
307         */Cross/mkdir)
308             cat >$targetmkdir <<EOF
309 #!/bin/sh
310 $targetrun -p $targetport -l $targetuser $targethost "mkdir -p \$@"
311 EOF
312             $chmod a+rx $targetmkdir
313             ;;
314         *)  echo "Unknown targetmkdir '$targetmkdir'" >&4
315             exit 1
316             ;;
317         esac
318         case "$targetto" in
319         scp|rcp)
320             cat >$to <<EOF
321 #!/bin/sh
322 for f in \$@
323 do
324   case "\$f" in
325   /*)
326     $targetmkdir \`dirname \$f\`
327     $targetto -P $targetport -r $q \$f $targetuser@$targethost:\$f           2>/dev/null  || exit 1
328     ;;
329   *)
330     $targetmkdir $targetdir/\`dirname \$f\`
331     $targetto -P $targetport -r $q \$f $targetuser@$targethost:$targetdir/\$f 2>/dev/null || exit 1
332     ;;
333   esac
334 done
335 exit 0
336 EOF
337             ;;
338         cp) cat >$to <<EOF
339 #!/bin/sh
340 for f in \$@
341 do
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
352 done
353 exit 0
354 EOF
355             ;;
356         *)  echo "Unknown targetto '$targetto'" >&4
357             exit 1
358             ;;
359         esac
360         case "$targetfrom" in
361         scp|rcp)
362           cat >$from <<EOF
363 #!/bin/sh
364 for f in \$@
365 do
366   $rm -f \$f
367   $targetfrom -P $targetport $q $targetuser@$targethost:$targetdir/\$f . || exit 1
368 done
369 exit 0
370 EOF
371             ;;
372         cp) cat >$from <<EOF
373 #!/bin/sh
374 for f in \$@
375 do
376   $rm -f \$f
377   cp $targetdir/\$f . || exit 1
378 done
379 exit 0
380 EOF
381             ;;
382         *)  echo "Unknown targetfrom '$targetfrom'" >&4
383             exit 1
384             ;;
385         esac
386         if $test ! -f $run; then
387             echo "Target 'run' script '$run' not found." >&4
388         else
389             $chmod a+rx $run
390         fi
391         if $test ! -f $to; then
392             echo "Target 'to' script '$to' not found." >&4
393         else
394             $chmod a+rx $to
395         fi
396         if $test ! -f $from; then
397             echo "Target 'from' script '$from' not found." >&4
398         else
399             $chmod a+rx $from
400         fi
401         if $test ! -f $run -o ! -f $to -o ! -f $from; then
402             exit 1
403         fi
404         cat >&4 <<EOF
405 Using '$run' for remote execution,
406 and '$from' and '$to'
407 for remote file transfer.
408 EOF
409         ;;
410 *)      run=''
411         to=:
412         from=:
413         usecrosscompile="$undef"
414         targetarch=''
415         ;;
416 esac
417