win32 fixes: more spurious CRs
[p5sagit/p5-mst-13.2.git] / hints / hpux.sh
1 #!/usr/bin/sh
2
3 ### SYSTEM ARCHITECTURE
4
5 # Determine the architecture type of this system.
6 # Keep leading tab below -- Configure Black Magic -- RAM, 03/02/97
7         xxOsRevMajor=`uname -r | sed -e 's/^[^0-9]*//' | cut -d. -f1`;
8 if [ "$xxOsRevMajor" -ge 10 ]; then
9     # This system is running >= 10.x
10
11     # Tested on 10.01 PA1.x and 10.20 PA[12].x.
12     # Idea: Scan /usr/include/sys/unistd.h for matches with
13     # "#define CPU_* `getconf # CPU_VERSION`" to determine CPU type.
14     # Note the text following "CPU_" is used, *NOT* the comment.
15     #
16     # ASSUMPTIONS: Numbers will continue to be defined in hex -- and in
17     # /usr/include/sys/unistd.h -- and the CPU_* #defines will be kept
18     # up to date with new CPU/OS releases.
19     xxcpu=`getconf CPU_VERSION`; # Get the number.
20     xxcpu=`printf '0x%x' $xxcpu`; # convert to hex
21     archname=`sed -n -e "s/^#[ \t]*define[ \t]*CPU_//p" /usr/include/sys/unistd.h |
22         sed -n -e "s/[ \t]*$xxcpu[ \t].*//p" |
23         sed -e s/_RISC/-RISC/ -e s/HP_// -e s/_/./`;
24 else
25     # This system is running <= 9.x
26     # Tested on 9.0[57] PA and [78].0 MC680[23]0.  Idea: After removing
27     # MC6888[12] from context string, use first CPU identifier.
28     #
29     # ASSUMPTION: Only CPU identifiers contain no lowercase letters.
30     archname=`getcontext | tr ' ' '\012' | grep -v '[a-z]' | grep -v MC688 |
31         sed -e 's/HP-//' -e 1q`;
32     selecttype='int *'
33     fi
34
35 echo "Archname is $archname"
36
37
38 ### HP-UX OS specific behaviour
39
40 # -ldbm is obsolete and should not be used
41 # -lBSD contains BSD-style duplicates of SVR4 routines that cause confusion
42 # -lPW is obsolete and should not be used
43 # The libraries crypt, malloc, ndir, and net are empty.
44 set `echo "X $libswanted " | sed -e 's/ ld / /' -e 's/ dbm / /' -e 's/ BSD / /' -e 's/ PW / /'`
45 shift
46 libswanted="$*"
47
48 cc=${cc:-cc}
49 ar=/usr/bin/ar  # Yes, truly override.  We do not want the GNU ar.
50 full_ar=$ar     # I repeat, no GNU ar.  arrr.
51
52 set `echo "X $ccflags " | sed -e 's/ -A[ea] / /' -e 's/ -D_HPUX_SOURCE / /'`
53 shift
54         cc_cppflags="$* -D_HPUX_SOURCE"
55 cppflags="-Aa -D__STDC_EXT__ $cc_cppflags"
56
57 case "$prefix" in
58     "") prefix='/opt/perl5' ;;
59     esac
60
61     gnu_as=no
62     gnu_ld=no
63 case `$cc -v 2>&1`"" in
64     *gcc*)  ccisgcc="$define"
65             ccflags="$cc_cppflags"
66             if [ "X$gccversion" = "X" ]; then
67                 # Done too late in Configure if hinted
68                 gccversion=`$cc --version`
69                 fi
70             case "`getconf KERNEL_BITS 2>/dev/null`" in
71                 *64*)
72                     case "$gccversion" in
73                         3*) ccflags="$ccflags -mpa-risc-2-0"
74                             ;;
75                         *)  echo "main(){}">try.c
76                             # gcc with gas will not accept +DA2.0
77                             case "`$cc -c -Wa,+DA2.0 try.c 2>&1`" in
78                                 *"+DA2.0"*)             # gas
79                                     gnu_as=yes
80                                     ;;
81                                 *)                      # HPas
82                                     ccflags="$ccflags -Wa,+DA2.0"
83                                     ;;
84                                 esac
85                             ;;
86                         esac
87                     # gcc with gld will not accept +vnocompatwarnings
88                     case "`$cc -o try -Wl,+vnocompatwarnings try.c 2>&1`" in
89                         *"+vnocompat"*)         # gld
90                             gnu_ld=yes
91                             ;;
92                         *)                      # HPld
93                            case "$gccversion" in
94                                [12]*)
95                                    ldflags="$ldflags -Wl,+vnocompatwarnings"
96                                    ccflags="$ccflags -Wl,+vnocompatwarnings"
97                                    ;;
98                                esac
99                             ;;
100                         esac
101                     ;;
102                 esac
103             ;;
104     *)      ccisgcc=''
105             ccversion=`which cc | xargs what | awk '/Compiler/{print $2}'`
106             ccflags="-Ae $cc_cppflags -Wl,+vnocompatwarnings"
107             # Needed because cpp does only support -Aa (not -Ae)
108             cpplast='-'
109             cppminus='-'
110             cppstdin='cc -E -Aa -D__STDC_EXT__'
111             cpprun=$cppstdin
112             case "$d_casti32" in
113                 "") d_casti32='undef' ;;
114                 esac
115             ;;
116     esac
117
118 # When HP-UX runs a script with "#!", it sets argv[0] to the script name.
119 toke_cflags='ccflags="$ccflags -DARG_ZERO_IS_SCRIPT"'
120
121 ### 64 BITNESS
122
123 # Some gcc versions do native 64 bit long (e.g. 2.9-hppa-000310 and gcc-3.0)
124 # We have to force 64bitness to go search the right libraries
125     gcc_64native=no
126 case "$ccisgcc" in
127     $define|true|[Yy])
128        echo 'int main(){long l;printf("%d\\n",sizeof(l));}'>try.c
129         $cc -o try $ccflags $ldflags try.c
130         if [ "`try`" = "8" ]; then
131             cat <<EOM >&4
132
133 *** This version of gcc uses 64 bit longs. -Duse64bitall is
134 *** implicitly set to enable continuation
135 EOM
136             use64bitall=$define
137             gcc_64native=yes
138             fi
139         ;;
140     esac
141
142 case "$use64bitall" in
143     $define|true|[yY]*) use64bitint="$define" ;;
144     esac
145
146 case "$usemorebits" in
147     $define|true|[yY]*) use64bitint="$define"; uselongdouble="$define" ;;
148     esac
149
150 case "$uselongdouble" in
151     $define|true|[yY]*)
152         cat <<EOM >&4
153
154 *** long doubles are not (yet) supported on HP-UX (any version)
155 *** Until it does, we cannot continue, aborting.
156 EOM
157         exit 1 ;;
158     esac
159
160 case "$use64bitint" in
161     $define|true|[Yy])
162
163         if [ "$xxOsRevMajor" -lt 11 ]; then
164             cat <<EOM >&4
165
166 *** 64-bit compilation is not supported on HP-UX $xxOsRevMajor.
167 *** You need at least HP-UX 11.0.
168 *** Cannot continue, aborting.
169 EOM
170             exit 1
171             fi
172
173         # Set libc and the library paths
174         case "$archname" in
175             PA-RISC*)
176                 loclibpth="$loclibpth /lib/pa20_64"
177                 libc='/lib/pa20_64/libc.sl' ;;
178             IA64*) 
179                 loclibpth="$loclibpth /usr/lib/hpux64"
180                 libc='/usr/lib/hpux64/libc.so' ;;
181             esac
182         if [ ! -f "$libc" ]; then
183             cat <<EOM >&4
184
185 *** You do not seem to have the 64-bit libc.
186 *** I cannot find the file $libc.
187 *** Cannot continue, aborting.
188 EOM
189             exit 1
190             fi
191
192         case "$ccisgcc" in
193             $define|true|[Yy])
194                 # For the moment, don't care that it ain't supported (yet)
195                 # by gcc (up to and including 2.95.3), cause it'll crash
196                 # anyway. Expect auto-detection of 64-bit enabled gcc on
197                 # HP-UX soon, including a user-friendly exit
198                 case $gcc_64native in
199                     no) case "$gccversion" in
200                             [12]*)  ccflags="$ccflags -mlp64"
201                                     ldflags="$ldflags -Wl,+DD64"
202                                     ;;
203                             esac
204                         ;;
205                     esac
206                 ;;
207             *)
208                 ccflags="$ccflags +DD64"
209                 ldflags="$ldflags +DD64"
210                 ;;
211             esac
212
213         # Reset the library checker to make sure libraries
214         # are the right type
215         libscheck='case "`/usr/bin/file $xxx`" in
216                        *ELF-64*|*LP64*|*PA-RISC2.0*) ;;
217                        *) xxx=/no/64-bit$xxx ;;
218                        esac'
219
220         ;;
221
222     *)  # Not in 64-bit mode
223
224         case "$archname" in
225             PA-RISC*)
226                 libc='/lib/libc.sl' ;;
227             IA64*) 
228                 loclibpth="$loclibpth /usr/lib/hpux32"
229                 libc='/usr/lib/hpux32/libc.so' ;;
230             esac
231         ;;
232     esac
233
234 # By setting the deferred flag below, this means that if you run perl
235 # on a system that does not have the required shared library that you
236 # linked it with, it will die when you try to access a symbol in the
237 # (missing) shared library.  If you would rather know at perl startup
238 # time that you are missing an important shared library, switch the
239 # comments so that immediate, rather than deferred loading is
240 # performed.  Even with immediate loading, you can postpone errors for
241 # undefined (or multiply defined) routines until actual access by
242 # adding the "nonfatal" option.
243 # ccdlflags="-Wl,-E -Wl,-B,immediate $ccdlflags"
244 # ccdlflags="-Wl,-E -Wl,-B,immediate,-B,nonfatal $ccdlflags"
245 if [ "$gnu_ld" = "yes" ]; then
246     ccdlflags="-Wl,-E $ccdlflags"
247 else
248     ccdlflags="-Wl,-E -Wl,-B,deferred $ccdlflags"
249     fi
250
251
252 ### COMPILER SPECIFICS
253
254 ## Local restrictions (point to README.hpux to lift these)
255
256 ## Optimization limits
257 cat >try.c <<EOF
258 #include <sys/resource.h>
259
260 int main ()
261 {
262     struct rlimit rl;
263     int i = getrlimit (RLIMIT_DATA, &rl);
264     printf ("%d\n", rl.rlim_cur / (1024 * 1024));
265     } /* main */
266 EOF
267 $cc -o try $ccflags $ldflags try.c
268         maxdsiz=`try`
269 if [ $maxdsiz -le 64 ]; then
270     # 64 Mb is probably not enough to optimize toke.c
271     # and regexp.c with -O2
272     cat <<EOM >&4
273 Your kernel limits the data section of your programs to $maxdsiz Mb,
274 which is (sadly) not enough to fully optimize some parts of the
275 perl binary. I'll try to use a lower optimization level for
276 those parts. If you are a sysadmin, and you *do* want full
277 optimization, raise the 'maxdsiz' kernel configuration parameter
278 to at least 0x08000000 (128 Mb) and rebuild your kernel.
279 EOM
280 regexec_cflags=''
281     fi
282
283 case "$ccisgcc" in
284     $define|true|[Yy])
285         
286         case "$optimize" in
287             "")           optimize="-g -O" ;;
288             *O[3456789]*) optimize=`echo "$optimize" | sed -e 's/O[3-9]/O2/'` ;;
289             esac
290         #ld="$cc"
291         ld=/usr/bin/ld
292         cccdlflags='-fPIC'
293         #lddlflags='-shared'
294         lddlflags='-b'
295         case "$optimize" in
296             *-g*-O*|*-O*-g*)
297                 # gcc without gas will not accept -g
298                 echo "main(){}">try.c
299                 case "`$cc $optimize -c try.c 2>&1`" in
300                     *"-g option disabled"*)
301                         set `echo "X $optimize " | sed -e 's/ -g / /'`
302                         shift
303                         optimize="$*"
304                         ;;
305                     esac
306                 ;;
307             esac
308         if [ $maxdsiz -le 64 ]; then
309             case "$optimize" in
310                 *O2*)   opt=`echo "$optimize" | sed -e 's/O2/O1/'`
311                         toke_cflags="$toke_cflags;optimize=\"$opt\""
312                         regexec_cflags="optimize=\"$opt\""
313                         ;;
314                 esac
315             fi
316         ;;
317
318     *)  # HP's compiler cannot combine -g and -O
319         case "$optimize" in
320             "")           optimize="+O2 +Onolimit" ;;
321             *O[3456789]*) optimize=`echo "$optimize" | sed -e 's/O[3-9]/O2/'` ;;
322             esac
323         if [ $maxdsiz -le 64 ]; then
324             case "$optimize" in
325                 *-O*|\
326                 *O2*)   opt=`echo "$optimize" | sed -e 's/-O/+O2/' -e 's/O2/O1/' -e 's/ *+Onolimit//'`
327                         toke_cflags="$toke_cflags;optimize=\"$opt\""
328                         regexec_cflags="optimize=\"$opt\""
329                         ;;
330                 esac
331             fi
332         ld=/usr/bin/ld
333         cccdlflags='+Z'
334         lddlflags='-b +vnocompatwarnings'
335         ;;
336     esac
337
338 ## LARGEFILES
339
340 #case "$uselargefiles-$ccisgcc" in
341 #    "$define-$define"|'-define') 
342 #       cat <<EOM >&4
343 #
344 #*** I'm ignoring large files for this build because
345 #*** I don't know how to do use large files in HP-UX using gcc.
346 #
347 #EOM
348 #       uselargefiles="$undef"
349 #       ;;
350 #    esac
351
352 cat >UU/uselargefiles.cbu <<'EOCBU'
353 # This script UU/uselargefiles.cbu will get 'called-back' by Configure 
354 # after it has prompted the user for whether to use large files.
355 case "$uselargefiles" in
356     ""|$define|true|[yY]*)
357         # there are largefile flags available via getconf(1)
358         # but we cheat for now.  (Keep that in the left margin.)
359 ccflags_uselargefiles="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
360
361         ccflags="$ccflags $ccflags_uselargefiles"
362
363         if test -z "$ccisgcc" -a -z "$gccversion"; then
364             # The strict ANSI mode (-Aa) doesn't like large files.
365             ccflags=`echo " $ccflags "|sed 's@ -Aa @ @g'`
366             case "$ccflags" in
367                 *-Ae*) ;;
368                 *)     ccflags="$ccflags -Ae" ;;
369                 esac
370             fi
371         ;;
372     esac
373 EOCBU
374
375 # THREADING
376
377 # This script UU/usethreads.cbu will get 'called-back' by Configure 
378 # after it has prompted the user for whether to use threads.
379 cat >UU/usethreads.cbu <<'EOCBU'
380 case "$usethreads" in
381     $define|true|[yY]*)
382         if [ "$xxOsRevMajor" -lt 10 ]; then
383             cat <<EOM >&4
384
385 HP-UX $xxOsRevMajor cannot support POSIX threads.
386 Consider upgrading to at least HP-UX 11.
387 Cannot continue, aborting.
388 EOM
389             exit 1
390             fi
391
392         if [ "$xxOsRevMajor" -eq 10 ]; then
393             # Under 10.X, a threaded perl can be built
394             if [ -f /usr/include/pthread.h ]; then
395                 if [ -f /usr/lib/libcma.sl ]; then
396                     # DCE (from Core OS CD) is installed
397
398                     # It needs # libcma and OLD_PTHREADS_API. Also
399                     # <pthread.h> needs to be #included before any
400                     # other includes (in perl.h)
401
402                     # HP-UX 10.X uses the old pthreads API
403                     d_oldpthreads="$define"
404
405                     # include libcma before all the others
406                     libswanted="cma $libswanted"
407
408                     # tell perl.h to include <pthread.h> before other
409                     # include files
410                     ccflags="$ccflags -DPTHREAD_H_FIRST"
411
412                     # CMA redefines select to cma_select, and cma_select
413                     # expects int * instead of fd_set * (just like 9.X)
414                     selecttype='int *'
415
416                 elif [ -f /usr/lib/libpthread.sl ]; then
417                     # PTH package is installed
418                     libswanted="pthread $libswanted"
419                 else
420                     libswanted="no_threads_available"
421                     fi
422             else
423                 libswanted="no_threads_available"
424                 fi
425
426             if [ $libswanted = "no_threads_available" ]; then
427                 cat <<EOM >&4
428
429 In HP-UX 10.X for POSIX threads you need both of the files
430 /usr/include/pthread.h and either /usr/lib/libcma.sl or /usr/lib/libpthread.sl.
431 Either you must upgrade to HP-UX 11 or install a posix thread library:
432
433     DCE-CoreTools from HP-UX 10.20 Hardware Extensions 3.0 CD (B3920-13941)
434
435 or
436
437     PTH package from e.g. http://hpux.tn.tudelft.nl/hppd/hpux/alpha.html
438
439 Cannot continue, aborting.
440 EOM
441                 exit 1
442                 fi
443         else
444             # 12 may want upping the _POSIX_C_SOURCE datestamp...
445             ccflags=" -D_POSIX_C_SOURCE=199506L $ccflags"
446             set `echo X "$libswanted "| sed -e 's/ c / pthread c /'`
447             shift
448             libswanted="$*"
449             fi
450
451         usemymalloc='n'
452         ;;
453     esac
454 EOCBU