Regenerate META.yml
[p5sagit/p5-mst-13.2.git] / hints / catamount.sh
CommitLineData
9c12f1e5 1#
2# Hints for the Cray XT4 Catamount/Qk system:
3# cross-compilation host is a SuSE x86_64-linux,
4# execution at the target with the 'yod' utility,
5# linux.sh will run this hints file when necessary.
6#
7# cc.sh: compiles the code with the cross-compiler, patches main/exit/_exit
8# (and traps signals) to be wrappers that echo the exit code.
9#
10# run.sh: runs the executable with yod and collects the exit status,
11# and exits with that status.
12#
13# You probably should do the compilation in non-Lustre filesystem
14# because Lustre does not support all the POSIX system calls, which may
15# cause weird errors during the Perl build:
16# 1182003549.604836:3-24:(super.c:1516:llu_iop_fcntl()): unsupported fcntl cmd 2
17#
6d4b7d88 18# As of 2007-Sep (pre-5.10) miniperl, libperl.a, and perl can be successfully
19# built; no extensions are built. It would be hard since Perl cannot run
20# anything external (pipes, system(), backticks or fork/exec, or globbing)
21# (which breaks MakeMaker, and confuses ext/util/make_ext).
9c12f1e5 22#
6d4b7d88 23# To build:
9c12f1e5 24#
25# sh Configure -des -Dusedevel
6d4b7d88 26# make perl
9c12f1e5 27#
6d4b7d88 28# The -Dusedevel is required for Perl 5.9, it is not required for the Perl
29# 5.10 sources, once they come out. "make install" won't work since it
30# assumes file globbing (see above). You can try the following manually:
9c12f1e5 31#
6d4b7d88 32# mkdir -p /opt/perl-catamount
33# mkdir -p /opt/perl-catamount/include
34# mkdir -p /opt/perl-catamount/lib
35# mkdir -p /opt/perl-catamount/lib/perl5/5.9.5
36# mkdir -p /opt/perl-catamount/bin
37# cp *.h /opt/perl-catamount/include
38# cp libperl.a /opt/perl-catamount/lib
39# cp -pr lib/* /opt/perl-catamount/lib/perl5/5.9.5
40# cp miniperl perl run.sh cc.sh /opt/perl-catamount/lib
41#
42# (For Perl 5.10.0 do the obvious renaming above.)
43# With the headers and the libperl.a you can embed Perl to your Catamount
44# application, see pod/perlembed.pod. You can do for example:
45#
46# cc -I/opt/perl-catamount/include -L/opt/perl-catamount/lib -o embed embed.c
47# yod -sz 1 ./embed -le 'print sqrt(2)'
48#
49# You might want to have the run.sh execution wrapper around (it gets created
50# in the Perl build directory) if you want to run the miniperl or perl in
51# the XT4. It collects the exit status (note that yod is run with "-sz 1",
52# so only one instance is run), and possible crash status (bare yod does
53# not collect the exit status). For example:
54#
55# sh /opt/perl-catamount/bin/run.sh /opt/perl-catamount/bin/perl -le 'print 42'
56#
57# or if you are still in the build directory:
58#
59# sh run.sh ./perl -le 'print 2*3*7'
60#
61# The cc.sh is a wrapper for the Catamount cc used when building Perl
62# (and before that, when running Configure), it arranges for the main()
63# exit(), _exit() to be wrapped so that the exit/crash status can be
64# collected (by run.sh).
9c12f1e5 65#
66
67case "$prefix" in
68'') prefix=/opt/perl-catamount ;;
69esac
70cat >&4 <<__EOF1__
71***
72*** You seem to be compiling in Linux for the Catamount/Qk environment.
73*** I'm therefore not going to install perl as /usr/bin/perl.
74*** Perl will be installed under $prefix.
75***
76__EOF1__
77
78archname='x86_64-catamount'
6d4b7d88 79archobjs='catalib.o'
9c12f1e5 80d_mmap='undef'
81d_setlocale='undef' # There is setlocale() but no locales.
82d_vprintf='define'
83hintfile='catamount'
84i_arpainet='undef'
85i_db='undef'
86i_netdb='undef'
87i_niin='undef'
88incpth=' '
89installusrbinperl='undef'
90libswanted="m crypt c"
91libpth=' '
6d4b7d88 92locincpth=' '
93nonxs_ext=' '
9c12f1e5 94osname='catamount'
95procselfexe='undef'
6d4b7d88 96static_ext=' '
9c12f1e5 97usedl='undef'
98useithreads='undef'
99uselargefiles='define'
100usenm='undef'
101usethreads='undef'
102use64bitall='define'
103
104BUILD=$PWD
105
106case "`yod -Version 2>&1`" in
107Red*) ;; # E.g. "Red Storm Protocol Release 2.1.0"
108*) echo >&4 "Could not find 'yod', aborting."
109 exit 1 ;;
110esac
111run=$BUILD/run.sh
112cat > $run <<'__EOF2__'
113#!/bin/sh
114#
115# $run
116#
117yod -sz 1 "$@" 2> .yod$$e > .yod$$o
118status=`awk '/^cata: exe .* pid [0-9][0-9]* (main|exit|_exit) [0-9][0-9]*$/ {print $NF}' .yod$$o|tail -1`
119grep -v "sz is 1" .yod$$e
120grep -v "^cata: exe .* pid [0-9][0-9]* " .yod$$o
121grep "^cata: exe .* signal " .yod$$o
122rm -f .yod$$o .yod$$e
123exit $status
124__EOF2__
125chmod 755 $run
126case "`cc -V 2>&1`" in
127*catamount*) ;; # E.g. "/opt/xt-pe/1.5.41/bin/snos64/cc: INFO: catamount target is being used"
128*) echo "Could not find 'cc' for catamount, aborting."
129 exit 1 ;;
130esac
131
132cc=$BUILD/cc.sh
133cat > $cc <<__EOF3a__
134#!/bin/sh
135#
136# $0
137#
138# This is essentially a frontend driver for the Catamount cc.
139# We arrange for (1) the main(), exit(), _exit() being wrapped (cpp-defined)
140# catamain(), cataexit(), and _cataexit() (2) the actual main() etc. are in
6d4b7d88 141# cata.c, and cata*.o are linked in when needed (3) signals being caught
9c12f1e5 142# All this mostly for being able to catch the exit status (or crash cause).
143#
144argv=''
145srco=''
146srct=''
147exe=''
148defs='-Dmain=catamain -Dexit=cataexit -D_exit=_cataexit'
149argv=''
150BUILD=/wrk/jhi/perl-5.9.x@31393+cata
151__EOF3a__
152cat >> $cc <<'__EOF3b__'
153case "$1" in
154--cata_o) ;;
6d4b7d88 155*) if test ! -f catalib.o
9c12f1e5 156 then
6d4b7d88 157 if test ! -f catalib.c
9c12f1e5 158 then
6d4b7d88 159 if test -f ../catalib.c # If compiling in UU during Configure.
9c12f1e5 160 then
6d4b7d88 161 cp ../catalib.c catalib.c
162 cp ../catamain.c catamain.c
9c12f1e5 163 cp ../cata.h cata.h
164 fi
165 fi
6d4b7d88 166 $0 --cata_o -c catalib.c || exit 1
167 $0 --cata_o -c catamain.c || exit 1
9c12f1e5 168 fi
169 ;;
170esac
171while test $# -ne 0
172do
173 i=$1
174 shift
175 case "$i" in
176 --cata_o) ;;
177 *.c)
178 argv="$argv $defs"
179 defs=""
180 if test ! -f $i
181 then
182 echo "$0: $i: No such file or directory"
183 exit 1
184 fi
185 j=$i$$.c
186 rm -f $j
187 if grep -q -s '#include "cata.h"' $i
188 then
189 :
190 else
191 cat >>$j<<__EOF4__
192#include "cata.h"
193# 1 "$i"
194__EOF4__
195 fi
196 cat $i >>$j
197 if grep -q -s 'int main()' $i
198 then
199 argv="$argv -Dmain0"
200 else
201 if grep -q -s 'int main([^,]*,[^,]*)' $i
202 then
203 argv="$argv -Dmain2"
204 else
205 if grep -q -s 'int main([^,]*,[^,]*,[^,]*)' $i
206 then
207 argv="$argv -Dmain3"
208 fi
209 fi
210 fi
211 argv="$argv $j"
212 srct="$j"
213 srco="$i"
214 ;;
215 *.o)
216 if test ! -f "$i"
217 then
218 c=$(echo $i|sed 's/\.o$/.c/')
219 $0 -c $c || exit 1
220 fi
221 argv="$argv $i"
222 ;;
223 -o)
224 exe="$1"
225 argv="$argv -o $exe -Dargv0=$exe"
226 shift
227 ;;
228 *)
229 argv="$argv $i"
230 ;;
231 esac
232done
233case "$exe" in
234'') ;;
235*) case "$argv" in
6d4b7d88 236 *catalib.o*|*" perlmain.o "*) ;;
237 *) argv="$argv catalib.o" ;;
238 esac
239 case "$argv" in
240 *catamain.o*) ;;
241 *) argv="$argv catamain.o" ;;
9c12f1e5 242 esac
243 ;;
244esac
245cc -I$BUILD $argv 2> .cc$$e > .cc$$o
246status=$?
247egrep -v 'catamount target|'$$'\.c:$' .cc$$e 1>&2
248case "`grep "is not implemented" .cc$$e`" in
249*"will always fail"*) status=1 ;;
250esac
251cat .cc$$o
252rm -f .cc$$o
253case "$status" in
2540) rm -f .cc$$e $srct
255 ;;
256esac
257objt=`echo $srct|sed -e 's/\.c$/.o/'`
258objo=`echo $srco|sed -e 's/\.c$/.o/'`
259if test -n "$objt" -a -f "$objt"
260then
261 mv -f $objt $objo
262fi
263exit $status
264__EOF3b__
265chmod 755 $cc
266
267cat >cata.h<<__EOF6__
268#ifndef CATA_H
269#define CATA_H
270void cataexit(int status);
271void _cataexit(int status);
272void catasigsetup();
273void catasighandle(int signum);
274#ifdef main0
275int catamain();
276#else
277#ifdef main2
278int main(int argc, char **argv);
279#else
280int main(int argc, char **argv, char **env);
281#endif
282#endif
283#endif
6d4b7d88 284#ifdef argv0
285#define ARGV0 STRINGIFY(argv0)
286#else
287#define ARGV0 argv0
288#endif
9c12f1e5 289__EOF6__
290
6d4b7d88 291cat >catalib.c<<__EOF7__
9c12f1e5 292#include <stdio.h>
293#include <signal.h>
294#undef printf
295#undef main
296#undef exit
297#undef _exit
298#include "cata.h"
6d4b7d88 299char* argv0;
9c12f1e5 300void cataexit(int status) {
301 printf("cata: exe %s pid %d exit %d\n", ARGV0, getpid(), status);
302 exit(status);
303}
304void _cataexit(int status) {
305 printf("cata: exe %s pid %d _exit %d\n", ARGV0, getpid(), status);
306 _exit(status);
307}
308void catasighandle(int signum) {
309 int core = 0;
310 printf("cata: exe %s pid %d signal %d\n", ARGV0, getpid(), signum);
311 switch (signum) {
312 case SIGQUIT:
313 case SIGILL:
314 case SIGTRAP:
315 case SIGABRT:
316 case SIGBUS:
317 case SIGSEGV:
318 case SIGXCPU:
319 case SIGXFSZ:
320 core = 0200;
321 break;
322 default:
323 break;
324 }
325 cataexit(core << 8 | signum);
326}
327void catasigsetup() {
328 signal(SIGHUP, catasighandle);
329 signal(SIGINT, catasighandle);
330 signal(SIGQUIT, catasighandle);
331 signal(SIGILL, catasighandle);
332 signal(SIGTRAP, catasighandle);
333 signal(SIGABRT, catasighandle);
334 signal(SIGIOT, catasighandle);
335 /* KILL */
336 signal(SIGBUS, catasighandle);
337 signal(SIGFPE, catasighandle);
338 signal(SIGUSR1, catasighandle);
339 signal(SIGUSR2, catasighandle);
340 signal(SIGSEGV, catasighandle);
341 signal(SIGPIPE, catasighandle);
342 signal(SIGALRM, catasighandle);
343 signal(SIGTERM, catasighandle);
344 signal(SIGSTKFLT, catasighandle);
345 signal(SIGCHLD, catasighandle);
346 signal(SIGCONT, catasighandle);
347 /* STOP */
348 signal(SIGTSTP, catasighandle);
349 signal(SIGTTIN, catasighandle);
350 signal(SIGTTOU, catasighandle);
351 signal(SIGURG, catasighandle);
352 signal(SIGXCPU, catasighandle);
353 signal(SIGXFSZ, catasighandle);
354 signal(SIGVTALRM, catasighandle);
355 signal(SIGPROF, catasighandle);
356 signal(SIGWINCH, catasighandle);
357 signal(SIGIO, catasighandle);
358 signal(SIGPWR, catasighandle);
359 signal(SIGSYS, catasighandle);
360}
6d4b7d88 361void boot_DynaLoader (void* cv) { }
362__EOF7__
363cat >catamain.c<<__EOF8__
364#include <stdio.h>
365#undef printf
366#undef main
367#undef exit
368#undef _exit
369#include "cata.h"
370extern char* argv0;
9c12f1e5 371int main(int argc, char *argv[], char *envv[]) {
372 int status;
373#ifndef argv0
374 argv0 = argv[0];
375#endif
376 catasigsetup();
377 status =
378#ifdef main0
379 catamain();
380#else
381#ifdef main2
382 catamain(argc, argv);
383#else
384 catamain(argc, argv, envv);
385#endif
386#endif
387 printf("cata: exe %s pid %d main %d\n", ARGV0, getpid(), status);
388 return status;
389}
6d4b7d88 390__EOF8__
9c12f1e5 391
392echo "Faking DynaLoader"
393touch DynaLoader.o # Oh, the agony.
394
395# That's it.