(back) towards g++ compilation (in Tru64, and elsewhere)
[p5sagit/p5-mst-13.2.git] / hints / dec_osf.sh
1 # hints/dec_osf.sh
2
3 #       * If you want to debug perl or want to send a
4 #       stack trace for inclusion into an bug report, call
5 #       Configure with the additional argument  -Doptimize=-g2
6 #       or uncomment this assignment to "optimize":
7 #
8 #optimize=-g2
9 #
10 #       If you want both to optimise and debug with the DEC cc
11 #       you must have -g3, e.g. "-O4 -g3", and (re)run Configure.
12 #
13 #       * gcc can always have both -g and optimisation on.
14 #
15 #       * debugging optimised code, no matter what compiler
16 #       one is using, can be surprising and confusing because of
17 #       the optimisation tricks like code motion, code removal,
18 #       loop unrolling, and inlining. The source code and the
19 #       executable code simply do not agree any more while in
20 #       mid-execution, the optimiser only cares about the results.
21 #
22 #       * Configure will automatically add the often quoted
23 #       -DDEBUGGING for you if the -g is specified.
24 #
25 #       * There is even more optimisation available in the new
26 #       (GEM) DEC cc: -O5 and -fast. "man cc" will tell more about them.
27 #       The jury is still out whether either or neither help for Perl
28 #       and how much. Based on very quick testing, -fast boosts
29 #       raw data copy by about 5-15% (-fast brings in, among other
30 #       things, inlined, ahem, fast memcpy()), while on the other
31 #       hand searching things (index, m//, s///), seems to get slower.
32 #       Your mileage will vary.
33 #
34 #       * The -std is needed because the following compiled
35 #       without the -std and linked with -lm
36 #
37 #       #include <math.h>
38 #       #include <stdio.h>
39 #       int main(){short x=10,y=sqrt(x);printf("%d\n",y);}
40 #
41 #       will in Digital UNIX 3.* and 4.0b print 0 -- and in Digital
42 #       UNIX 4.0{,a} dump core: Floating point exception in the printf(),
43 #       the y has become a signaling NaN.
44 #
45 #       * Compilation warnings like:
46 #
47 #       "Undefined the ANSI standard macro ..."
48 #
49 #       can be ignored, at least while compiling the POSIX extension
50 #       and especially if using the sfio (the latter is not a standard
51 #       part of Perl, never mind if it says little to you).
52 #
53
54 # If using the DEC compiler we must find out the DEC compiler style:
55 # the style changed between Digital UNIX (aka DEC OSF/1) 3 and
56 # Digital UNIX 4. The old compiler was originally from Ultrix and
57 # the MIPS company, the new compiler is originally from the VAX world
58 # and it is called GEM. Many of the options we are going to use depend
59 # on the compiler style.
60
61 cc=${cc:-cc}
62
63 case "`$cc -v 2>&1 | grep cc`" in
64 *gcc*) isgcc=gcc ;;
65 esac
66
67 # do NOT, I repeat, *NOT* take away the leading tabs
68 # Configure Black Magic (TM)
69         # reset
70         _DEC_cc_style=
71 case "$isgcc" in
72 gcc)    if [ "X$gccversion" = "X" ]; then
73             # Done too late in Configure if hinted
74             gccversion=`$cc --version | sed 's/.*(GCC) *//'`
75         fi
76         set $gccversion
77         if test "$1" -lt 2 -o \( "$1" -eq 2 -a \( "$2" -lt 95 -o \( "$2" -eq 95 -a "$3" -lt 3 \) \) \); then
78             cat >&4 <<EOF
79
80 *** Your cc seems to be gcc and its version ($gccversion) seems to be
81 *** less than 2.95.3.  This is not a good idea since old versions of gcc
82 *** are known to produce buggy code when compiling Perl (and no doubt for
83 *** other programs, too).
84 ***
85 *** Therefore, I strongly suggest upgrading your gcc.  (Why don't you use
86 *** the vendor cc is also a good question.  It comes with the operating
87 *** system, produces good code, and is very ANSI C fastidious.)
88
89 Cannot continue, aborting.
90
91 EOF
92             exit 1
93         fi
94         if test "$1" -eq 2 -a "$2" -eq 95 -a "$3" -le 2; then
95             cat >&4 <<EOF
96
97 *** Note that as of gcc 2.95.2 (19991024) and Perl 5.6.0 (March 2000)
98 *** if the said Perl is compiled with the said gcc the lib/sdbm test
99 *** may dump core (meaning that the SDBM_File extension is unusable).
100 *** As this core dump never happens with the vendor cc, this is most
101 *** probably a lingering bug in gcc.  Therefore unless you have a better
102 *** gcc installation you are still better off using the vendor cc.
103
104 Since you explicitly chose gcc, I assume that you know what are doing.
105
106 EOF
107         fi
108         # -ansi is fine for gcc in Tru64 (-ansi is not universally so).
109         _ccflags_strict_ansi="-ansi"
110         ;;
111 *)      # compile something.
112         cat >try.c <<EOF
113 int main() { return 0; }
114 EOF
115         ccversion=`cc -V | awk '/(Compaq|DEC) C/ {print $3}' | grep '^V'`
116         # the main point is the '-v' flag of 'cc'.
117         case "`cc -v -c try.c 2>&1`" in
118         */gemc_cc*)     # we have the new DEC GEM CC
119                         _DEC_cc_style=new
120                         ;;
121         *)              # we have the old MIPS CC
122                         _DEC_cc_style=old
123                         ;;
124         esac
125         # We need to figure out whether -c99 is a valid flag to use.
126         # If it is, we can use it for being nauseatingly C99 ANSI --
127         # but even then the lddlflags needs to stay -std1.
128         # If it is not, we must use -std1 for both flags.
129         #
130         case "`cc -c99 try.c 2>&1`" in
131         *"-c99: Unknown flag"*)
132                 _ccflags_strict_ansi="-std1"
133                 ;;
134         *)      # However, use the -c99 only if compiling for
135                 # -DPERL_MEM_LOG, where the C99 feature __func__
136                 # is useful to have.  Otherwise use the good old
137                 # -std1 so that we stay C89 strict, which the goal
138                 # of the Perl C code base (no //, no code between
139                 # declarations, etc).  Moreover, the Tru64 cc is
140                 # not fully C99, and most probably never will be.
141                 #
142                 # The -DPERL_MEM_LOG can be either in ccflags
143                 # (if using an old config.sh) or in the command line
144                 # (which has been stowed away in UU/cmdline.opt).
145                 #
146                 case "$ccflags `cat UU/cmdline.opt`" in
147                 *-DPERL_MEM_LOG*)       _ccflags_strict_ansi="-c99"  ;;
148                 *)                      _ccflags_strict_ansi="-std1" ;;
149                 esac
150                 ;;
151         esac
152         _lddlflags_strict_ansi="-std1"
153         # -no_ansi_alias because Perl code is not that strict
154         # (also gcc uses by default -fno-strict-aliasing).
155         _ccflags_strict_ansi="$_ccflags_strict_ansi -no_ansi_alias"
156         # Cleanup.
157         rm -f try.c try.o
158         ;;
159 esac
160
161 # Be nauseatingly ANSI
162 ccflags="$ccflags $_ccflags_strict_ansi"
163
164 # g++ needs -D_XOPEN_SOURCE -D_OSF_SOURCE to get much use of <unistd.h>.
165 case "$cc" in
166 *g++*) ccflags="$ccflags -D_XOPEN_SOURCE -D_OSF_SOURCE" ;;
167 esac
168
169 # for gcc the Configure knows about the -fpic:
170 # position-independent code for dynamic loading
171
172 # we want optimisation
173
174 case "$optimize" in
175 '')     case "$isgcc" in
176         gcc)    optimize='-O3'                          ;;
177         *)      case "$_DEC_cc_style" in
178                 new)    optimize='-O4'                  ;;
179                 old)    optimize='-O2 -Olimit 3200'     ;;
180                 esac
181                 ccflags="$ccflags -D_INTRINSICS"
182                 ;;
183         esac
184         ;;
185 esac
186
187 case "$isgcc" in
188 gcc)    ;;
189 *)      case "$optimize" in
190         *-O*)   # With both -O and -g, the -g must be -g3.
191                 optimize="`echo $optimize | sed 's/-g[1-4]*/-g3/'`"
192                 ;;
193         esac
194         ;;
195 esac
196
197 ## Optimization limits
198 case "$isgcc" in
199 gcc) #  gcc 3.2.1 wants a lot of memory for -O3'ing toke.c
200 cat >try.c <<EOF
201 #include <stdio.h>
202 #include <sys/resource.h>
203
204 int main ()
205 {
206     struct rlimit rl;
207     int i = getrlimit (RLIMIT_DATA, &rl);
208     printf ("%d\n", rl.rlim_cur / (1024 * 1024));
209     } /* main */
210 EOF
211 $cc -o try $ccflags $ldflags try.c
212         maxdsiz=`./try`
213 rm -f try try.c core
214 if [ $maxdsiz -lt 256 ]; then
215     # less than 256 MB is probably not enough to optimize toke.c with gcc -O3
216     cat <<EOM >&4
217
218 Your process datasize is limited to $maxdsiz MB, which is (sadly) not
219 always enough to fully optimize some source code files of Perl,
220 at least 256 MB seems to be necessary as of Perl 5.8.0.  I'll try to
221 use a lower optimization level for those parts.  You could either try
222 using your shell's ulimit/limit/limits command to raise your datasize
223 (assuming the system-wide hard resource limits allow you to go higher),
224 or if you can't go higher and if you are a sysadmin, and you *do* want
225 the full optimization, you can tune the 'max_per_proc_data_size'
226 kernel parameter: see man sysconfigtab, and man sys_attrs_proc.
227
228 EOM
229 toke_cflags='optimize=-O2'
230     fi
231 ;;
232 esac
233
234 # The patch 23787
235 # http://public.activestate.com/cgi-bin/perlbrowse?patch=23787
236 # broke things for gcc (at least gcc 3.3) so that many of the pack()
237 # checksum tests for formats L, j, J, especially when combined
238 # with the < and > specifiers, started to fail if compiled with plain -O3.
239 case "$isgcc" in
240 gcc)
241 pp_pack_cflags='optimize="-O3 -fno-cse-skip-blocks"'
242 ;;
243 esac
244
245 # we want dynamic fp rounding mode, and we want ieee exception semantics
246 case "$isgcc" in
247 gcc)    ;;
248 *)      case "$_DEC_cc_style" in
249         new)    ccflags="$ccflags -fprm d -ieee"        ;;
250         esac
251         ;;
252 esac
253
254 # Make glibpth agree with the compiler suite.  Note that /shlib
255 # is not here.  That's on purpose.  Even though that's where libc
256 # really lives from V4.0 on, the linker (and /sbin/loader) won't
257 # look there by default.  The sharable /sbin utilities were all
258 # built with "-Wl,-rpath,/shlib" to get around that.  This makes
259 # no attempt to figure out the additional location(s) searched by
260 # gcc, since not all versions of gcc are easily coerced into
261 # revealing that information.
262 glibpth="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc"
263 glibpth="$glibpth /usr/lib /usr/local/lib /var/shlib"
264
265 # dlopen() is in libc
266 libswanted="`echo $libswanted | sed -e 's/ dl / /'`"
267
268 # libPW contains nothing useful for perl
269 libswanted="`echo $libswanted | sed -e 's/ PW / /'`"
270
271 # libnet contains nothing useful for perl here, and doesn't work
272 libswanted="`echo $libswanted | sed -e 's/ net / /'`"
273
274 # libbsd contains nothing used by perl that is not already in libc
275 libswanted="`echo $libswanted | sed -e 's/ bsd / /'`"
276
277 # libc need not be separately listed
278 libswanted="`echo $libswanted | sed -e 's/ c / /'`"
279
280 # ndbm is already in libc
281 libswanted="`echo $libswanted | sed -e 's/ ndbm / /'`"
282
283 # the basic lddlflags used always
284 lddlflags='-shared -expect_unresolved "*"'
285
286 # Intentional leading tab.
287         myosvers="`/usr/sbin/sizer -v 2>/dev/null || uname -r`"
288
289 # Fancy compiler suites use optimising linker as well as compiler.
290 # <spider@Orb.Nashua.NH.US>
291 case "`uname -r`" in
292 *[123].*)       # old loader
293                 lddlflags="$lddlflags -O3"
294                 ;;
295 *)            if $test "X$optimize" = "X$undef"; then
296                       lddlflags="$lddlflags -msym"
297               else
298                   case "$myosvers" in
299                   *4.0D*)
300                       # QAR 56761: -O4 + .so may produce broken code,
301                       # fixed in 4.0E or better.
302                       ;;
303                   *)    
304                       lddlflags="$lddlflags $optimize"
305                       ;;
306                   esac
307                   # -msym: If using a sufficiently recent /sbin/loader,
308                   # keep the module symbols with the modules.
309                   lddlflags="$lddlflags -msym $_lddlflags_strict_ansi"
310               fi
311                 ;;
312 esac
313 # Yes, the above loses if gcc does not use the system linker.
314 # If that happens, let me know about it. <jhi@iki.fi>
315
316 # Because there is no other handy way to recognize 3.X.
317 case "`uname -r`" in
318 *3.*)   ccflags="$ccflags -DDEC_OSF1_3_X" ;;
319 esac
320
321 # If debugging or (old systems and doing shared)
322 # then do not strip the lib, otherwise, strip.
323 # As noted above the -DDEBUGGING is added automagically by Configure if -g.
324 case "$optimize" in
325         *-g*) ;; # left intentionally blank
326 *)      case "`uname -r`" in
327         *[123].*)
328                 case "$useshrplib" in
329                 false|undef|'') lddlflags="$lddlflags -s"       ;;
330                 esac
331                 ;;
332         *) lddlflags="$lddlflags -s"
333                 ;;
334         esac
335         ;;
336 esac
337
338 #
339 # Make embedding in things like INN and Apache more memory friendly.
340 # Keep it overridable on the Configure command line, though, so that
341 # "-Uuseshrplib" prevents this default.
342 #
343
344 case "$_DEC_cc_style.$useshrplib" in
345         new.)   useshrplib="$define"    ;;
346 esac
347
348 # The EFF_ONLY_OK from <sys/access.h> is present but dysfunctional for
349 # [RWX]_OK as of Digital UNIX 4.0[A-D]?.  If and when this gets fixed,
350 # please adjust this appropriately.  See also pp_sys.c just before the
351 # emulate_eaccess().
352
353 # Fixed in V5.0A.
354 case "$myosvers" in
355 *5.0[A-Z]*|*5.[1-9]*|*[6-9].[0-9]*)
356         : ok
357         ;;
358 *)
359 # V5.0 or previous
360 pp_sys_cflags='ccflags="$ccflags -DNO_EFF_ONLY_OK"'
361         ;;
362 esac
363
364 # The off_t is already 8 bytes, so we do have largefileness.
365
366 cat > UU/usethreads.cbu <<'EOCBU'
367 # This script UU/usethreads.cbu will get 'called-back' by Configure 
368 # after it has prompted the user for whether to use threads.
369 case "$usethreads" in
370 $define|true|[yY]*)
371         # In Tru64 V5 (at least V5.1A, V5.1B) gcc (at least 3.2.2)
372         # cannot be used to compile a threaded Perl.
373         cat > pthread.c <<EOF
374 #include <pthread.h>
375 extern int foo; 
376 EOF
377         $cc -c pthread.c 2> pthread.err
378         if grep -q "unrecognized compiler" pthread.err; then
379             cat >&4 <<EOF
380 ***
381 *** I'm sorry but your C compiler ($cc) cannot be used to
382 *** compile Perl with threads.  The system C compiler should work.
383 ***
384
385 Cannot continue, aborting.
386
387 EOF
388             rm -f pthread.*
389             exit 1
390         fi
391         rm -f pthread.*
392         # Threads interfaces changed with V4.0.
393         case "$isgcc" in
394         gcc)
395             ccflags="-D_REENTRANT $ccflags"
396             ;;
397         *)  case "`uname -r`" in
398             *[123].*)   ccflags="-threads $ccflags" ;;
399             *)          ccflags="-pthread $ccflags" ;;
400             esac
401             ;;
402         esac    
403         case "`uname -r`" in
404         *[123].*) libswanted="$libswanted pthreads mach exc c_r" ;;
405         *)        libswanted="$libswanted pthread exc" ;;
406         esac
407
408         case "$usemymalloc" in
409         '')
410                 usemymalloc='n'
411                 ;;
412         esac
413         # These symbols are renamed in <time.h> so
414         # that the Configure hasproto doesn't see them.
415         d_asctime_r_proto="$define"
416         d_ctime_r_proto="$define"
417         d_gmtime_r_proto="$define"
418         d_localtime_r_proto="$define"
419         ;;
420 esac
421 EOCBU
422
423 # malloc wrap works
424 case "$usemallocwrap" in
425 '') usemallocwrap='define' ;;
426 esac
427
428 cat > UU/uselongdouble.cbu <<'EOCBU'
429 # This script UU/uselongdouble.cbu will get 'called-back' by Configure 
430 # after it has prompted the user for whether to use long doubles.
431 case "$uselongdouble" in
432 $define|true|[yY]*)
433         case "$myosvers" in
434         *[1-4].0*)      cat >&4 <<EOF
435
436 ***
437 *** Sorry, you cannot use long doubles in pre-V5.0 releases of Tru64.
438 ***
439
440 Cannot continue, aborting.
441
442 EOF
443                 exit 1
444                 ;;
445         *)
446                 # Test whether libc's been fixed yet for long doubles.
447                 cat >try.c <<\TRY
448 #include <stdio.h>
449 int main(int argc, char **argv)
450 {
451         unsigned long uvmax = ~0UL;
452         long double ld = uvmax + 0.0L;
453         char buf1[30], buf2[30];
454
455         (void) sprintf(buf1, "%lu", uvmax);
456         (void) sprintf(buf2, "%.0Lf", ld);
457         return strcmp(buf1, buf2) != 0;
458 }
459 TRY
460                 # Don't bother trying to work with Configure's idea of
461                 # cc and the various flags.  This might not work as-is
462                 # with gcc -- but we're testing libc, not the compiler.
463                 if cc -o try $_ccflags_strict_ansi try.c && ./try
464                 then
465                         : ok
466                 else
467                         cat <<\UGLY >&4
468 !
469 Warning!  Your libc has not yet been patched so that its "%Lf" format for
470 printing long doubles shows all the significant digits.  You will get errors
471 in the t/op/numconvert test because of this.  (The data is still good
472 internally, and the "%e" format of printf() or sprintf() in perl will still
473 produce valid results.)  See README.tru64 for additional details.
474
475 Continuing anyway.
476 !
477 UGLY
478                 fi
479                 $rm -f try try.c
480         esac
481         ;;
482 esac
483 EOCBU
484
485 case "$myosvers" in
486 *[1-4].0*) d_modfl=undef ;; # must wait till 5.0
487 esac
488
489 # Keep that leading tab.
490         old_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
491 for p in $loclibpth
492 do
493         if test -d $p; then
494             echo "Appending $p to LD_LIBRARY_PATH." >& 4
495             case "$LD_LIBRARY_PATH" in
496             '') LD_LIBRARY_PATH=$p                  ;;
497             *)  LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$p ;;
498             esac
499         fi      
500 done
501 case "$LD_LIBRARY_PATH" in
502 "$old_LD_LIBRARY_PATH") ;;
503 *) echo "LD_LIBRARY_PATH is now $LD_LIBRARY_PATH." >& 4 ;;
504 esac
505 case "$LD_LIBRARY_PATH" in
506 '') ;;
507 * ) export LD_LIBRARY_PATH ;;
508 esac
509
510 #
511 # Unset temporary variables no more needed.
512 #
513
514 unset _DEC_cc_style
515     
516 #
517 # History:
518 #
519 # perl5.005_51:
520 #
521 #       September-1998 Jarkko Hietaniemi <jhi@iki.fi>
522 #
523 #       * Added the -DNO_EFF_ONLY_OK flag ('use filetest;' support).
524 #
525 # perl5.004_57:
526 #
527 #       19-Dec-1997 Spider Boardman <spider@Orb.Nashua.NH.US>
528 #
529 #       * Newer Digital UNIX compilers enforce signaling for NaN without
530 #         -ieee.  Added -fprm d at the same time since it's friendlier for
531 #         embedding.
532 #
533 #       * Fixed the library search path to match cc, ld, and /sbin/loader.
534 #
535 #       * Default to building -Duseshrplib on newer systems.  -Uuseshrplib
536 #         still overrides.
537 #
538 #       * Fix -pthread additions for useshrplib.  ld has no -pthread option.
539 #
540 #
541 # perl5.004_04:
542 #
543 #       19-Sep-1997 Spider Boardman <spider@Orb.Nashua.NH.US>
544 #
545 #       * libnet on Digital UNIX is for JAVA, not for sockets.
546 #
547 #
548 # perl5.003_28:
549 #
550 #       22-Feb-1997 Jarkko Hietaniemi <jhi@iki.fi>
551 #
552 #       * Restructuring Spider's suggestions.
553 #
554 #       * Older Digital UNIXes cannot handle -Olimit ... for $lddlflags.
555 #       
556 #       * ld -s cannot be used in older Digital UNIXes when doing shared.
557 #
558 #
559 #       21-Feb-1997 Spider Boardman <spider@Orb.Nashua.NH.US>
560 #
561 #       * -hidden removed.
562 #       
563 #       * -DSTANDARD_C removed.
564 #
565 #       * -D_INTRINSICS added. (that -fast does not seem to buy much confirmed)
566 #
567 #       * odbm not in libc, only ndbm. Therefore dbm back to $libswanted.
568 #
569 #       * -msym for the newer runtime loaders.
570 #
571 #       * $optimize also in $lddflags.
572 #
573 #
574 # perl5.003_27:
575 #
576 #       18-Feb-1997 Jarkko Hietaniemi <jhi@iki.fi>
577 #
578 #       * unset _DEC_cc_style and more commentary on -std.
579 #
580 #
581 # perl5.003_26:
582 #
583 #       15-Feb-1997 Jarkko Hietaniemi <jhi@iki.fi>
584 #
585 #       * -std and -ansi.
586 #
587 #
588 # perl5.003_24:
589 #
590 #       30-Jan-1997 Jarkko Hietaniemi <jhi@iki.fi>
591 #
592 #       * Fixing the note on -DDEBUGGING.
593 #
594 #       * Note on -O5 -fast.
595 #
596 #
597 # perl5.003_23:
598 #
599 #       26-Jan-1997 Jarkko Hietaniemi <jhi@iki.fi>
600 #
601 #       * Notes on how to do both optimisation and debugging.
602 #
603 #
604 #       25-Jan-1997 Jarkko Hietaniemi <jhi@iki.fi>
605 #
606 #       * Remove unneeded libraries from $libswanted: PW, bsd, c, dbm
607 #
608 #       * Restructure the $lddlflags build.
609 #
610 #       * $optimize based on which compiler we have.
611 #
612 #
613 # perl5.003_22:
614 #
615 #       23-Jan-1997 Achim Bohnet <ach@rosat.mpe-garching.mpg.de>
616 #
617 #       * Added comments 'how to create a debugging version of perl'
618 #
619 #       * Fixed logic of this script to prevent stripping of shared
620 #         objects by the loader (see ld man page for -s) is debugging
621 #         is set via the -g switch.
622 #
623 #
624 #       21-Jan-1997 Achim Bohnet <ach@rosat.mpe-garching.mpg.de>
625 #
626 #       * now 'dl' is always removed from libswanted. Not only if
627 #         optimize is an empty string.
628 #        
629 #
630 #       17-Jan-1997 Achim Bohnet <ach@rosat.mpe-garching.mpg.de>
631 #
632 #       * Removed 'dl' from libswanted: When the FreePort binary
633 #         translator for Sun binaries is installed Configure concludes
634 #         that it should use libdl.x.yz.fpx.so :-(
635 #         Because the dlopen, dlclose,... calls are in the
636 #         C library it not necessary at all to check for the
637 #         dl library.  Therefore dl is removed from libswanted.
638 #       
639 #
640 #       1-Jan-1997 Achim Bohnet <ach@rosat.mpe-garching.mpg.de>
641 #       
642 #       * Set -Olimit to 3200 because perl_yylex.c got too big
643 #         for the optimizer.
644 #
645