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