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