[J @sdZddlZddlZddlZddddgZd0Zd1ZdZdddZddZ ddZ da ddZ ddZ ddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,dZd-dZd.dZd/dZdS)2zShared OS X support functions.Ncompiler_fixupcustomize_config_varscustomize_compilerget_platform_osxCFLAGSLDFLAGSCPPFLAGS BASECFLAGS BLDSHAREDLDSHAREDCCCXX PY_CFLAGS PY_LDFLAGS PY_CPPFLAGSPY_CORE_CFLAGSZ_OSX_SUPPORT_INITIAL_cCs|dkrtjd}n|jtj}tjj|\}}tjdkrn|dkrn|d}ntjj|sx9|D]1}tjj ||}tjj|r|SqWdS|SdS)zTries to find 'executable' in the directories listed in 'path'. A string listing directories separated by 'os.pathsep'; defaults to os.environ['PATH']. Returns the complete filename or None if not found. NPATHZwin32z.exe) osenvironsplitpathseppathsplitextsysplatformisfilejoin) executablerZpathsbaseZextpfr!"/usr/lib/python3.4/_osx_support.py_find_executables   r#cCsddl}yddl}|j}Wn.tk rXtdtjfd}YnX|j|F}d||jf}tj |s|j j dj SdSWdQXdS)z0Output from successful command execution or NonerNz/tmp/_osx_support.%szw+bz%s 2>/dev/null >'%s'zutf-8) contextlibtempfileZNamedTemporaryFile ImportErroropenrgetpidclosingnamesystemreaddecodestrip)Z commandstringr$r%fpcmdr!r!r" _read_output7s   r1cCs#t|p"td|fp"dS)z0Find a build tool on current path or using xcrunz/usr/bin/xcrun -find %s)r#r1)Ztoolnamer!r!r"_find_build_toolJs r3cCstdkrdaytd}Wntk r6YqXztjd|j}Wd|jX|dk rdj|jdj dddaqntS)z*Return the OS X system version as a stringNr2z0/System/Library/CoreServices/SystemVersion.plistz=ProductUserVisibleVersion\s*(.*?).) _SYSTEM_VERSIONr'OSErrorresearchr,closergroupr)r mr!r!r"_get_system_versionSs     1r>cCs4x-t|D]}|jtr ||=q q WdS)z-Remove original unmodified values for testingN)list startswith_INITPRE) _config_varskr!r!r"_remove_original_valuesqsrDcCsM|j|d}||kr?t||kr?||t|sz-_supports_universal_builds..r4r2 F)rLrM)r>tupler ValueErrorbool)Z osx_versionr!r!r"_supports_universal_buildss & rQcCsDdtjkr|S|djd}}t|sFtd}n^tjj|jdrtd|j ddf}|rd|krtd}qn|st d n||kr@xxt D]m}||kr|tjkr||j}|d kr|n|d |d/dev/nullrRz'"'"'z-arch\s+ppc\w*\srS) rrr9r:r+rUrZr[rG)rBZstatusrFr]r!r!r"_remove_unsupported_archss   r_cCsdtjkrtjd}xmtD]b}||kr#d||kr#||}tjdd|}|d|}t|||q#q#Wn|S)z2Allow override of all archs with ARCHFLAGS env var ARCHFLAGSz-archz -arch\s+\w+\srS)rrrZr9r[rG)rBZarchrFr]r!r!r"_override_all_archss   racCs|jdd}tjd|}|dk r|jd}tjj|sx^tD]S}||krX|tjkrX||}tj dd|}t |||qXqXWqn|S)z+Remove references to any SDKs not availablerr2z-isysroot\s+(\S+)Nr5z-isysroot\s+\S+(?:\s|$)rS) rEr9r:r<rrexistsrZrr[rG)rBcflagsr=ZsdkrFr]r!r!r"_check_for_unavailable_sdks    rdc Csd}}t|}ts,d}}nd|k}d|k}|sYdtjkrxAy$|jd}|||d=Wq\tk rPYq\Xq\Wndtjkr| r|tjdj}n|rxAy$|jd}|||d=Wqtk rPYqXqWnd}d|krI|jd}||d}n,d|kru|jd}||d}n|rtjj| rd d l m }|j d ||j d n|S) ae This function will strip '-isysroot PATH' and '-arch ARCH' from the compile flags if the user has specified one them in extra_compile_flags. This is needed because '-arch ARCH' adds another architecture to the build, without a way to remove an architecture. Furthermore GCC will barf if multiple '-isysroot' arguments are present. FTz-archz -isysrootr`r6Nr5r)logz4Compiling with an SDK that doesn't seem to exist: %sz$Please check your Xcode installation) r?rQrrindexrOrrisdirZ distutilsrewarn)Z compiler_soZcc_argsZ stripArchZ stripSysrootrfZsysrootidxrer!r!r"r0sF             cCs.tst|nt|t||S)aCustomize Python build configuration variables. Called internally from sysconfig with a mutable mapping containing name/value pairs parsed from the configured makefile used to build this interpreter. Returns the mapping updated as needed to reflect the environment in which the interpreter is running; in the case of a Python from a binary installer, the installed environment may be very different from the build environment, i.e. different OS levels, different built tools, different available CPU architectures. This customization is performed whenever distutils.sysconfig.get_config_vars() is first called. It may be used in environments where no compilers are present, i.e. when installing pure Python dists. Customization of compiler paths and detection of unavailable archs is deferred until the first extension module build is requested (in distutils.sysconfig.customize_compiler). Currently called from distutils.sysconfig )rQr^rard)rBr!r!r"rps     cCs"t|t|t||S)zCustomize compiler path and configuration variables. This customization is performed when the first extension module build is requested in distutils.sysconfig.customize_compiler). )rYr_ra)rBr!r!r"rs   c Cs |jdd}tp|}|p*|}|r|}d}|jtd|jdd}|ry0tdd|jddd D}Wqtk rd}YqXnd}|dkrd |jkrd }tjd|}tt t |}t |dkr(|d}q|dkr=d }q|d krRd}q|d!krgd}q|d"kr|d}q|d#krd}qtd|fq|dkrt j d$krd}qq|d%krt j d&krd}qd}qn|||fS)'z Filter values for get_platform()ZMACOSX_DEPLOYMENT_TARGETr2Zmacosxrcss|]}t|VqdS)N)rH)rIrJr!r!r"rKsz#get_platform_osx..r4rr6rLrMz-archZfatz -arch\s+(\S+)r5i386ppcx86_64ZintelZfat3ppc64Zfat64Z universalz%Don't know machine value for archs=%r PowerPCPower_Macintosh)rLr)rLr)rLrM)rjrk)rjrl)rjrkrl)rmrl)rjrkrmrll)rorpl)rEr>rArNrrOr.r9findallsortedsetlenrmaxsize)rBZosnamereleasemachineZmacverZ macreleasercZarchsr!r!r"rsP   0                 ) zCFLAGSrrr r r CCCXXrrrr)r r rxry)__doc__rr9r__all__rZrWrAr#r1r3r7r>rDrGrQrYr^r_rardrrrrr!r!r!r"s<           >  (   @ )