File::Basename docs
[p5sagit/p5-mst-13.2.git] / hints / aix.sh
1 # hints/aix.sh
2
3 # AIX 3 and AIX 4 are split off to aix_3.sh and aix_4.sh
4 #    early Feb 2004 by H.Merijn Brand
5 # please read comments in there for historic questions.
6 #    many now stripped here
7
8 # Contact dfavor@corridor.com for any of the following:
9 #
10 #    - AIX 43x and above support
11 #    - gcc + threads support
12 #    - socks support
13 #
14 # Notes:
15 #
16 #    - shared libperl support is tricky. if ever libperl.a ends up
17 #      in /usr/local/lib/* it can override any subsequent builds of
18 #      that same perl release. to make sure you know where the shared
19 #      libperl.a is coming from do a 'dump -Hv perl' and check all the
20 #      library search paths in the loader header.
21 #
22 #      it would be nice to warn the user if a libperl.a exists that is
23 #      going to override the current build, but that would be complex.
24 #
25 #      better yet, a solid fix for this situation should be developed.
26 #
27
28 # Configure finds setrgid and setruid, but they're useless.  The man
29 # pages state:
30 #    setrgid: The EPERM error code is always returned.
31 #    setruid: The EPERM error code is always returned. Processes cannot
32 #             reset only their real user IDs.
33 d_setrgid='undef'
34 d_setruid='undef'
35
36 alignbytes=8
37
38 case "$usemymalloc" in
39     '')  usemymalloc='n' ;;
40     esac
41
42 # malloc wrap works, but not in vac-5, see later
43 case "$usemallocwrap" in
44     '') usemallocwrap='define' ;;
45     esac
46
47 # Intuiting the existence of system calls under AIX is difficult,
48 # at best; the safest technique is to find them empirically.
49
50 case "$usenativedlopen" in
51     '') usenativedlopen='true' ;;
52     esac
53
54 so="a"
55 # AIX itself uses .o (libc.o) but we prefer compatibility
56 # with the rest of the world and with rest of the scripting
57 # languages (Tcl, Python) and related systems (SWIG).
58 # Stephanie Beals <bealzy@us.ibm.com>
59 dlext="so"
60
61 # Take possible hint from the environment.  If 32-bit is set in the
62 # environment, we can override it later.  If set for 64, the
63 # 'sizeof' test sees a native 64-bit architecture and never looks back.
64 case "$OBJECT_MODE" in
65     32) cat >&4 <<EOF
66
67 You have OBJECT_MODE=32 set in the environment.
68 I take this as a hint you do not want to
69 build for a 64-bit address space. You will be
70 given the opportunity to change this later.
71 EOF
72         ;;
73     64) cat >&4 <<EOF
74
75 You have OBJECT_MODE=64 set in the environment.
76 This forces a full 64-bit build.  If that is
77 not what you intended, please terminate this
78 program, unset it and restart.
79 EOF
80         ;;
81     esac
82
83 # uname -m output is too specific and not appropriate here
84 case "$archname" in
85     '') archname="$osname" ;;
86     esac
87
88 cc=${cc:-cc}
89
90 ccflags="$ccflags -D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE"
91 case "$cc" in
92     *gcc*) ;;
93     *) ccflags="$ccflags -qmaxmem=-1 -qnoansialias" ;;
94     esac
95 nm_opt='-B'
96
97 # These functions don't work like Perl expects them to.
98 d_setregid='undef'
99 d_setreuid='undef'
100
101 # Changes for dynamic linking by Wayne Scott <wscott@ichips.intel.com>
102 #
103 # Tell perl which symbols to export for dynamic linking.
104 cccdlflags='none'       # All AIX code is position independent
105    cc_type=xlc          # do not export to config.sh
106 case "$cc" in
107     *gcc*)
108         cc_type=gcc
109         ccdlflags='-Xlinker'
110         if [ "X$gccversion" = "X" ]; then
111             # Done too late in Configure if hinted
112             gccversion=`$cc --version | sed 's/.*(GCC) *//'`
113             fi
114         ;;
115
116     *)  ccversion=`lslpp -L | grep 'C for AIX Compiler$' | grep -v '\.msg\.[A-Za-z_]*\.' | head -1 | awk '{print $1,$2}'`
117         case "$ccversion" in
118             '') ccversion=`lslpp -L | grep 'IBM C and C++ Compilers LUM$'` ;;
119
120             *.*.*.*.*.*.*)      # Ahhrgg, more than one C compiler installed
121                 first_cc_path=`which ${cc:-cc}`
122                 case "$first_cc_path" in
123                     *vac*)
124                         cc_type=vac ;;
125
126                     /usr/bin/cc)                # Check the symlink
127                         if [ -h $first_cc_path ] ; then
128                             ls -l $first_cc_path > reflect
129                             if grep -i vac reflect >/dev/null 2>&1 ; then
130                                 cc_type=vac
131                                 fi
132                             rm -f reflect
133                             fi
134                         ;;
135                     esac
136                 ccversion=`lslpp -L | grep 'C for AIX Compiler$' | grep -i $cc_type | head -1`
137                 ;;
138
139             vac*.*.*.*)
140                 cc_type=vac
141                 ;;
142             esac
143
144         ccversion=`echo "$ccversion" | awk '{print $2}'`
145         # Redbooks state AIX-5 only supports vac-5.0.2.0 and up
146         case "$ccversion" in
147             5*) usemallocwrap='n' ;; # panic in miniperl
148             esac
149         ;;
150     esac
151
152 # the required -bE:$installarchlib/CORE/perl.exp is added by
153 # libperl.U (Configure) later.
154
155 # The first 3 options would not be needed if dynamic libs. could be linked
156 # with the compiler instead of ld.
157 # -bI:$(PERL_INC)/perl.exp  Read the exported symbols from the perl binary
158 # -bE:$(BASEEXT).exp        Export these symbols.  This file contains only one
159 #                           symbol: boot_$(EXP)  can it be auto-generated?
160 lddlflags="$lddlflags -bhalt:4 -bM:SRE -bI:\$(PERL_INC)/perl.exp -bE:\$(BASEEXT).exp -bnoentry -lc"
161
162 case "$use64bitall" in
163     $define|true|[yY]*) use64bitint="$define" ;;
164     esac
165
166 case "$usemorebits" in
167     $define|true|[yY]*) use64bitint="$define"; uselongdouble="$define" ;;
168     esac
169
170 case $cc_type in
171     vac|xlc)
172         case "$uselongdouble" in
173             $define|true|[yY]*)
174                 ccflags="$ccflags -qlongdouble"
175                 libswanted="c128 $libswanted"
176                 lddlflags=`echo "$lddlflags " | sed -e 's/ -lc / -lc128 -lc /'`
177                 ;;
178             esac
179         ;;
180     esac
181
182 case "$cc" in
183     *gcc*) ;;
184
185     cc*|xlc*) # cc should've been set by line 116 or so if empty.
186         if test ! -x /usr/bin/$cc -a -x /usr/vac/bin/$cc; then
187             case ":$PATH:" in
188                 *:/usr/vac/bin:*) ;;
189                 *)  if test ! -x /QOpenSys/usr/bin/$cc; then
190                         # The /QOpenSys/usr/bin/$cc saves us if we are
191                         # building natively in OS/400 PASE.
192                         cat >&4 <<EOF
193
194 ***
195 *** You either implicitly or explicitly specified an IBM C compiler,
196 *** but you do not seem to have one in /usr/bin, but you seem to have
197 *** the VAC installed in /usr/vac, but you do not have the /usr/vac/bin
198 *** in your PATH.  I suggest adding that and retrying Configure.
199 ***
200 EOF
201                         exit 1
202                         fi
203                     ;;
204                 esac
205             fi
206         ;;
207     esac
208
209 case "$ldlibpthname" in
210     '') ldlibpthname=LIBPATH ;;
211     esac
212
213 # This script UU/usethreads.cbu will get 'called-back' by Configure
214 # after it has prompted the user for whether to use threads.
215 cat > UU/usethreads.cbu <<'EOCBU'
216 case "$usethreads" in
217     $define|true|[yY]*)
218         d_drand48_r='undef'
219         d_endgrent_r='undef'
220         d_endpwent_r='undef'
221         d_getgrent_r='undef'
222         d_getpwent_r='undef'
223         d_random_r='undef'
224         d_setgrent_r='undef'
225         d_setpwent_r='undef'
226         d_srand48_r='undef'
227         d_strerror_r='undef'
228
229         ccflags="$ccflags -DNEED_PTHREAD_INIT"
230         case "$cc" in
231             *gcc*) ccflags="-D_THREAD_SAFE $ccflags" ;;
232
233             cc_r) ;;
234             cc|xl[cC]|xl[cC]_r)
235                 echo >&4 "Switching cc to cc_r because of POSIX threads."
236                 # xlc_r has been known to produce buggy code in AIX 4.3.2.
237                 # (e.g. pragma/overload core dumps)      Let's suspect xlC_r, too.
238                 # --jhi@iki.fi
239                 cc=cc_r
240                 ;;
241
242             '') cc=cc_r ;;
243
244             *)
245                 cat >&4 <<EOM
246 *** For pthreads you should use the AIX C compiler cc_r.
247 *** (now your compiler was set to '$cc')
248 *** Cannot continue, aborting.
249 EOM
250                 exit 1
251                 ;;
252             esac
253
254         # Insert pthreads to libswanted, before any libc or libC.
255         set `echo X "$libswanted "| sed -e 's/ \([cC]\) / pthreads \1 /'`
256         shift
257         libswanted="$*"
258         # Insert pthreads to lddlflags, before any libc or libC.
259         set `echo X "$lddlflags " | sed -e 's/ \(-l[cC]\) / -lpthreads \1 /'`
260         shift
261         lddlflags="$*"
262         ;;
263 esac
264 EOCBU
265
266 # This script UU/uselargefiles.cbu will get 'called-back' by Configure
267 # after it has prompted the user for whether to use large files.
268 cat > UU/uselargefiles.cbu <<'EOCBU'
269 case "$uselargefiles" in
270     ''|$define|true|[yY]*)
271         # Configure should take care of use64bitint and use64bitall being
272         # defined before uselargefiles.cbu is consulted.
273         if test X"$use64bitint:$quadtype" = X"$define:long" -o X"$use64bitall" = Xdefine; then
274 # Keep these at the left margin.
275 ccflags_uselargefiles="`getconf XBS5_LP64_OFF64_CFLAGS 2>/dev/null`"
276 ldflags_uselargefiles="`getconf XBS5_LP64_OFF64_LDFLAGS 2>/dev/null`"
277         else
278 # Keep these at the left margin.
279 ccflags_uselargefiles="`getconf XBS5_ILP32_OFFBIG_CFLAGS 2>/dev/null`"
280 ldflags_uselargefiles="`getconf XBS5_ILP32_OFFBIG_LDFLAGS 2>/dev/null`"
281             fi
282         if test X"$use64bitint:$quadtype" = X"$define:long" -o X"$use64bitall" = Xdefine; then
283 # Keep this at the left margin.
284 libswanted_uselargefiles="`getconf XBS5_LP64_OFF64_LIBS 2>/dev/null|sed -e 's@^-l@@' -e 's@ -l@ @g`"
285         else
286 # Keep this at the left margin.
287 libswanted_uselargefiles="`getconf XBS5_ILP32_OFFBIG_LIBS 2>/dev/null|sed -e 's@^-l@@' -e 's@ -l@ @g`"
288             fi
289
290         case "$ccflags_uselargefiles$ldflags_uselargefiles$libs_uselargefiles" in
291             '') ;;
292             *)  ccflags="$ccflags $ccflags_uselargefiles"
293                 ldflags="$ldflags $ldflags_uselargefiles"
294                 libswanted="$libswanted $libswanted_uselargefiles"
295                 ;;
296             esac
297
298         case "$gccversion" in
299             '') ;;
300             *)  # Remove xlc-specific -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 xlc-specific -bflags.
304                 ccflags="`echo $ccflags | sed -e 's@ -b@ -Wl,-b@g'`"
305                 ldflags="`echo ' '$ldflags | sed -e 's@ -b@ -Wl,-b@g'`"
306                 lddlflags="`echo ' '$lddlflags | sed -e 's@ -b@ -Wl,-b@g'`"
307                 ld='gcc'
308                 echo >&4 "(using ccflags   $ccflags)"
309                 echo >&4 "(using ldflags   $ldflags)"
310                 echo >&4 "(using lddlflags $lddlflags)"
311                 ;;
312             esac
313         ;;
314     esac
315 EOCBU
316
317 cat > UU/use64bitall.cbu <<'EOCBU'
318 # This script UU/use64bitall.cbu will get 'called-back' by Configure
319 # after it has prompted the user for whether to be maximally 64-bitty.
320 case "$use64bitall" in
321     $define|true|[yY]*)
322         echo " "
323         echo "Checking the CPU width of your hardware..." >&4
324         $cat >size.c <<EOCP
325 #include <stdio.h>
326 #include <sys/systemcfg.h>
327 int main (void)
328 {
329     printf ("%d\n", _system_configuration.width);
330     return (0);
331     }
332 EOCP
333         set size
334         if eval $compile_ok; then
335             qacpuwidth=`./size`
336             echo "You are running on $qacpuwidth bit hardware."
337         else
338             dflt="32"
339             echo " "
340             echo "(I can't seem to compile the test program.  Guessing...)"
341             rp="What is the width of your CPU (in bits)?"
342             . ./myread
343             qacpuwidth="$ans"
344             fi
345         $rm -f size.c size
346
347         case "$qacpuwidth" in
348             32*)
349                 cat >&4 <<EOM
350 Bzzzt! At present, you can only perform a
351 full 64-bit build on a 64-bit machine.
352 EOM
353                 exit 1
354                 ;;
355             esac
356         qacflags="`getconf XBS5_LP64_OFF64_CFLAGS 2>/dev/null`"
357         qaldflags="`getconf XBS5_LP64_OFF64_LDFLAGS 2>/dev/null`"
358         # See jhi's comments above regarding this re-eval.  I've
359         # seen similar weirdness in the form of:
360         #
361 # 1506-173 (W) Option lm is not valid.  Enter xlc for list of valid options.
362         #
363         # error messages from 'cc -E' invocation. Again, the offending
364         # string is simply not detectable by any means.  Since it doesn't
365         # do any harm, I didn't pursue it. -- sh
366         qaldflags="`echo $qaldflags`"
367         qalibs="`getconf XBS5_LP64_OFF64_LIBS 2>/dev/null|sed -e 's@^-l@@' -e 's@ -l@ @g`"
368         # -q32 and -b32 may have been set by uselargefiles or user.
369         # Remove them.
370         ccflags="`echo $ccflags | sed -e 's@-q32@@'`"
371         ldflags="`echo $ldflags | sed -e 's@-b32@@'`"
372         # Tell archiver to use large format.  Unless we remove 'ar'
373         # from 'trylist', the Configure script will just reset it to 'ar'
374         # immediately prior to writing config.sh.  This took me hours
375         # to figure out.
376         trylist="`echo $trylist | sed -e 's@^ar @@' -e 's@ ar @ @g' -e 's@ ar$@@'`"
377         ar="ar -X64"
378         nm_opt="-X64 $nm_opt"
379         # Note: Placing the 'qacflags' variable into the 'ldflags' string
380         # is NOT a typo.  ldflags is passed to the C compiler for final
381         # linking, and it wants -q64 (-b64 is for ld only!).
382         case "$qacflags$qaldflags$qalibs" in
383             '') ;;
384             *)  ccflags="$ccflags $qacflags"
385                 ldflags="$ldflags $qacflags"
386                 lddlflags="$qaldflags $lddlflags"
387                 libswanted="$libswanted $qalibs"
388                 ;;
389             esac
390         case "$ccflags" in
391             *-DUSE_64_BIT_ALL*) ;;
392             *) ccflags="$ccflags -DUSE_64_BIT_ALL";;
393             esac
394         case "$archname64" in
395             ''|64*) archname64=64all ;;
396             esac
397         longsize="8"
398         qacflags=''
399         qaldflags=''
400         qalibs=''
401         qacpuwidth=''
402         ;;
403     esac
404 EOCBU
405
406 if test $usenativedlopen = 'true' ; then
407     ccflags="$ccflags -DUSE_NATIVE_DLOPEN"
408     case "$cc" in
409         *gcc*) ldflags="$ldflags -Wl,-brtl" ;;
410         *)     ldflags="$ldflags -brtl" ;;
411         esac
412 elif test -f /lib/libC.a -a X"`$cc -v 2>&1 | grep gcc`" = X; then
413     # If the C++ libraries, libC and libC_r, are available we will
414     # prefer them over the vanilla libc, because the libC contain
415     # loadAndInit() and terminateAndUnload() which work correctly
416     # with C++ statics while libc load() and unload() do not. See
417     # ext/DynaLoader/dl_aix.xs. The C-to-C_r switch is done by
418     # usethreads.cbu, if needed.
419
420     # Cify libswanted.
421     set `echo X "$libswanted "| sed -e 's/ c / C c /'`
422     shift
423     libswanted="$*"
424     # Cify lddlflags.
425     set `echo X "$lddlflags "| sed -e 's/ -lc / -lC -lc /'`
426     shift
427     lddlflags="$*"
428     fi
429
430 case "$PASE" in
431     define)
432         case "$prefix" in
433             '') prefix=/QOpenSys/perl ;;
434             esac
435         cat >&4 <<EOF
436
437 ***
438 *** You seem to be compiling in AIX for the OS/400 PASE environment.
439 *** I'm not going to use the AIX bind, nsl, and possible util libraries, then.
440 *** I'm also not going to install perl as /usr/bin/perl.
441 *** Perl will be installed under $prefix.
442 *** For instructions how to install this build from AIX to PASE,
443 *** see the file README.os400.  Accept the "aix" for the question
444 *** about "Operating system name".
445 ***
446 EOF
447         set `echo " $libswanted " | sed -e 's@ bind @ @' -e 's@ nsl @ @' -e 's@ util @ @'`
448         shift
449         libswanted="$*"
450         installusrbinperl="$undef"
451
452         # V5R1 doesn't have this (V5R2 does), without knowing
453         # which one we have it's safer to be pessimistic.
454         # Cwd will work fine even without fchdir(), but if
455         # V5R1 tries to use code compiled assuming fchdir(),
456         # lots of grief will issue forth from Cwd.
457         case "$d_fchdir" in
458             '') d_fchdir="$undef" ;;
459             esac
460         ;;
461     esac
462
463 # EOF