This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Part 2 of a big cleanup action based on the upcoming dist-4.0
[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 usecrosscompile: src awk grep test rm \
9         echo sed mkdir cp touch chmod
10 ?MAKE:  -pick add $@ %<
11 ?Y:TOP
12 ?S:usecrosscompile:
13 ?S:     This variable conditionally defines the USE_CROSS_COMPILE symbol,
14 ?S:     and indicates that Perl has been cross-compiled.
15 ?S:.
16 ?S:run:
17 ?S:     This variable contains the command used by Configure
18 ?S:     to copy and execute a cross-compiled executable in the
19 ?S:     target host.  Useful and available only during Perl build.
20 ?S:     Empty string '' if not cross-compiling.
21 ?S:.
22 ?S:from:
23 ?S:     This variable contains the command used by Configure
24 ?S:     to copy files from the target host.  Useful and available
25 ?S:     only during Perl build.
26 ?S:     The string ':' if not cross-compiling.
27 ?S:.
28 ?S:to:
29 ?S:     This variable contains the command used by Configure
30 ?S:     to copy to from the target host.  Useful and available
31 ?S:     only during Perl build.
32 ?S:     The string ':' if not cross-compiling.
33 ?S:.
34 ?S:targetarch:
35 ?S:     If cross-compiling, this variable contains the target architecture.
36 ?S:     If not, this will be empty.
37 ?S:.
38 ?C:USE_CROSS_COMPILE:
39 ?C:     This symbol, if defined, indicates that Perl is being cross-compiled.
40 ?C:.
41 ?C:PERL_TARGETARCH:
42 ?C:     This symbol, if defined, indicates the target architecture
43 ?C:     Perl has been cross-compiled to.  Undefined if not a cross-compile.
44 ?C:.
45 ?H:?%<:#ifndef USE_CROSS_COMPILE
46 ?H:?%<:#$usecrosscompile        USE_CROSS_COMPILE       /**/
47 ?H:?%<:#define  PERL_TARGETARCH "$targetarch"   /**/
48 ?H:?%<:#endif
49 ?H:.
50 ?T:croak pwd exe f q i j cwd
51 ?LINT:extern usecrosscompile
52 ?LINT:extern cc
53 ?LINT:extern usrinc
54 ?LINT:change usrinc
55 ?LINT:change ar
56 ?LINT:change nm
57 ?LINT:change ranlib
58 ?LINT:extern targethost
59 ?LINT:extern targetdir
60 ?LINT:change targetdir
61 ?LINT:extern targetuser
62 ?LINT:change targetuser
63 ?LINT:extern targetrun
64 ?LINT:extern targetfrom
65 ?LINT:extern targetto
66 ?LINT:extern targetmkdir
67 ?LINT:change targetrun
68 ?LINT:change targetfrom
69 ?LINT:change targetto
70 ?LINT:change targetmkdir
71 ?LINT:extern incpth
72 ?LINT:extern libpth
73 ?LINT:change incpth
74 ?LINT:change libpth
75 ?LINT:extern locincpth
76 ?LINT:extern loclibpth
77 ?LINT:change locincpth
78 ?LINT:change loclibpth
79 : Check for Cross-Compilation
80 case "$usecrosscompile" in
81 $define|true|[yY]*)
82         $echo "Cross-compiling..."
83         croak=''
84         case "$cc" in
85         *-*-gcc) # A cross-compiling gcc, probably.
86             targetarch=`$echo $cc|$sed 's/-gcc$//'`
87             ar=$targetarch-ar
88             # leave out ld, choosing it is more complex
89             nm=$targetarch-nm
90             ranlib=$targetarch-ranlib
91             $echo 'extern int foo;' > try.c
92             set X `$cc -v -E try.c 2>&1 | $awk '/^#include </,/^End of search /'|$grep '/include'`
93             shift
94             if $test $# -gt 0; then
95                 incpth="$incpth $*"
96                 incpth="`$echo $incpth|$sed 's/^ //'`"
97                 echo "Guessing incpth '$incpth'." >&4
98                 for i in $*; do
99                     j="`$echo $i|$sed 's,/include$,/lib,'`"
100                     if $test -d $j; then
101                         libpth="$libpth $j"
102                     fi
103                 done   
104                 libpth="`$echo $libpth|$sed 's/^ //'`"
105                 echo "Guessing libpth '$libpth'." >&4
106             fi
107             $rm -f try.c
108             ;;
109         esac
110         case "$targetarch" in
111         '') echo "Targetarch not defined." >&4; croak=y ;;
112         *)  echo "Using targetarch $targetarch." >&4 ;;
113         esac
114         case "$incpth" in
115         '') echo "Incpth not defined." >&4; croak=y ;;
116         *)  echo "Using incpth '$incpth'." >&4 ;;
117         esac
118         case "$libpth" in
119         '') echo "Libpth not defined." >&4; croak=y ;;
120         *)  echo "Using libpth '$libpth'." >&4 ;;
121         esac
122         case "$usrinc" in
123         '') for i in $incpth; do
124                 if $test -f $i/errno.h -a -f $i/stdio.h -a -f $i/time.h; then
125                     usrinc=$i
126                     echo "Guessing usrinc $usrinc." >&4
127                     break
128                 fi
129             done
130             case "$usrinc" in
131             '') echo "Usrinc not defined." >&4; croak=y ;;
132             esac
133             ;;
134         *)  echo "Using usrinc $usrinc." >&4 ;;
135         esac
136         case "$targethost" in
137         '') echo "Targethost not defined." >&4; croak=y ;;
138         *)  echo "Using targethost $targethost." >&4
139         esac
140         locincpth=' '
141         loclibpth=' '
142         case "$croak" in
143         y) echo "Cannot continue, aborting." >&4; exit 1 ;;
144         esac
145         case "$src" in
146         /*) run=$src/Cross/run
147             targetmkdir=$src/Cross/mkdir
148             to=$src/Cross/to
149             from=$src/Cross/from
150             ;;
151         *)  pwd=`$test -f ../Configure & cd ..; pwd`
152             run=$pwd/Cross/run
153             targetmkdir=$pwd/Cross/mkdir
154             to=$pwd/Cross/to
155             from=$pwd/Cross/from
156             ;;
157         esac
158         case "$targetrun" in
159         '') targetrun=ssh ;;
160         esac
161         case "$targetto" in
162         '') targetto=scp ;;
163         esac
164         case "$targetfrom" in
165         '') targetfrom=scp ;;
166         esac
167         run=$run-$targetrun
168         to=$to-$targetto
169         from=$from-$targetfrom
170         case "$targetdir" in
171         '')  targetdir=/tmp
172              echo "Guessing targetdir $targetdir." >&4
173              ;;
174         esac
175         case "$targetuser" in
176         '')  targetuser=root
177              echo "Guessing targetuser $targetuser." >&4
178              ;;
179         esac
180         case "$targetfrom" in
181         scp)    q=-q ;;
182         *)      q='' ;;
183         esac
184         case "$targetrun" in
185         ssh|rsh)
186             cat >$run <<EOF
187 #!/bin/sh
188 case "\$1" in
189 -cwd)
190   shift
191   cwd=\$1
192   shift
193   ;;
194 esac
195 case "\$cwd" in
196 '') cwd=$targetdir ;;
197 esac
198 exe=\$1
199 shift
200 if $test ! -f \$exe.xok; then
201   $to \$exe
202   $touch \$exe.xok
203 fi
204 $targetrun -l $targetuser $targethost "cd \$cwd && ./\$exe \$@"
205 EOF
206             ;;
207         *)  echo "Unknown targetrun '$targetrun'" >&4
208             exit 1
209             ;;
210         esac
211         case "$targetmkdir" in
212         */Cross/mkdir)
213             cat >$targetmkdir <<EOF
214 #!/bin/sh
215 $targetrun -l $targetuser $targethost "mkdir -p \$@"
216 EOF
217             $chmod a+rx $targetmkdir
218             ;;
219         *)  echo "Unknown targetmkdir '$targetmkdir'" >&4
220             exit 1
221             ;;
222         esac
223         case "$targetto" in
224         scp|rcp)
225             cat >$to <<EOF
226 #!/bin/sh
227 for f in \$@
228 do
229   case "\$f" in
230   /*)
231     $targetmkdir \`dirname \$f\`
232     $targetto $q \$f $targetuser@$targethost:\$f            || exit 1
233     ;;
234   *)
235     $targetmkdir $targetdir/\`dirname \$f\`
236     $targetto $q \$f $targetuser@$targethost:$targetdir/\$f || exit 1
237     ;;
238   esac
239 done
240 exit 0
241 EOF
242             ;;
243         cp) cat >$to <<EOF
244 #!/bin/sh
245 for f in \$@
246 do
247   case "\$f" in
248   /*)
249     $mkdir -p $targetdir/\`dirname \$f\`
250     $cp \$f $targetdir/\$f || exit 1
251     ;;
252   *)
253     $targetmkdir $targetdir/\`dirname \$f\`
254     $cp \$f $targetdir/\$f || exit 1
255     ;;
256   esac
257 done
258 exit 0
259 EOF
260             ;;
261         *)  echo "Unknown targetto '$targetto'" >&4
262             exit 1
263             ;;
264         esac
265         case "$targetfrom" in
266         scp|rcp)
267           cat >$from <<EOF
268 #!/bin/sh
269 for f in \$@
270 do
271   $rm -f \$f
272   $targetfrom $q $targetuser@$targethost:$targetdir/\$f . || exit 1
273 done
274 exit 0
275 EOF
276             ;;
277         cp) cat >$from <<EOF
278 #!/bin/sh
279 for f in \$@
280 do
281   $rm -f \$f
282   cp $targetdir/\$f . || exit 1
283 done
284 exit 0
285 EOF
286             ;;
287         *)  echo "Unknown targetfrom '$targetfrom'" >&4
288             exit 1
289             ;;
290         esac
291         if $test ! -f $run; then
292             echo "Target 'run' script '$run' not found." >&4
293         else
294             $chmod a+rx $run
295         fi
296         if $test ! -f $to; then
297             echo "Target 'to' script '$to' not found." >&4
298         else
299             $chmod a+rx $to
300         fi
301         if $test ! -f $from; then
302             echo "Target 'from' script '$from' not found." >&4
303         else
304             $chmod a+rx $from
305         fi
306         if $test ! -f $run -o ! -f $to -o ! -f $from; then
307             exit 1
308         fi
309         cat >&4 <<EOF
310 Using '$run' for remote execution,
311 and '$from' and '$to'
312 for remote file transfer.
313 EOF
314         ;;
315 *)      run=''
316         to=:
317         from=:
318         usecrosscompile='undef'
319         targetarch=''
320         ;;
321 esac
322