AIX and gcc (moving targets)
[p5sagit/p5-mst-13.2.git] / hints / aix.sh
1 # hints/aix.sh
2 # AIX 3.x.x hints thanks to Wayne Scott <wscott@ichips.intel.com>
3 # AIX 4.1 hints thanks to Christopher Chan-Nui <channui@austin.ibm.com>.
4 # AIX 4.1 pthreading by Christopher Chan-Nui <channui@austin.ibm.com> and
5 #         Jarkko Hietaniemi <jhi@iki.fi>.
6 # AIX 4.3.x LP64 build by Steven Hirsch <hirschs@btv.ibm.com>
7 # Merged on Mon Feb  6 10:22:35 EST 1995 by
8 #   Andy Dougherty  <doughera@lafcol.lafayette.edu>
9
10 #
11 # Contact dfavor@corridor.com for any of the following:
12 #
13 #    - AIX 43x and above support
14 #    - gcc + threads support
15 #    - socks support
16 #
17 # Apr 99 changes:
18 #
19 #    - use nm in AIX 43x and above
20 #    - gcc + threads now builds
21 #    [(added support for socks) Jul 99 SOCKS support rewritten]
22 #
23 # Notes:
24 #
25 #    - shared libperl support is tricky. if ever libperl.a ends up
26 #      in /usr/local/lib/* it can override any subsequent builds of
27 #      that same perl release. to make sure you know where the shared
28 #      libperl.a is coming from do a 'dump -Hv perl' and check all the
29 #      library search paths in the loader header.
30 #
31 #      it would be nice to warn the user if a libperl.a exists that is
32 #      going to override the current build, but that would be complex.
33 #
34 #      better yet, a solid fix for this situation should be developed.
35 #
36
37 # Configure finds setrgid and setruid, but they're useless.  The man
38 # pages state:
39 #    setrgid: The EPERM error code is always returned.
40 #    setruid: The EPERM error code is always returned. Processes cannot
41 #             reset only their real user IDs.
42 d_setrgid='undef'
43 d_setruid='undef'
44
45 alignbytes=8
46
47 case "$usemymalloc" in
48 '')  usemymalloc='n' ;;
49 esac
50
51 # Intuiting the existence of system calls under AIX is difficult,
52 # at best; the safest technique is to find them empirically.
53
54 # AIX 4.3.* and above default to using nm for symbol extraction
55 case "$osvers" in
56    3.*|4.1.*|4.2.*)
57       usenm='undef'
58       ;;
59    *)
60       usenm='true'
61       ;;
62 esac
63
64 so="a"
65 # AIX itself uses .o (libc.o) but we prefer compatibility
66 # with the rest of the world and with rest of the scripting
67 # languages (Tcl, Python) and related systems (SWIG).
68 # Stephanie Beals <bealzy@us.ibm.com>
69 dlext="so"
70
71 # Take possible hint from the environment.  If 32-bit is set in the
72 # environment, we can override it later.  If set for 64, the
73 # 'sizeof' test sees a native 64-bit architecture and never looks back.
74 case "$OBJECT_MODE" in
75 32)
76     cat >&4 <<EOF
77
78 You have OBJECT_MODE=32 set in the environment. 
79 I take this as a hint you do not want to
80 build for a 64-bit address space. You will be
81 given the opportunity to change this later.
82 EOF
83     ;;
84 64)
85     cat >&4 <<EOF
86
87 You have OBJECT_MODE=64 set in the environment. 
88 This forces a full 64-bit build.  If that is
89 not what you intended, please terminate this
90 program, unset it and restart.
91 EOF
92     ;;
93 *)  ;;
94 esac
95
96 # Trying to set this breaks the POSIX.c compilation
97
98 # Make setsockopt work correctly.  See man page.
99 # ccflags='-D_BSD=44'
100
101 # uname -m output is too specific and not appropriate here
102 case "$archname" in
103 '') archname="$osname" ;;
104 esac
105
106 cc=${cc:-cc}
107
108 case "$osvers" in
109 3*) d_fchmod=undef
110     ccflags="$ccflags -D_ALL_SOURCE"
111     ;;
112 *)  # These hints at least work for 4.x, possibly other systems too.
113     ccflags="$ccflags -D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE"
114     case "$cc" in
115      *gcc*) ;;
116      *) ccflags="$ccflags -qmaxmem=16384" ;;
117     esac
118     nm_opt='-B'
119     ;;
120 esac
121
122 # These functions don't work like Perl expects them to.
123 d_setregid='undef'
124 d_setreuid='undef'
125
126 # Changes for dynamic linking by Wayne Scott <wscott@ichips.intel.com>
127 #
128 # Tell perl which symbols to export for dynamic linking.
129 cccdlflags='none'      # All AIX code is position independent
130 case "$cc" in
131 *gcc*) ccdlflags='-Xlinker' ;;
132 *) ccversion=`lslpp -L | grep 'C for AIX Compiler$' | awk '{print $2}'`
133    case "$ccversion" in
134      '') ccversion=`lslpp -L | grep 'IBM C and C++ Compilers LUM$' | awk '{print $2}'`
135         ;;
136      esac
137    case "$ccversion" in
138      3.6.6.0)
139         optimize='none'
140         ;;
141      4.4.0.0|4.4.0.1|4.4.0.2)
142         cat >&4 <<EOF
143 ***
144 *** This C compiler ($ccversion) is outdated.
145 ***
146 *** Please upgrade to at least 4.4.0.3.
147 ***
148 EOF
149         ;;
150      5.0.0.0)
151         cat >&4 <<EOF
152 ***
153 *** This C compiler ($ccversion) is known to have optimizer problems
154 *** when compiling perl.c.
155 ***
156 *** Disabling optimization for that file but consider upgrading
157 *** your C compiler.
158 ***
159 EOF
160 perl_cflags='optimize='
161         ;;
162      5.0.1.0)
163         cat >&4 <<EOF
164 ***
165 *** This C compiler ($ccversion) is known to have optimizer problems
166 *** when compiling regcomp.c.
167 ***
168 *** Disabling optimization for that file but consider upgrading
169 *** your C compiler.
170 ***
171 EOF
172 regcomp_cflags='optimize='
173         ;;
174      esac
175 esac
176 # the required -bE:$installarchlib/CORE/perl.exp is added by
177 # libperl.U (Configure) later.
178
179 case "$ldlibpthname" in
180 '') ldlibpthname=LIBPATH ;;
181 esac
182
183 # The first 3 options would not be needed if dynamic libs. could be linked
184 # with the compiler instead of ld.
185 # -bI:$(PERL_INC)/perl.exp  Read the exported symbols from the perl binary
186 # -bE:$(BASEEXT).exp        Export these symbols.  This file contains only one
187 #                           symbol: boot_$(EXP)  can it be auto-generated?
188 case "$osvers" in
189 3*) 
190     lddlflags="$lddlflags -H512 -T512 -bhalt:4 -bM:SRE -bI:\$(PERL_INC)/perl.exp -bE:\$(BASEEXT).exp -e _nostart -lc"
191     ;;
192 *) 
193     lddlflags="$lddlflags -bhalt:4 -bM:SRE -bI:\$(PERL_INC)/perl.exp -bE:\$(BASEEXT).exp -b noentry -lc"
194     ;;
195 esac
196 # AIX 4.2 (using latest patchlevels on 20001130) has a broken bind
197 # library (getprotobyname and getprotobynumber are outversioned by
198 # the same calls in libc, at least for xlc version 3...
199 case "`oslevel`" in
200     4.2.1.*)  # Test for xlc version too, should we?
201       case "$ccversion" in    # Don't know if needed for gcc
202           3.1.4.*)    # libswanted "bind ... c ..." => "... c bind ..."
203               set `echo X "$libswanted "| sed -e 's/ bind\( .*\) \([cC]\) / \1 \2 bind /'`
204               shift
205               libswanted="$*"
206               ;;
207           esac
208       ;;
209     esac
210
211 # This script UU/usethreads.cbu will get 'called-back' by Configure 
212 # after it has prompted the user for whether to use threads.
213 cat > UU/usethreads.cbu <<'EOCBU'
214 case "$usethreads" in
215 $define|true|[yY]*)
216         ccflags="$ccflags -DNEED_PTHREAD_INIT"
217         case "$cc" in
218         gcc) ;;
219         cc_r) ;;
220         cc|xl[cC]_r) 
221             echo >&4 "Switching cc to cc_r because of POSIX threads."
222             # xlc_r has been known to produce buggy code in AIX 4.3.2.
223             # (e.g. pragma/overload core dumps)  Let's suspect xlC_r, too.
224             # --jhi@iki.fi
225             cc=cc_r
226             ;;
227         '') 
228             cc=cc_r
229             ;;
230         *)
231             cat >&4 <<EOM
232 *** For pthreads you should use the AIX C compiler cc_r.
233 *** (now your compiler was set to '$cc')
234 *** Cannot continue, aborting.
235 EOM
236             exit 1
237             ;;
238         esac
239
240         # c_rify libswanted.
241         set `echo X "$libswanted "| sed -e 's/ \([cC]\) / \1_r /g'`
242         shift
243         libswanted="$*"
244         # c_rify lddlflags.
245         set `echo X "$lddlflags "| sed -e 's/ \(-l[cC]\) / \1_r /g'`
246         shift
247         lddlflags="$*"
248
249         # Insert pthreads to libswanted, before any libc or libC.
250         set `echo X "$libswanted "| sed -e 's/ \([cC]\) / pthreads \1 /'`
251         shift
252         libswanted="$*"
253         # Insert pthreads to lddlflags, before any libc or libC.
254         set `echo X "$lddlflags " | sed -e 's/ \(-l[cC]\) / -lpthreads \1 /'`
255         shift
256         lddlflags="$*"
257
258         ;;
259 esac
260 EOCBU
261
262 # This script UU/uselargefiles.cbu will get 'called-back' by Configure 
263 # after it has prompted the user for whether to use large files.
264 cat > UU/uselargefiles.cbu <<'EOCBU'
265 case "$uselargefiles" in
266 ''|$define|true|[yY]*)
267 # Keep these at the left margin.
268 ccflags_uselargefiles="`getconf XBS5_ILP32_OFFBIG_CFLAGS 2>/dev/null`"
269 ldflags_uselargefiles="`getconf XBS5_ILP32_OFFBIG_LDFLAGS 2>/dev/null`"
270         # _Somehow_ in AIX 4.3.1.0 the above getconf call manages to
271         # insert(?) *something* to $ldflags so that later (in Configure) evaluating
272         # $ldflags causes a newline after the '-b64' (the result of the getconf).
273         # (nothing strange shows up in $ldflags even in hexdump;
274         #  so it may be something (a bug) in the shell, instead?)
275         # Try it out: just uncomment the below line and rerun Configure:
276 # echo >&4 "AIX 4.3.1.0 $ldflags_uselargefiles mystery" ; exit 1
277         # Just don't ask me how AIX does it, I spent hours wondering.
278         # Therefore the line re-evaluating ldflags_uselargefiles: it seems to fix
279         # the whatever it was that AIX managed to break. --jhi
280         ldflags_uselargefiles="`echo $ldflags_uselargefiles`"
281 # Keep this at the left margin.
282 libswanted_uselargefiles="`getconf XBS5_ILP32_OFFBIG_LIBS 2>/dev/null|sed -e 's@^-l@@' -e 's@ -l@ @g`"
283         case "$ccflags_uselargefiles$ldflags_uselargefiles$libs_uselargefiles" in
284         '');;
285         *) ccflags="$ccflags $ccflags_uselargefiles"
286            ldflags="$ldflags $ldflags_uselargefiles"
287            libswanted="$libswanted $libswanted_uselargefiles"
288            ;;
289         esac
290         case "$gccversion" in
291         '') ;;
292         *)
293         cat >&4 <<EOM
294
295 *** Warning: gcc in AIX might not work with the largefile support of Perl
296 *** (default since 5.6.0), this combination hasn't been tested.
297 *** I will try, though.
298
299 EOM
300         # Remove xlc-spefific -qflags.
301         ccflags="`echo $ccflags | sed -e 's@ -q[^ ]*@ @g' -e 's@^-q[^ ]* @@g'`"
302         ldflags="`echo $ldflags | sed -e 's@ -q[^ ]*@ @g' -e 's@^-q[^ ]* @@g'`"
303         # Move xld-spefific -bflags.
304         ccflags="`echo $ccflags | sed -e 's@ -b@ -Wl,-b@g'`"
305         ldflags="`echo $ldflags | sed -e 's@ -b@ -Wl,-b@g'`"
306         echo >&4 "(using ccflags $ccflags)"
307         echo >&4 "(using ldflags $ldflags)"
308         ;; 
309         esac
310         ;;
311 esac
312 EOCBU
313
314 # This script UU/use64bitint.cbu will get 'called-back' by Configure 
315 # after it has prompted the user for whether to use 64 bit integers.
316 cat > UU/use64bitint.cbu <<'EOCBU'
317 case "$use64bitint" in
318 $define|true|[yY]*)
319             case "`oslevel`" in
320             3.*|4.[012].*)
321                 cat >&4 <<EOM
322 AIX `oslevel` does not support 64-bit interfaces.
323 You should upgrade to at least AIX 4.3.
324 EOM
325                 exit 1
326                 ;;
327             esac
328             ;;
329 esac
330 EOCBU
331
332 cat > UU/use64bitall.cbu <<'EOCBU'
333 # This script UU/use64bitall.cbu will get 'called-back' by Configure 
334 # after it has prompted the user for whether to be maximally 64-bitty.
335 case "$use64bitall" in
336 $define|true|[yY]*)
337             case "`oslevel`" in
338             3.*|4.[012].*)
339                 cat >&4 <<EOM
340 AIX `oslevel` does not support 64-bit interfaces.
341 You should upgrade to at least AIX 4.3.
342 EOM
343                 exit 1
344                 ;;
345             esac
346             echo " "
347             echo "Checking the CPU width of your hardware..." >&4
348             $cat >size.c <<EOCP
349 #include <stdio.h>
350 #include <sys/systemcfg.h>
351 int main (void)
352 {
353   printf("%d\n",_system_configuration.width);
354   return(0);
355 }
356 EOCP
357             set size
358             if eval $compile_ok; then
359                 qacpuwidth=`./size`
360                 echo "You are running on $qacpuwidth bit hardware."
361             else
362                 dflt="32"
363                 echo " "
364                 echo "(I can't seem to compile the test program.  Guessing...)"
365                 rp="What is the width of your CPU (in bits)?"
366                 . ./myread
367                 qacpuwidth="$ans"
368             fi
369             $rm -f size.c size
370             case "$qacpuwidth" in
371             32*)
372                 cat >&4 <<EOM
373 Bzzzt! At present, you can only perform a
374 full 64-bit build on a 64-bit machine.
375 EOM
376                 exit 1
377                 ;;
378             esac
379             qacflags="`getconf XBS5_LP64_OFF64_CFLAGS 2>/dev/null`"
380             qaldflags="`getconf XBS5_LP64_OFF64_LDFLAGS 2>/dev/null`"
381             # See jhi's comments above regarding this re-eval.  I've
382             # seen similar weirdness in the form of:
383             #
384 # 1506-173 (W) Option lm is not valid.  Enter xlc for list of valid options.
385             #
386             # error messages from 'cc -E' invocation. Again, the offending
387             # string is simply not detectable by any means.  Since it doesn't
388             # do any harm, I didn't pursue it. -- sh
389             qaldflags="`echo $qaldflags`"
390             qalibs="`getconf XBS5_LP64_OFF64_LIBS 2>/dev/null|sed -e 's@^-l@@' -e 's@ -l@ @g`"
391             # -q32 and -b32 may have been set by uselargefiles or user.
392             # Remove them.
393             ccflags="`echo $ccflags | sed -e 's@-q32@@'`"
394             ldflags="`echo $ldflags | sed -e 's@-b32@@'`"
395             # Tell archiver to use large format.  Unless we remove 'ar'
396             # from 'trylist', the Configure script will just reset it to 'ar'
397             # immediately prior to writing config.sh.  This took me hours
398             # to figure out.
399             trylist="`echo $trylist | sed -e 's@^ar @@' -e 's@ ar @ @g' -e 's@ ar$@@'`"
400             ar="ar -X64"
401             nm_opt="-X64 $nm_opt"
402             # Note: Placing the 'qacflags' variable into the 'ldflags' string
403             # is NOT a typo.  ldflags is passed to the C compiler for final
404             # linking, and it wants -q64 (-b64 is for ld only!).
405             case "$qacflags$qaldflags$qalibs" in
406             '');;
407             *) ccflags="$ccflags $qacflags"
408                ldflags="$ldflags $qacflags"
409                lddlflags="$qaldflags $lddlflags"
410                libswanted="$libswanted $qalibs"
411                ;;
412             esac
413             case "$ccflags" in
414             *-DUSE_64_BIT_ALL*) ;;
415             *) ccflags="$ccflags -DUSE_64_BIT_ALL";;
416             esac
417             case "$archname64" in
418             ''|64*) archname64=64all ;;
419             esac
420             longsize="8"
421             # Don't try backwards compatibility
422             bincompat="$undef"
423             d_bincompat5005="$undef"
424             qacflags=''
425             qaldflags=''
426             qalibs=''
427             qacpuwidth=''
428             ;;
429 esac
430 EOCBU
431
432 cat > UU/uselongdouble.cbu <<'EOCBU'
433 # This script UU/uselongdouble.cbu will get 'called-back' by Configure 
434 # after it has prompted the user for whether to use long doubles.
435 case "$uselongdouble" in
436 $define|true|[yY]*)
437         # -qlongdouble for cc taken out on 20010522 cause it
438         # causes more trouble than it does any good --hmb
439         d_Gconvert='sprintf((b),"%.*llg",((int)(n)),(x))'
440         ;;
441 esac
442 EOCBU
443
444 # If the C++ libraries, libC and libC_r, are available we will prefer them
445 # over the vanilla libc, because the libC contain loadAndInit() and
446 # terminateAndUnload() which work correctly with C++ statics while libc
447 # load() and unload() do not.  See ext/DynaLoader/dl_aix.xs.
448 # The C-to-C_r switch is done by usethreads.cbu, if needed.
449 if test -f /lib/libC.a -a X"`$cc -v 2>&1 | grep gcc`" = X; then
450     # Cify libswanted.
451     set `echo X "$libswanted "| sed -e 's/ c / C c /'`
452     shift
453     libswanted="$*"
454     # Cify lddlflags.
455     set `echo X "$lddlflags "| sed -e 's/ -lc / -lC -lc /'`
456     shift
457     lddlflags="$*"
458 fi
459
460 # EOF