This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
inline.h: Fix comment
[perl5.git] / hints / darwin.sh
1 ##
2 # Darwin (Mac OS) hints
3 # Wilfredo Sanchez <wsanchez@wsanchez.net>
4 ##
5
6 ##
7 # Paths
8 ##
9
10 # Configure hasn't figured out the version number yet.  Bummer.
11 perl_revision=`awk '/define[    ]+PERL_REVISION/ {print $3}' $src/patchlevel.h`
12 perl_version=`awk '/define[     ]+PERL_VERSION/ {print $3}' $src/patchlevel.h`
13 perl_subversion=`awk '/define[  ]+PERL_SUBVERSION/ {print $3}' $src/patchlevel.h`
14 version="${perl_revision}.${perl_version}.${perl_subversion}"
15
16 # Pretend that Darwin doesn't know about those system calls in Tiger
17 # (10.4/darwin 8) and earlier [perl #24122]
18 case "$osvers" in
19 [1-8].*)
20     d_setregid='undef'
21     d_setreuid='undef'
22     d_setrgid='undef'
23     d_setruid='undef'
24     ;;
25 esac
26
27 # finite() deprecated in 10.9, use isfinite() instead.
28 case "$osvers" in
29 [1-8].*) ;;
30 *) d_finite='undef' ;;
31 esac
32
33 # This was previously used in all but causes three cases
34 # (no -Ddprefix=, -Dprefix=/usr, -Dprefix=/some/thing/else)
35 # but that caused too much grief.
36 # vendorlib="/System/Library/Perl/${version}"; # Apple-supplied modules
37
38 # BSD paths
39 case "$prefix" in
40 '')     # Default install; use non-system directories
41         prefix='/usr/local';
42         siteprefix='/usr/local';
43         ;;
44 '/usr') # We are building/replacing the built-in perl
45         prefix='/';
46         installprefix='/';
47         bin='/usr/bin';
48         siteprefix='/usr/local';
49         # We don't want /usr/bin/HEAD issues.
50         sitebin='/usr/local/bin';
51         sitescript='/usr/local/bin';
52         installusrbinperl='define'; # You knew what you were doing.
53         privlib="/System/Library/Perl/${version}";
54         sitelib="/Library/Perl/${version}";
55         vendorprefix='/';
56         usevendorprefix='define';
57         vendorbin='/usr/bin';
58         vendorscript='/usr/bin';
59         vendorlib="/Network/Library/Perl/${version}";
60         # 4BSD uses ${prefix}/share/man, not ${prefix}/man.
61         man1dir='/usr/share/man/man1';
62         man3dir='/usr/share/man/man3';
63         # But users' installs shouldn't touch the system man pages.
64         # Transient obsoleted style.
65         siteman1='/usr/local/share/man/man1';
66         siteman3='/usr/local/share/man/man3';
67         # New style.
68         siteman1dir='/usr/local/share/man/man1';
69         siteman3dir='/usr/local/share/man/man3';
70         ;;
71   *)    # Anything else; use non-system directories, use Configure defaults
72         ;;
73 esac
74
75 ##
76 # Tool chain settings
77 ##
78
79 # Since we can build fat, the archname doesn't need the processor type
80 archname='darwin';
81
82 # nm isn't known to work after Snow Leopard and XCode 4; testing with OS X 10.5
83 # and Xcode 3 shows a working nm, but pretending it doesn't work produces no
84 # problems.
85 usenm='false';
86
87 case "$optimize" in
88 '')
89 #    Optimizing for size also mean less resident memory usage on the part
90 # of Perl.  Apple asserts that this is a more important optimization than
91 # saving on CPU cycles.  Given that memory speed has not increased at
92 # pace with CPU speed over time (on any platform), this is probably a
93 # reasonable assertion.
94 if [ -z "${optimize}" ]; then
95   case "`${cc:-gcc} -v 2>&1`" in
96     *"gcc version 3."*) optimize='-Os' ;;
97     *) optimize='-O3' ;;
98   esac
99 else
100   optimize='-O3'
101 fi
102 ;;
103 esac
104
105 # -fno-common because common symbols are not allowed in MH_DYLIB
106 # -DPERL_DARWIN: apparently the __APPLE__ is not sanctioned by Apple
107 # as the way to differentiate Mac OS X.  (The official line is that
108 # *no* cpp symbol does differentiate Mac OS X.)
109 ccflags="${ccflags} -fno-common -DPERL_DARWIN"
110
111 # At least on Darwin 1.3.x:
112 #
113 # # define INT32_MIN -2147483648
114 # int main () {
115 #  double a = INT32_MIN;
116 #  printf ("INT32_MIN=%g\n", a);
117 #  return 0;
118 # }
119 # will output:
120 # INT32_MIN=2.14748e+09
121 # Note that the INT32_MIN has become positive.
122 # INT32_MIN is set in /usr/include/stdint.h by:
123 # #define INT32_MIN        -2147483648
124 # which seems to break the gcc.  Defining INT32_MIN as (-2147483647-1)
125 # seems to work.  INT64_MIN seems to be similarly broken.
126 # -- Nicholas Clark, Ken Williams, and Edward Moy
127 #
128 # This seems to have been fixed since at least Mac OS X 10.1.3,
129 # stdint.h defining INT32_MIN as (-INT32_MAX-1)
130 # -- Edward Moy
131 #
132 if test -f /usr/include/stdint.h; then
133   case "$(grep '^#define INT32_MIN' /usr/include/stdint.h)" in
134   *-2147483648) ccflags="${ccflags} -DINT32_MIN_BROKEN -DINT64_MIN_BROKEN" ;;
135   esac
136 fi
137
138 # Avoid Apple's cpp precompiler, better for extensions
139 if [ "X`echo | ${cc} -no-cpp-precomp -E - 2>&1 >/dev/null`" = "X" ]; then
140     cppflags="${cppflags} -no-cpp-precomp"
141
142     # This is necessary because perl's build system doesn't
143     # apply cppflags to cc compile lines as it should.
144     ccflags="${ccflags} ${cppflags}"
145 fi
146
147 # Known optimizer problems.
148 case "`cc -v 2>&1`" in
149   *"3.1 20020105"*) toke_cflags='optimize=""' ;;
150 esac
151
152 # Shared library extension is .dylib.
153 # Bundle extension is .bundle.
154 so='dylib';
155 dlext='bundle';
156 usedl='define';
157
158 # 10.4 can use dlopen.
159 # 10.4 broke poll().
160 case "$osvers" in
161 [1-7].*)
162     dlsrc='dl_dyld.xs';
163     ;;
164 *)
165     dlsrc='dl_dlopen.xs';
166     d_poll='undef';
167     i_poll='undef';
168     ;;
169 esac
170
171 case "$ccdlflags" in            # If passed in from command line, presume user knows best
172 '')
173    cccdlflags=' '; # space, not empty, because otherwise we get -fpic
174 ;;
175 esac
176
177 # Allow the user to override ld, but modify it as necessary below
178 case "$ld" in
179     '') case "$cc" in
180         # If the cc is explicitly something else than cc (or empty),
181         # set the ld to be that explicitly something else.  Conversely,
182         # if the cc is 'cc' (or empty), set the ld to be 'cc'.
183         cc|'') ld='cc';;
184         *) ld="$cc" ;;
185         esac
186         ;;
187 esac
188
189 # From http://ftp.netbsd.org/pub/pkgsrc/current/pkgsrc/mk/platform/Darwin.mk
190 # and https://trac.macports.org/wiki/XcodeVersionInfo
191 # and https://trac.macports.org/wiki/UsingTheRightCompiler
192 #
193 # OS, Kernel, Xcode Version
194 # Note that Xcode gets updates on older systems sometimes.
195 # pkgsrc generally expects that the most up-to-date xcode available for
196 # an OS version is installed
197 #
198 # Note that Apple hijacks the clang preprocessor symbols __clang_major__
199 # and __clang_minor__ so they cannot be used (easily) to detect the
200 # actual clang release.  For example:
201 #
202 # "Yosemite 10.10.x 14.x.y 6.3 (clang 3.6 as 6.1/602.0.49)"
203 #
204 # means that the Xcode 6.3 provided the clang 6.3 but called it 6.1
205 # (__clang_major__, __clang_minor__) and in addition the preprocessor
206 # symbol __apple_build_version__ was 6020049.
207 #
208 # Codename        OS      Kernel  Xcode
209 #
210 # Cheetah         10.0.x  1.3.1
211 # Puma            10.1    1.4.1
212 #                 10.1.x  5.x.y
213 # Jaguar          10.2.x  6.x.y
214 # Panther         10.3.x  7.x.y
215 # Tiger           10.4.x  8.x.y   2.0 (gcc4 4.0.0)
216 #                                 2.2 (gcc4 4.0.1)
217 #                                 2.2.1 (gcc 3.3)
218 #                                 2.5 ?
219 # Leopard         10.5.x  9.x.y   3.0 (gcc 4.0.1 default)
220 #                                 3.1 (gcc 4.2.1)
221 # Snow Leopard    10.6.x  10.x.y  3.2 (llvm gcc 4.2, clang 2.3 as 1.0)
222 #                                 3.2.1 (clang 1.0.1 as 1.0.1/24)
223 #                                 3.2.2 (clang 1.0.2 as 1.0.2/32)
224 #                                 3.2.3 (clang 1.5 as 1.5/60)
225 #                                 4.0.1 (clang 2.9 as 2.0/138)
226 # Lion            10.7.x  11.x.y  4.1 (llvm gcc 4.2.1, clang 3.0 as 2.1/163.7.1)
227 #                                 4.2 (clang 3.0 as 3.0/211.10.1)
228 #                                 4.3.3 (clang 3.1 as 3.1/318.0.61)
229 #                                 4.4 (clang 3.1 as 4.0/421.0.57)
230 # Mountain Lion   10.8.x  12.x.y  4.5 (clang 3.1 as 4.1/421.11.65, real gcc removed, there is gcc but it's really clang)
231 #                                 4.6 (clang 3.2 as 4.2/425.0.24)
232 #                                 5.0 (clang 3.3 as 5.0/500.2.75)
233 #                                 5.1 (clang 3.4 as 5.1/503.0.38)
234 # Mavericks       10.9.x  13.x.y  6.0.1 (clang 3.5 as 6.0/600.0.51)
235 #                                 6.1 (clang 3.5 as 6.0/600.0.54)
236 #                                 6.2 (clang 3.5 as 6.0/600.0.57)
237 # Yosemite        10.10.x 14.x.y  6.3 (clang 3.6 as 6.1/602.0.49)
238 # El Capitan      10.11.x 15.x.y  7.0 (clang 3.7 as 7.0/700.0.72)
239 #                                 7.1 (clang 3.7 as 7.0/700.1.76)
240 #
241
242 # Processors Supported
243 #
244 # PowerPC (PPC):       10.0.x - 10.5.8 (final 10.5.x)
245 # PowerPC via Rosetta: 10.4.4 - 10.6.8 (final 10.6.x)
246 # IA-32:               10.4.4 - 10.6.8 (though still supported on x86-64)
247 # x86-64:              10.4.7 - current
248
249 # MACOSX_DEPLOYMENT_TARGET selects the minimum OS level we want to support
250 #
251 # It is needed for OS releases before 10.6.
252 #
253 # https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/cross_development/Configuring/configuring.html
254 #
255 # If it is set, we also propagate its value to ccflags and ldflags
256 # using the -mmacosx-version-min flag.  If it is not set, we use
257 # the OS X release as the min value for the flag.
258
259 # Adds "-mmacosx-version-min=$2" to "$1" unless it already is there.
260 add_macosx_version_min () {
261   local v
262   eval "v=\$$1"
263   case " $v " in
264   *"-mmacosx-version-min"*)
265      echo "NOT adding -mmacosx-version-min=$2 to $1 ($v)" >&4
266      ;;
267   *) echo "Adding -mmacosx-version-min=$2 to $1" >&4
268      eval "$1='$v -mmacosx-version-min=$2'"
269      ;;
270   esac
271 }
272
273 # Perl bundles do not expect two-level namespace, added in Darwin 1.4.
274 # But starting from perl 5.8.1/Darwin 7 the default is the two-level.
275 case "$osvers" in  # Note: osvers is the kernel version, not the 10.x
276 1.[0-3].*) # OS X 10.0.x
277    lddlflags="${ldflags} -bundle -undefined suppress"
278    ;;
279 1.*)       # OS X 10.1
280    ldflags="${ldflags} -flat_namespace"
281    lddlflags="${ldflags} -bundle -undefined suppress"
282    ;;
283 [2-6].*)   # OS X 10.1.x - 10.2.x (though [2-4] never existed publicly)
284    ldflags="${ldflags} -flat_namespace"
285    lddlflags="${ldflags} -bundle -undefined suppress"
286    ;;
287 [7-9].*)   # OS X 10.3.x - 10.5.x
288    lddlflags="${ldflags} -bundle -undefined dynamic_lookup"
289    case "$ld" in
290        *MACOSX_DEVELOPMENT_TARGET*) ;;
291        *) ld="env MACOSX_DEPLOYMENT_TARGET=10.3 ${ld}" ;;
292    esac
293    ;;
294 *)        # OS X 10.6.x - current
295    # The MACOSX_DEPLOYMENT_TARGET is not needed,
296    # but the -mmacosx-version-min option is always used.
297
298    # We now use MACOSX_DEPLOYMENT_TARGET, if set, as an override by
299    # capturing its value and adding it to the flags.
300     case "$MACOSX_DEPLOYMENT_TARGET" in
301     10.*)
302       add_macosx_version_min ccflags $MACOSX_DEPLOYMENT_TARGET
303       add_macosx_version_min ldflags $MACOSX_DEPLOYMENT_TARGET
304       ;;
305     '')
306       # Empty MACOSX_DEPLOYMENT_TARGET is okay.
307       ;;
308     *)
309       cat <<EOM >&4
310
311 *** Unexpected MACOSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET
312 ***
313 *** Please either set it to 10.something, or to empty.
314
315 EOM
316       exit 1
317       ;;
318     esac
319
320     # Keep the prodvers leading whitespace (Configure magic).
321     # Cannot use $osvers here since that is the kernel version.
322     # sw_vers output                 what we want
323     # "ProductVersion:    10.10.5"   "10.10"
324     # "ProductVersion:    10.11"     "10.11"
325         prodvers=`sw_vers|awk '/^ProductVersion:/{print $2}'|awk -F. '{print $1"."$2}'`
326     case "$prodvers" in
327     10.*)
328       add_macosx_version_min ccflags $prodvers
329       add_macosx_version_min ldflags $prodvers
330       ;;
331     *)
332       cat <<EOM >&4
333
334 *** Unexpected product version $prodvers.
335 ***
336 *** Try running sw_vers and see what its ProductVersion says.
337
338 EOM
339       exit 1
340     esac
341
342    lddlflags="${ldflags} -bundle -undefined dynamic_lookup"
343    ;;
344 esac
345
346 ldlibpthname='DYLD_LIBRARY_PATH';
347
348 # useshrplib=true results in much slower startup times.
349 # 'false' is the default value.  Use Configure -Duseshrplib to override.
350
351 cat > UU/archname.cbu <<'EOCBU'
352 # This script UU/archname.cbu will get 'called-back' by Configure 
353 # after it has otherwise determined the architecture name.
354 case "$ldflags" in
355 *"-flat_namespace"*) ;; # Backward compat, be flat.
356 # If we are using two-level namespace, we will munge the archname to show it.
357 *) archname="${archname}-2level" ;;
358 esac
359 EOCBU
360
361 # 64-bit addressing support. Currently strictly experimental. DFD 2005-06-06
362 case "$use64bitall" in
363 $define|true|[yY]*)
364 case "$osvers" in
365 [1-7].*)
366      cat <<EOM >&4
367
368
369
370 *** 64-bit addressing is not supported for Mac OS X versions
371 *** below 10.4 ("Tiger") or Darwin versions below 8. Please try
372 *** again without -Duse64bitall. (-Duse64bitint will work, however.)
373
374 EOM
375      exit 1
376   ;;
377 *)
378     case "$osvers" in
379     8.*)
380         cat <<EOM >&4
381
382
383
384 *** Perl 64-bit addressing support is experimental for Mac OS X
385 *** 10.4 ("Tiger") and Darwin version 8. System V IPC is disabled
386 *** due to problems with the 64-bit versions of msgctl, semctl,
387 *** and shmctl. You should also expect the following test failures:
388 ***
389 ***    ext/threads-shared/t/wait (threaded builds only)
390
391 EOM
392
393         [ "$d_msgctl" ] || d_msgctl='undef'
394         [ "$d_semctl" ] || d_semctl='undef'
395         [ "$d_shmctl" ] || d_shmctl='undef'
396     ;;
397     esac
398
399     case `uname -p` in 
400     powerpc) arch=ppc64 ;;
401     i386) arch=x86_64 ;;
402     *) cat <<EOM >&4
403
404 *** Don't recognize processor, can't specify 64 bit compilation.
405
406 EOM
407     ;;
408     esac
409     for var in ccflags cppflags ld ldflags
410     do
411        eval $var="\$${var}\ -arch\ $arch"
412     done
413
414     ;;
415 esac
416 ;;
417 esac
418
419 ##
420 # System libraries
421 ##
422
423 # vfork works
424 usevfork='true';
425
426 # malloc wrap works
427 case "$usemallocwrap" in
428 '') usemallocwrap='define' ;;
429 esac
430
431 # our malloc works (but allow users to override)
432 case "$usemymalloc" in
433 '') usemymalloc='n' ;;
434 esac
435 # However sbrk() returns -1 (failure) somewhere in lib/unicore/mktables at
436 # around 14M, so we need to use system malloc() as our sbrk()
437 #
438 # sbrk() in Darwin deprecated since Mavericks (10.9), it still exists
439 # in Yosemite (10.10) but that is just an emulation, and fails for
440 # allocations beyond 4MB.  One should use e.g. mmap instead (or system
441 # malloc, as suggested above, that but is kind of backward).
442 malloc_cflags='ccflags="-DUSE_PERL_SBRK -DPERL_SBRK_VIA_MALLOC $ccflags"'
443
444 # Locales aren't feeling well.
445 LC_ALL=C; export LC_ALL;
446 LANG=C; export LANG;
447
448 #
449 # The libraries are not threadsafe as of OS X 10.1.
450 #
451 # Fix when Apple fixes libc.
452 #
453 case "$usethreads$useithreads" in
454   *define*)
455   case "$osvers" in
456     [12345].*)     cat <<EOM >&4
457
458
459
460 *** Warning, there might be problems with your libraries with
461 *** regards to threading.  The test ext/threads/t/libc.t is likely
462 *** to fail.
463
464 EOM
465     ;;
466     *) usereentrant='define';;
467   esac
468
469 esac
470
471 # Fink can install a GDBM library that claims to have the ODBM interfaces
472 # but Perl dynaloader cannot for some reason use that library.  We don't
473 # really need ODBM_FIle, though, so let's just hint ODBM away.
474 i_dbm=undef;
475
476 # Configure doesn't detect ranlib on Tiger properly.
477 # NeilW says this should be acceptable on all darwin versions.
478 ranlib='ranlib'
479
480 # Catch MacPorts gcc/g++ extra libdir
481 case "$($cc -v 2>&1)" in
482 *"MacPorts gcc"*) loclibpth="$loclibpth /opt/local/lib/libgcc" ;;
483 esac
484
485 ##
486 # Build process
487 ##
488
489 # Case-insensitive filesystems don't get along with Makefile and
490 # makefile in the same place.  Since Darwin uses GNU make, this dodges
491 # the problem.
492 firstmakefile=GNUmakefile;
493
494 # Parts of the system call setenv(), in particular in an atfork handler.
495 # This causes problems when the child tries to clean up environ[], so
496 # let libc manage environ[].
497 cat >> config.over <<'EOOVER'
498 if test "$d_unsetenv" = "$define" -a \
499     `expr "$ccflags" : '.*-DPERL_USE_SAFE_PUTENV'` -eq 0; then
500         ccflags="$ccflags -DPERL_USE_SAFE_PUTENV"
501 fi
502 EOOVER