This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: [patch] perlhack.pod
[perl5.git] / hints / catamount.sh
CommitLineData
9c12f1e5
RGS
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#
18# As of 2007-Jun (pre-5.9.5) miniperl and libperl.a can be successfully built;
19# building any extensions would be hard since Perl cannot run anything
20# external (which breaks MakeMaker, and confuses ext/util/make_ext).
21#
22# To build libperl.a (which also gets miniperl built):
23#
24# sh Configure -des -Dusedevel
25# make libperl.a
26#
27# The -Dusedevel is required for Perl 5.9, it is not required for Perl 5.10
28# sources, once they come out. You will need to have the run.sh execution
29# wrapper around (it gets created in the Perl build directory) if you want to
30# run the miniperl in the XT4. It collects the exit status (note that yod
31# is run with "-sz 1", so only one instance is run), and possible crash status.
32# For example:
33#
34# sh run.sh ./miniperl -le 'print 42'
35#
36
37case "$prefix" in
38'') prefix=/opt/perl-catamount ;;
39esac
40cat >&4 <<__EOF1__
41***
42*** You seem to be compiling in Linux for the Catamount/Qk environment.
43*** I'm therefore not going to install perl as /usr/bin/perl.
44*** Perl will be installed under $prefix.
45***
46__EOF1__
47
48archname='x86_64-catamount'
49archobjs='cata.o'
50d_mmap='undef'
51d_setlocale='undef' # There is setlocale() but no locales.
52d_vprintf='define'
53hintfile='catamount'
54i_arpainet='undef'
55i_db='undef'
56i_netdb='undef'
57i_niin='undef'
58incpth=' '
59installusrbinperl='undef'
60libswanted="m crypt c"
61libpth=' '
62locincpth=''
63onlyextensions='Fcntl' # Not that we can build this, really.
64osname='catamount'
65procselfexe='undef'
66usedl='undef'
67useithreads='undef'
68uselargefiles='define'
69usenm='undef'
70usethreads='undef'
71use64bitall='define'
72
73BUILD=$PWD
74
75case "`yod -Version 2>&1`" in
76Red*) ;; # E.g. "Red Storm Protocol Release 2.1.0"
77*) echo >&4 "Could not find 'yod', aborting."
78 exit 1 ;;
79esac
80run=$BUILD/run.sh
81cat > $run <<'__EOF2__'
82#!/bin/sh
83#
84# $run
85#
86yod -sz 1 "$@" 2> .yod$$e > .yod$$o
87status=`awk '/^cata: exe .* pid [0-9][0-9]* (main|exit|_exit) [0-9][0-9]*$/ {print $NF}' .yod$$o|tail -1`
88grep -v "sz is 1" .yod$$e
89grep -v "^cata: exe .* pid [0-9][0-9]* " .yod$$o
90grep "^cata: exe .* signal " .yod$$o
91rm -f .yod$$o .yod$$e
92exit $status
93__EOF2__
94chmod 755 $run
95case "`cc -V 2>&1`" in
96*catamount*) ;; # E.g. "/opt/xt-pe/1.5.41/bin/snos64/cc: INFO: catamount target is being used"
97*) echo "Could not find 'cc' for catamount, aborting."
98 exit 1 ;;
99esac
100
101cc=$BUILD/cc.sh
102cat > $cc <<__EOF3a__
103#!/bin/sh
104#
105# $0
106#
107# This is essentially a frontend driver for the Catamount cc.
108# We arrange for (1) the main(), exit(), _exit() being wrapped (cpp-defined)
109# catamain(), cataexit(), and _cataexit() (2) the actual main() etc. are in
110# cata.c, and cata.o is linked in when needed (3) signals being caught
111# All this mostly for being able to catch the exit status (or crash cause).
112#
113argv=''
114srco=''
115srct=''
116exe=''
117defs='-Dmain=catamain -Dexit=cataexit -D_exit=_cataexit'
118argv=''
119BUILD=/wrk/jhi/perl-5.9.x@31393+cata
120__EOF3a__
121cat >> $cc <<'__EOF3b__'
122case "$1" in
123--cata_o) ;;
124*) if test ! -f cata.o
125 then
126 if test ! -f cata.c
127 then
128 if test -f ../cata.c # If compiling in UU during Configure.
129 then
130 cp ../cata.c cata.c
131 cp ../cata.h cata.h
132 fi
133 fi
134 $0 --cata_o -c cata.c || exit 1
135 fi
136 ;;
137esac
138while test $# -ne 0
139do
140 i=$1
141 shift
142 case "$i" in
143 --cata_o) ;;
144 *.c)
145 argv="$argv $defs"
146 defs=""
147 if test ! -f $i
148 then
149 echo "$0: $i: No such file or directory"
150 exit 1
151 fi
152 j=$i$$.c
153 rm -f $j
154 if grep -q -s '#include "cata.h"' $i
155 then
156 :
157 else
158 cat >>$j<<__EOF4__
159#include "cata.h"
160# 1 "$i"
161__EOF4__
162 fi
163 cat $i >>$j
164 if grep -q -s 'int main()' $i
165 then
166 argv="$argv -Dmain0"
167 else
168 if grep -q -s 'int main([^,]*,[^,]*)' $i
169 then
170 argv="$argv -Dmain2"
171 else
172 if grep -q -s 'int main([^,]*,[^,]*,[^,]*)' $i
173 then
174 argv="$argv -Dmain3"
175 fi
176 fi
177 fi
178 argv="$argv $j"
179 srct="$j"
180 srco="$i"
181 ;;
182 *.o)
183 if test ! -f "$i"
184 then
185 c=$(echo $i|sed 's/\.o$/.c/')
186 $0 -c $c || exit 1
187 fi
188 argv="$argv $i"
189 ;;
190 -o)
191 exe="$1"
192 argv="$argv -o $exe -Dargv0=$exe"
193 shift
194 ;;
195 *)
196 argv="$argv $i"
197 ;;
198 esac
199done
200case "$exe" in
201'') ;;
202*) case "$argv" in
203 *cata.o*) ;;
204 *) argv="$argv cata.o" ;;
205 esac
206 ;;
207esac
208cc -I$BUILD $argv 2> .cc$$e > .cc$$o
209status=$?
210egrep -v 'catamount target|'$$'\.c:$' .cc$$e 1>&2
211case "`grep "is not implemented" .cc$$e`" in
212*"will always fail"*) status=1 ;;
213esac
214cat .cc$$o
215rm -f .cc$$o
216case "$status" in
2170) rm -f .cc$$e $srct
218 ;;
219esac
220objt=`echo $srct|sed -e 's/\.c$/.o/'`
221objo=`echo $srco|sed -e 's/\.c$/.o/'`
222if test -n "$objt" -a -f "$objt"
223then
224 mv -f $objt $objo
225fi
226exit $status
227__EOF3b__
228chmod 755 $cc
229
230cat >cata.h<<__EOF6__
231#ifndef CATA_H
232#define CATA_H
233void cataexit(int status);
234void _cataexit(int status);
235void catasigsetup();
236void catasighandle(int signum);
237#ifdef main0
238int catamain();
239#else
240#ifdef main2
241int main(int argc, char **argv);
242#else
243int main(int argc, char **argv, char **env);
244#endif
245#endif
246#endif
247__EOF6__
248
249cat >cata.c<<__EOF7__
250#include <stdio.h>
251#include <signal.h>
252#undef printf
253#undef main
254#undef exit
255#undef _exit
256#include "cata.h"
257#ifndef STRINGIFY
258#define STRINGIFY(a) #a
259#endif
260#ifdef argv0
261#define ARGV0 STRINGIFY(argv0)
262#else
263static char* argv0;
264#define ARGV0 argv0
265#endif
266void cataexit(int status) {
267 printf("cata: exe %s pid %d exit %d\n", ARGV0, getpid(), status);
268 exit(status);
269}
270void _cataexit(int status) {
271 printf("cata: exe %s pid %d _exit %d\n", ARGV0, getpid(), status);
272 _exit(status);
273}
274void catasighandle(int signum) {
275 int core = 0;
276 printf("cata: exe %s pid %d signal %d\n", ARGV0, getpid(), signum);
277 switch (signum) {
278 case SIGQUIT:
279 case SIGILL:
280 case SIGTRAP:
281 case SIGABRT:
282 case SIGBUS:
283 case SIGSEGV:
284 case SIGXCPU:
285 case SIGXFSZ:
286 core = 0200;
287 break;
288 default:
289 break;
290 }
291 cataexit(core << 8 | signum);
292}
293void catasigsetup() {
294 signal(SIGHUP, catasighandle);
295 signal(SIGINT, catasighandle);
296 signal(SIGQUIT, catasighandle);
297 signal(SIGILL, catasighandle);
298 signal(SIGTRAP, catasighandle);
299 signal(SIGABRT, catasighandle);
300 signal(SIGIOT, catasighandle);
301 /* KILL */
302 signal(SIGBUS, catasighandle);
303 signal(SIGFPE, catasighandle);
304 signal(SIGUSR1, catasighandle);
305 signal(SIGUSR2, catasighandle);
306 signal(SIGSEGV, catasighandle);
307 signal(SIGPIPE, catasighandle);
308 signal(SIGALRM, catasighandle);
309 signal(SIGTERM, catasighandle);
310 signal(SIGSTKFLT, catasighandle);
311 signal(SIGCHLD, catasighandle);
312 signal(SIGCONT, catasighandle);
313 /* STOP */
314 signal(SIGTSTP, catasighandle);
315 signal(SIGTTIN, catasighandle);
316 signal(SIGTTOU, catasighandle);
317 signal(SIGURG, catasighandle);
318 signal(SIGXCPU, catasighandle);
319 signal(SIGXFSZ, catasighandle);
320 signal(SIGVTALRM, catasighandle);
321 signal(SIGPROF, catasighandle);
322 signal(SIGWINCH, catasighandle);
323 signal(SIGIO, catasighandle);
324 signal(SIGPWR, catasighandle);
325 signal(SIGSYS, catasighandle);
326}
327int main(int argc, char *argv[], char *envv[]) {
328 int status;
329#ifndef argv0
330 argv0 = argv[0];
331#endif
332 catasigsetup();
333 status =
334#ifdef main0
335 catamain();
336#else
337#ifdef main2
338 catamain(argc, argv);
339#else
340 catamain(argc, argv, envv);
341#endif
342#endif
343 printf("cata: exe %s pid %d main %d\n", ARGV0, getpid(), status);
344 return status;
345}
346__EOF7__
347
348echo "Faking DynaLoader"
349touch DynaLoader.o # Oh, the agony.
350
351# That's it.