Remaining smoked platforms where malloc wrap is known to work.
[p5sagit/p5-mst-13.2.git] / hints / solaris_2.sh
1 # hints/solaris_2.sh
2 # Contributions by (in alphabetical order) Alan Burlison, Andy Dougherty,
3 # Dean Roehrich, Jarkko Hietaniemi, Lupe Christoph, Richard Soderberg and
4 # many others.
5 #
6 # See README.solaris for additional information.
7 #
8 # For consistency with gcc, we do not adopt Sun Marketing's
9 # removal of the '2.' prefix from the Solaris version number.
10 # (Configure tries to detect an old fixincludes and needs
11 # this information.)
12
13 # If perl fails tests that involve dynamic loading of extensions, and
14 # you are using gcc, be sure that you are NOT using GNU as and ld.  One
15 # way to do that is to invoke Configure with
16 #
17 #     sh Configure -Dcc='gcc -B/usr/ccs/bin/'
18 #
19 #  (Note that the trailing slash is *required*.)
20 #  gcc will occasionally emit warnings about "unused prefix", but
21 #  these ought to be harmless.  See below for more details.
22
23 # Solaris has secure SUID scripts
24 d_suidsafe=${d_suidsafe:-define}
25
26 # Be paranoid about nm failing to find symbols
27 mistrustnm=${mistrustnm:-run}
28
29 # Several people reported problems with perl's malloc, especially
30 # when use64bitall is defined or when using gcc.
31 #     http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2001-01/msg01318.html
32 #     http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2001-01/msg00465.html
33 usemymalloc=${usemymalloc:-false}
34
35 # malloc wrap works
36 case "$usemallocwrap" in
37 '') usemallocwrap='define' ;;
38 esac
39
40 # Avoid all libraries in /usr/ucblib.
41 # /lib is just a symlink to /usr/lib
42 set `echo $glibpth | sed -e 's@/usr/ucblib@@' -e 's@ /lib @ @'`
43 glibpth="$*"
44
45 # Remove unwanted libraries.  -lucb contains incompatible routines.
46 # -lld and -lsec don't do anything useful. -lcrypt does not
47 # really provide anything we need over -lc, so we drop it, too.
48 # -lmalloc can cause a problem with GNU CC & Solaris.  Specifically,
49 # libmalloc.a may allocate memory that is only 4 byte aligned, but
50 # GNU CC on the Sparc assumes that doubles are 8 byte aligned.
51 # Thanks to  Hallvard B. Furuseth <h.b.furuseth@usit.uio.no>
52 set `echo " $libswanted " | sed -e 's@ ld @ @' -e 's@ malloc @ @' -e 's@ ucb @ @' -e 's@ sec @ @' -e 's@ crypt @ @'`
53 libswanted="$*"
54
55 # Look for architecture name.  We want to suggest a useful default.
56 case "$archname" in
57 '')
58     if test -f /usr/bin/arch; then
59         archname=`/usr/bin/arch`
60         archname="${archname}-${osname}"
61     elif test -f /usr/ucb/arch; then
62         archname=`/usr/ucb/arch`
63         archname="${archname}-${osname}"
64     fi
65     ;;
66 esac
67
68 #
69 # This extracts the library directories that will be searched by the Sun
70 # Workshop compiler, given the command-line supplied in $tryworkshopcc.
71 # Use thusly: loclibpth="`$getworkshoplibs` $loclibpth"
72 #
73         getworkshoplibs=`cat <<'END'
74 eval $tryworkshopcc -### 2>&1 | \
75 sed -n '/ -Y /s!.* -Y "P,\([^"]*\)".*!\1!p' | tr ':' ' ' | \
76 sed -e 's!/usr/lib/sparcv9!!' -e 's!/usr/ccs/lib/sparcv9!!' \
77     -e 's!/usr/lib!!g' -e 's!/usr/ccs/lib!!g'
78 END
79 `
80
81 case "$cc" in
82 '')     if test -f /opt/SUNWspro/bin/cc; then
83                 cc=/opt/SUNWspro/bin/cc
84                 cat <<EOF >&4   
85
86 You specified no cc but you seem to have the Workshop compiler
87 ($cc) installed, using that.
88 If you want something else, specify that in the command line,
89 e.g. Configure -Dcc=gcc
90
91 EOF
92         fi
93         ;;
94 esac
95
96 ######################################################
97 # General sanity testing.  See below for excerpts from the Solaris FAQ.
98 #
99 # From roehrich@ironwood-fddi.cray.com Wed Sep 27 12:51:46 1995
100 # Date: Thu, 7 Sep 1995 16:31:40 -0500
101 # From: Dean Roehrich <roehrich@ironwood-fddi.cray.com>
102 # To: perl5-porters@africa.nicoh.com
103 # Subject: Re: On perl5/solaris/gcc
104 #
105 # Here's another draft of the perl5/solaris/gcc sanity-checker.
106
107 case `type ${cc:-cc}` in
108 */usr/ucb/cc*) cat <<END >&4
109
110 NOTE:  Some people have reported problems with /usr/ucb/cc.
111 If you have difficulties, please make sure the directory
112 containing your C compiler is before /usr/ucb in your PATH.
113
114 END
115 ;;
116 esac
117
118
119 # Check that /dev/fd is mounted.  If it is not mounted, let the
120 # user know that suid scripts may not work.
121 mount | grep '^/dev/fd ' 2>&1 > /dev/null
122 case $? in
123 0) ;;
124 *)
125         cat <<END >&4
126
127 NOTE: Your system does not have /dev/fd mounted.  If you want to
128 be able to use set-uid scripts you must ask your system administrator
129 to mount /dev/fd.
130
131 END
132         ;;
133 esac
134
135
136 # See if libucb can be found in /usr/lib.  If it is, warn the user
137 # that this may cause problems while building Perl extensions.
138 /usr/bin/ls /usr/lib/libucb* >/dev/null 2>&1
139 case $? in
140 0)
141         cat <<END >&4
142
143 NOTE: libucb has been found in /usr/lib.  libucb should reside in
144 /usr/ucblib.  You may have trouble while building Perl extensions.
145
146 END
147 ;;
148 esac
149
150 # Use shell built-in 'type' command instead of /usr/bin/which to
151 # avoid possible csh start-up problems and also to use the same shell
152 # we'll be using to Configure and make perl.
153 # The path name is the last field in the output, but the type command
154 # has an annoying array of possible outputs, e.g.:
155 #       make is hashed (/opt/gnu/bin/make)
156 #       cc is /usr/ucb/cc
157 #       foo not found
158 # use a command like type make | awk '{print $NF}' | sed 's/[()]//g'
159
160 # See if make(1) is GNU make(1).
161 # If it is, make sure the setgid bit is not set.
162 make -v > make.vers 2>&1
163 if grep GNU make.vers > /dev/null 2>&1; then
164     tmp=`type make | awk '{print $NF}' | sed 's/[()]//g'`
165     case "`/usr/bin/ls -lL $tmp`" in
166     ??????s*)
167             cat <<END >&2
168
169 NOTE: Your PATH points to GNU make, and your GNU make has the set-group-id
170 bit set.  You must either rearrange your PATH to put /usr/ccs/bin before the
171 GNU utilities or you must ask your system administrator to disable the
172 set-group-id bit on GNU make.
173
174 END
175             ;;
176     esac
177 fi
178 rm -f make.vers
179
180 cat > UU/cc.cbu <<'EOCBU'
181 # This script UU/cc.cbu will get 'called-back' by Configure after it
182 # has prompted the user for the C compiler to use.
183
184 # If the C compiler is gcc:
185 #   - check the fixed-includes
186 #   - check as(1) and ld(1), they should not be GNU
187 #       (GNU as and ld 2.8.1 and later are reportedly ok, however.)
188 # If the C compiler is not gcc:
189 #   - Check if it is the Workshop/Forte compiler.
190 #     If it is, prepare for 64 bit and long doubles.
191 #   - check as(1) and ld(1), they should not be GNU
192 #       (GNU as and ld 2.8.1 and later are reportedly ok, however.)
193 #
194 # Watch out in case they have not set $cc.
195
196 # Perl compiled with some combinations of GNU as and ld may not
197 # be able to perform dynamic loading of extensions.  If you have a
198 # problem with dynamic loading, be sure that you are using the Solaris
199 # /usr/ccs/bin/as and /usr/ccs/bin/ld.  You can do that with
200 #               sh Configure -Dcc='gcc -B/usr/ccs/bin/'
201 # (note the trailing slash is required).
202 # Combinations that are known to work with the following hints:
203 #
204 #  gcc-2.7.2, GNU as 2.7, GNU ld 2.7
205 #  egcs-1.0.3, GNU as 2.9.1 and GNU ld 2.9.1
206 #       --Andy Dougherty  <doughera@lafayette.edu>
207 #       Tue Apr 13 17:19:43 EDT 1999
208
209 # Get gcc to share its secrets.
210 echo 'int main() { return 0; }' > try.c
211         # Indent to avoid propagation to config.sh
212         verbose=`${cc:-cc} -v -o try try.c 2>&1`
213
214 if echo "$verbose" | grep '^Reading specs from' >/dev/null 2>&1; then
215         #
216         # Using gcc.
217         #
218         cc_name='gcc'
219
220         # See if as(1) is GNU as(1).  GNU as(1) might not work for this job.
221         if echo "$verbose" | grep ' /usr/ccs/bin/as ' >/dev/null 2>&1; then
222             :
223         else
224             cat <<END >&2
225
226 NOTE: You are using GNU as(1).  GNU as(1) might not build Perl.  If you
227 have trouble, you can use /usr/ccs/bin/as by including -B/usr/ccs/bin/
228 in your ${cc:-cc} command.  (Note that the trailing "/" is required.)
229
230 END
231             # Apparently not needed, at least for as 2.7 and later.
232             # cc="${cc:-cc} -B/usr/ccs/bin/"
233         fi
234
235         # See if ld(1) is GNU ld(1).  GNU ld(1) might not work for this job.
236         # Recompute $verbose since we may have just changed $cc.
237         verbose=`${cc:-cc} -v -o try try.c 2>&1 | grep ld 2>&1`
238
239         if echo "$verbose" | grep ' /usr/ccs/bin/ld ' >/dev/null 2>&1; then
240             # Ok, gcc directly calls the Solaris /usr/ccs/bin/ld.
241             :
242         elif echo "$verbose" | grep "ld: Software Generation Utilities" >/dev/null 2>&1; then
243             # Hmm.  gcc doesn't call /usr/ccs/bin/ld directly, but it
244             # does appear to be using it eventually.  egcs-1.0.3's ld
245             # wrapper does this.
246             # All Solaris versions of ld I've seen contain the magic
247             # string used in the grep.
248             :
249         else
250             # No evidence yet of /usr/ccs/bin/ld.  Some versions
251             # of egcs's ld wrapper call /usr/ccs/bin/ld in turn but
252             # apparently don't reveal that unless you pass in -V.
253             # (This may all depend on local configurations too.)
254
255             # Recompute verbose with -Wl,-v to find GNU ld if present
256             verbose=`${cc:-cc} -v -Wl,-v -o try try.c 2>&1 | grep ld 2>&1`
257
258             myld=`echo $verbose| grep ld | awk '/\/ld/ {print $1}'`
259             # This assumes that gcc's output will not change, and that
260             # /full/path/to/ld will be the first word of the output.
261             # Thus myld is something like /opt/gnu/sparc-sun-solaris2.5/bin/ld
262
263             # Allow that $myld may be '', due to changes in gcc's output 
264             if ${myld:-ld} -V 2>&1 |
265                 grep "ld: Software Generation Utilities" >/dev/null 2>&1; then
266                 # Ok, /usr/ccs/bin/ld eventually does get called.
267                 :
268             else
269                 echo "Found GNU ld='$myld'" >&4
270                 cat <<END >&2
271
272 NOTE: You are using GNU ld(1).  GNU ld(1) might not build Perl.  If you
273 have trouble, you can use /usr/ccs/bin/ld by including -B/usr/ccs/bin/
274 in your ${cc:-cc} command.  (Note that the trailing "/" is required.)
275
276 I will try to use GNU ld by passing in the -Wl,-E flag, but if that
277 doesn't work, you should use -B/usr/ccs/bin/ instead.
278
279 END
280                 ccdlflags="$ccdlflags -Wl,-E"
281                 lddlflags="$lddlflags -Wl,-E -G"
282             fi
283         fi
284
285 else
286         #
287         # Not using gcc.
288         #
289         cat > try.c << 'EOM'
290 #include <stdio.h>
291 int main() {
292 #ifdef __SUNPRO_C
293         printf("workshop\n");
294 #else
295         printf("\n");
296 #endif
297 return(0);
298 }
299 EOM
300         tryworkshopcc="${cc:-cc} try.c -o try"
301         if $tryworkshopcc >/dev/null 2>&1; then
302                 cc_name=`./try`
303                 if test "$cc_name" = "workshop"; then
304                         ccversion="`${cc:-cc} -V 2>&1|sed -n -e '1s/^cc: //p'`"
305                         if test ! "$use64bitall_done"; then
306                                 loclibpth="/usr/lib /usr/ccs/lib `$getworkshoplibs` $loclibpth"
307                         fi
308                 fi
309         fi
310
311         # See if as(1) is GNU as(1).  GNU might not work for this job.
312         case `as --version < /dev/null 2>&1` in
313         *GNU*)
314                 cat <<END >&2
315
316 NOTE: You are using GNU as(1).  GNU as(1) might not build Perl.
317 You must arrange to use /usr/ccs/bin/as, perhaps by adding /usr/ccs/bin
318 to the beginning of your PATH.
319
320 END
321                 ;;
322         esac
323
324         # See if ld(1) is GNU ld(1).  GNU ld(1) might not work for this job.
325         # ld --version doesn't properly report itself as a GNU tool,
326         # as of ld version 2.6, so we need to be more strict. TWP 9/5/96
327         # Sun's ld always emits the "Software Generation Utilities" string.
328         if ld -V 2>&1 | grep "ld: Software Generation Utilities" >/dev/null 2>&1; then
329             # Ok, ld is /usr/ccs/bin/ld.
330             :
331         else
332             cat <<END >&2
333
334 NOTE: You are apparently using GNU ld(1).  GNU ld(1) might not build Perl.
335 You should arrange to use /usr/ccs/bin/ld, perhaps by adding /usr/ccs/bin
336 to the beginning of your PATH.
337
338 END
339         fi
340 fi
341
342 # as --version or ld --version might dump core.
343 rm -f try try.c core
344 EOCBU
345
346 cat > UU/usethreads.cbu <<'EOCBU'
347 # This script UU/usethreads.cbu will get 'called-back' by Configure
348 # after it has prompted the user for whether to use threads.
349 case "$usethreads" in
350 $define|true|[yY]*)
351         ccflags="-D_REENTRANT $ccflags"
352
353         # -lpthread overrides some lib C functions, so put it before c.
354         set `echo X "$libswanted "| sed -e "s/ c / pthread c /"`
355         shift
356         libswanted="$*"
357
358         # sched_yield is available in the -lrt library.  However,
359         # we can also pick up the equivalent yield() function in the
360         # normal C library.  To avoid pulling in unnecessary
361         # libraries, we'll normally avoid sched_yield()/-lrt and
362         # just use yield().  However, we'll honor a command-line
363         # override : "-Dsched_yield=sched_yield".
364         # If we end up using sched_yield, we're going to need -lrt.
365         sched_yield=${sched_yield:-yield}
366         if test "$sched_yield" = "sched_yield"; then
367             set `echo X "$libswanted "| sed -e "s/ pthread / rt pthread /"`
368             shift
369             libswanted="$*"
370         fi
371
372         # On Solaris 2.6 x86 there is a bug with sigsetjmp() and siglongjmp()
373         # when linked with the threads library, such that whatever positive
374         # value you pass to siglongjmp(), sigsetjmp() returns 1.
375         # Thanks to Simon Parsons <S.Parsons@ftel.co.uk> for this report.
376         # Sun BugID is 4117946, "sigsetjmp always returns 1 when called by
377         # siglongjmp in a MT program". As of 19980622, there is no patch
378         # available.
379         cat >try.c <<'EOM'
380         /* Test for sig(set|long)jmp bug. */
381         #include <setjmp.h>
382
383         int main()
384         {
385             sigjmp_buf env;
386             int ret;
387
388             ret = sigsetjmp(env, 1);
389             if (ret) { return ret == 2; }
390             siglongjmp(env, 2);
391         }
392 EOM
393         if test "`arch`" = i86pc -a `uname -r` = 5.6 && \
394            ${cc:-cc} try.c -lpthread >/dev/null 2>&1 && ./a.out; then
395             d_sigsetjmp=$undef
396             cat << 'EOM' >&2
397
398 You will see a *** WHOA THERE!!! ***  message from Configure for
399 d_sigsetjmp.  Keep the recommended value.  See hints/solaris_2.sh
400 for more information.
401
402 EOM
403         fi
404
405         # These prototypes should be visible since we using
406         # -D_REENTRANT, but that does not seem to work.
407         # It does seem to work for getnetbyaddr_r, weirdly enough,
408         # and other _r functions. (Solaris 8)
409
410         d_ctermid_r_proto="$define"
411         d_gethostbyaddr_r_proto="$define"
412         d_gethostbyname_r_proto="$define"
413         d_getnetbyname_r_proto="$define"
414         d_getprotobyname_r_proto="$define"
415         d_getprotobynumber_r_proto="$define"
416         d_getservbyname_r_proto="$define"
417         d_getservbyport_r_proto="$define"
418
419         # Ditto. (Solaris 7)
420         d_readdir_r_proto="$define"
421         d_readdir64_r_proto="$define"
422         d_tmpnam_r_proto="$define"
423         d_ttyname_r_proto="$define"
424
425         ;;
426 esac
427 EOCBU
428
429 cat > UU/uselargefiles.cbu <<'EOCBU'
430 # This script UU/uselargefiles.cbu will get 'called-back' by Configure
431 # after it has prompted the user for whether to use large files.
432 case "$uselargefiles" in
433 ''|$define|true|[yY]*)
434
435 # Keep these in the left margin.
436 ccflags_uselargefiles="`getconf LFS_CFLAGS 2>/dev/null`"
437 ldflags_uselargefiles="`getconf LFS_LDFLAGS 2>/dev/null`"
438 libswanted_uselargefiles="`getconf LFS_LIBS 2>/dev/null|sed -e 's@^-l@@' -e 's@ -l@ @g`"
439
440     ccflags="$ccflags $ccflags_uselargefiles"
441     ldflags="$ldflags $ldflags_uselargefiles"
442     libswanted="$libswanted $libswanted_uselargefiles"
443     ;;
444 esac
445 EOCBU
446
447 # This is truly a mess.
448 case "$usemorebits" in
449 "$define"|true|[yY]*)
450         use64bitint="$define"
451         uselongdouble="$define"
452         ;;
453 esac
454
455 if test `uname -p` = "sparc"; then
456     cat > UU/use64bitint.cbu <<'EOCBU'
457 # This script UU/use64bitint.cbu will get 'called-back' by Configure
458 # after it has prompted the user for whether to use 64 bit integers.
459 case "$use64bitint" in
460 "$define"|true|[yY]*)
461             case "`uname -r`" in
462             5.[0-4])
463                 cat >&4 <<EOM
464 Solaris `uname -r|sed -e 's/^5\./2./'` does not support 64-bit integers.
465 You should upgrade to at least Solaris 2.5.
466 EOM
467                 exit 1
468                 ;;
469             esac
470
471 # gcc-2.8.1 on Solaris 8 with -Duse64bitint fails op/pat.t test 822
472 # if we compile regexec.c with -O.  Turn off optimization for that one
473 # file.  See hints/README.hints , especially 
474 # =head2 Propagating variables to config.sh, method 3.
475 #  A. Dougherty  May 24, 2002
476     case "${gccversion}-${optimize}" in
477     2.8*-O*)
478         # Honor a command-line override (rather unlikely)
479         case "$regexec_cflags" in
480         '') echo "Disabling optimization on regexec.c for gcc $gccversion" >&4
481             regexec_cflags='optimize='
482             echo "regexec_cflags='optimize=\"\"'" >> config.sh 
483             ;;
484         esac
485         ;;
486     esac
487     ;;
488 esac
489 EOCBU
490
491     cat > UU/use64bitall.cbu <<'EOCBU'
492 # This script UU/use64bitall.cbu will get 'called-back' by Configure
493 # after it has prompted the user for whether to be maximally 64 bitty.
494 case "$use64bitall-$use64bitall_done" in
495 "$define-"|true-|[yY]*-)
496             case "`uname -r`" in
497             5.[0-6])
498                 cat >&4 <<EOM
499 Solaris `uname -r|sed -e 's/^5\./2./'` does not support 64-bit pointers.
500 You should upgrade to at least Solaris 2.7.
501 EOM
502                 exit 1
503                 ;;
504             esac
505             libc='/usr/lib/sparcv9/libc.so'
506             if test ! -f $libc; then
507                 cat >&4 <<EOM
508
509 I do not see the 64-bit libc, $libc.
510 Cannot continue, aborting.
511
512 EOM
513                 exit 1
514             fi
515             case "${cc:-cc} -v 2>/dev/null" in
516             *gcc*)
517                 echo 'int main() { return 0; }' > try.c
518                 case "`${cc:-cc} -mcpu=v9 -m64 -S try.c 2>&1 | grep 'm64 is not supported by this configuration'`" in
519                 *"m64 is not supported"*)
520                     cat >&4 <<EOM
521
522 Full 64-bit build is not supported by this gcc configuration.
523 Check http://gcc.gnu.org/ for the latest news of availability
524 of gcc for 64-bit Sparc.
525
526 Cannot continue, aborting.
527
528 EOM
529                     exit 1
530                     ;;
531                 esac
532                 loclibpth="/usr/lib/sparcv9 $loclibpth"
533                 ccflags="$ccflags -mcpu=v9 -m64"
534                 if test X`getconf XBS5_LP64_OFF64_CFLAGS 2>/dev/null` != X; then
535                     # This adds in -Wa,-xarch=v9.  I suspect that's superfluous,
536                     # since the -m64 above should do that already.  Someone
537                     # with gcc-3.x.x, please test with gcc -v.   A.D. 20-Nov-2003
538                     ccflags="$ccflags -Wa,`getconf XBS5_LP64_OFF64_CFLAGS 2>/dev/null`"
539                 fi
540                 ldflags="$ldflags -m64"
541                 lddlflags="$lddlflags -G -m64"
542                 ;;
543             *)
544                 ccflags="$ccflags `getconf XBS5_LP64_OFF64_CFLAGS 2>/dev/null`"
545                 ldflags="$ldflags `getconf XBS5_LP64_OFF64_LDFLAGS 2>/dev/null`"
546                 lddlflags="$lddlflags -G `getconf XBS5_LP64_OFF64_LDFLAGS 2>/dev/null`"
547                 echo "int main() { return(0); } " > try.c
548                 tryworkshopcc="${cc:-cc} try.c -o try $ccflags"
549                 loclibpth="/usr/lib/sparcv9 /usr/ccs/lib/sparcv9 `$getworkshoplibs` $loclibpth"
550                 ;;
551             esac
552
553             use64bitall_done=yes
554             archname64=64
555             ;;
556 esac
557 EOCBU
558
559     # Actually, we want to run this already now, if so requested,
560     # because we need to fix up things right now.
561     case "$use64bitall" in
562     "$define"|true|[yY]*)
563         # CBUs expect to be run in UU
564         cd UU; . ./use64bitall.cbu; cd ..
565         ;;
566     esac
567 fi
568
569 cat > UU/uselongdouble.cbu <<'EOCBU'
570 # This script UU/uselongdouble.cbu will get 'called-back' by Configure
571 # after it has prompted the user for whether to use long doubles.
572 case "$uselongdouble" in
573 "$define"|true|[yY]*)
574         if test "$cc_name" = "workshop"; then
575                 cat > try.c << 'EOM'
576 #include <sunmath.h>
577 int main() { (void) powl(2, 256); return(0); }
578 EOM
579                 if ${cc:-cc} try.c -lsunmath -o try > /dev/null 2>&1 && ./try; then
580                         libswanted="$libswanted sunmath"
581                 fi
582         else
583                 cat >&4 <<EOM
584
585 The Sun Workshop math library is either not available or not working,
586 so I do not know how to do long doubles, sorry.
587 I'm therefore disabling the use of long doubles.
588 EOM
589                 uselongdouble="$undef"
590         fi
591         ;;
592 esac
593 EOCBU
594
595 rm -f try.c try.o try a.out