
    Ig<                         d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	 ddl
mZmZmZ ddlmZmZmZmZ ddlmZ dd	lmZ d
 Zd Zd Z G d de          ZdS )a9  distutils.unixccompiler

Contains the UnixCCompiler class, a subclass of CCompiler that handles
the "typical" Unix-style command-line C compiler:
  * macros defined with -Dname[=value]
  * macros undefined with -Uname
  * include search directories specified with -Idir
  * libraries specified with -lllib
  * library search directories specified with -Ldir
  * compile handled by 'cc' (or similar) executable with -c option:
    compiles .c to .o
  * link static library handled by 'ar' command (possibly with 'ranlib')
  * link shared library handled by 'cc -shared'
    N   )	sysconfig)newer)	CCompilergen_preprocess_optionsgen_lib_options)DistutilsExecErrorCompileErrorLibError	LinkError)log)compiler_fixupc                     d}t           j                            | d                   dk    rd}d| |         v r|dz  }d| |         v | d|         | |d         fS )z
    For macOS, split command into 'env' portion (if any)
    and the rest of the linker command.

    >>> _split_env(['a', 'b', 'c'])
    ([], ['a', 'b', 'c'])
    >>> _split_env(['/usr/bin/env', 'A=3', 'gcc'])
    (['/usr/bin/env', 'A=3'], ['gcc'])
    r   envr   =Nospathbasenamecmdpivots     _/var/www/html/4nations/venv/lib/python3.11/site-packages/setuptools/_distutils/unixccompiler.py
_split_envr   -   sq     E	wA5((SZQJE SZvv;EFF##    c                 |    t           j                            | d                   dk    }| d|         | |d         fS )a  
    AIX platforms prefix the compiler with the ld_so_aix
    script, so split that from the linker command.

    >>> _split_aix(['a', 'b', 'c'])
    ([], ['a', 'b', 'c'])
    >>> _split_aix(['/bin/foo/ld_so_aix', 'gcc'])
    (['/bin/foo/ld_so_aix'], ['gcc'])
    r   	ld_so_aixNr   r   s     r   
_split_aixr   ?   s=     GSV$$3Evv;EFF##r   c                 X    t          |          }| d|         |k    r|nd}| |d         S )a  
    The linker command usually begins with the compiler
    command (possibly multiple elements), followed by zero or more
    params for shared library building.

    If the LDSHARED env variable overrides the linker command,
    however, the commands may not match.

    Return the best guess of the linker parameters by stripping
    the linker command. If the compiler command does not
    match the linker command, assume the linker command is
    just the first element.

    >>> _linker_params('gcc foo bar'.split(), ['gcc'])
    ['foo', 'bar']
    >>> _linker_params('gcc foo bar'.split(), ['other'])
    ['foo', 'bar']
    >>> _linker_params('ccache gcc foo bar'.split(), 'ccache gcc'.split())
    ['foo', 'bar']
    >>> _linker_params(['gcc'], ['gcc'])
    []
    Nr   )len)
linker_cmdcompiler_cmdc_lenr   s       r   _linker_paramsr$   M   s<    . E'<77EEQEeffr   c            	       $   e Zd ZdZddgdgdgddgdgddgddZej        dd         d	k    rd
ged
<   g dZdZdZ	dZ
dZdZdxZxZZeZej        dk    rdZ	 	 	 	 	 ddZd Z	 d dZ	 	 	 	 	 	 	 	 	 	 d!dZd Zd Zd Zd Zed             Zd"dZdS )#UnixCCompilerunixNccz-sharedarz-cr)preprocessorcompilercompiler_socompiler_cxx	linker_so
linker_exearchiverranlib   darwinr1   )z.cz.Cz.ccz.cxxz.cppz.mz.oz.az.soz.dylibz.tbdzlib%s%scygwinz.exec                 $   |                      d ||          }|\  }}}t          ||          }	| j        |	z   }
|r|
                    d|g           |r||
d d<   |r|
                    |           |
                    |           | j        p|d u pt          ||          }|sd S |r2|                     t          j	        
                    |                     	 |                     |
           d S # t          $ r}t          |          d }~ww xY w)N-or   )_fix_compile_argsr   r*   extendappendforcer   mkpathr   r   dirnamespawnr	   r
   )selfsourceoutput_filemacrosinclude_dirsextra_preargsextra_postargs
fixed_argsignorepp_optspp_args
preprocessmsgs                r   rI   zUnixCCompiler.preprocess   sD    ++D&,GG
'1$(>>#g- 	0NND+./// 	('GBQBK 	+NN>***v ZT;$#6T%:T:T
 	F 	6KK44555	$JJw! 	$ 	$ 	$s###	$s   C1 1
D;D

Dc                     t          | j        ||z             }	 |                     ||z   |d|gz   |z              d S # t          $ r}t	          |          d }~ww xY w)Nr6   )r   r,   r=   r	   r
   )	r>   objsrcextcc_argsrD   rG   r,   rJ   s	            r   _compilezUnixCCompiler._compile   sy    $T%5w7OPP	$JJ{W,T3/??.PQQQQQ! 	$ 	$ 	$s###	$s   != 
AAAr   c                    |                      ||          \  }}|                     ||          }|                     ||          r|                     t          j                            |                     |                     | j        |gz   |z   | j	        z              | j
        rB	 |                     | j
        |gz              d S # t          $ r}t          |          d }~ww xY wd S t          j        d|           d S )N)
output_dirskipping %s (up-to-date))_fix_object_argslibrary_filename
_need_linkr;   r   r   r<   r=   r0   objectsr1   r	   r   r   debug)r>   rW   output_libnamerR   rX   target_langoutput_filenamerJ   s           r   create_static_libzUnixCCompiler.create_static_lib   s    #33GZHH//:/VV??7O44 	CKK88999JJt}'887BT\QRRR { ((JJt{o->>?????) ( ( ("3--'(( ( I0/BBBBBs   *C
 

C(C##C(c                 P   |                      ||          \  }}|                     |||          }|\  }}}t          | |||          }t          |t          t          d           f          st          d          | t          j        	                    ||          }| 
                    ||          r\|| j        z   |z   d|gz   }|	rdg|d d<   |
r|
|d d<   |r|                    |           |                     t          j                            |                     	 |t          j        k    }|r| j        n| j        d d          }|dk    rt| j        rmt)          |          \  }}t+          |          \  }}t)          | j                  \  }}t)          | j                  \  }}t-          ||          }||z   |z   |z   }t/          ||          }|                     ||z              d S # t2          $ r}t5          |          d }~ww xY wt7          j        d|           d S )Nz%'output_dir' must be a string or Noner6   z-gr   zc++rS   )rT   _fix_lib_argsr   
isinstancestrtype	TypeErrorr   r   joinrV   rW   r8   r;   r<   r   
EXECUTABLEr/   r.   r-   r   r   r$   r   r=   r	   r   r   rX   )r>   target_descrW   r[   rR   	librarieslibrary_dirsruntime_library_dirsexport_symbolsrX   rC   rD   
build_temprZ   rE   lib_optsld_argsbuilding_exelinkerr   	linker_neaix	linker_na_compiler_cxx_nelinker_exe_neparamsrJ   s                               r   linkzUnixCCompiler.link   sX     #33GZHH''	<AUVV
8B5	<!5"47KYWW*sDJJ&788 	ECDDD! gll:GGO??7O44 	C,x74:QQG %#f ,+ /~...KK88999%  +i.BB-9M$//t~qqqQ%''D,='%/%7%7NC%/	%:%:NC)3D4E)F)F&A'1$/'B'B$A}+I}EEF 3Y86AF'88

6G+,,,,,% % % %nn$% I0/BBBBBs   $C
G0 0
H:H		Hc                     d|z   S )N-L )r>   dirs     r   library_dir_optionz UnixCCompiler.library_dir_option      czr   c                     t          j        d          }t          j                            t          j        |          d                   }d|v pd|v S )NCCr   gcczg++)r   get_config_varr   r   r   shlexsplit)r>   cc_varr+   s      r   _is_gcczUnixCCompiler._is_gcc  sK    )$//7##EK$7$7$:;; 5EX$55r   c                 x   t           j        d d         dk    r/ddlm}m}  |            }|r ||          ddgk    rd|z   S d|z   S t           j        d d	         d
k    rd|z   S t           j        d d         dk    r|                                 rdndd|z   gS t          j        d          dk    rd|z   S d|z   S )Nr2   r3   r   )get_macosx_target_versplit_version
      z-Wl,-rpath,rx      freebsdz-Wl,-rpath=zhp-uxz-Wl,+sz+sGNULDyesz-Wl,--enable-new-dtags,-Rz-Wl,-R)sysplatformdistutils.utilr   r   r   r   r   )r>   rz   r   r   macosx_target_vers        r   runtime_library_dir_optionz(UnixCCompiler.runtime_library_dir_option  s    <x''KKKKKKKK 5 5 7 7  "]]3D%E%E"a%P%P$s**cz!\"1"** 3&&\"1"(( LLNN4s
  #G,,55 /44c>!r   c                     d|z   S )Nz-lry   )r>   libs     r   library_optionzUnixCCompiler.library_optionE  r|   r   c                 v   t          j        d          }t          j        d|          }t          j        dk    oA|o?|                     d          p*|                     d          o|                     d           }|r;t          j        	                    |
                    d          | dd                   n| S )	a  
        macOS users can specify an alternate SDK using'-isysroot'.
        Calculate the SDK root if it is specified.

        Note that, as of Xcode 7, Apple SDKs may contain textual stub
        libraries with .tbd extensions rather than the normal .dylib
        shared libraries installed in /.  The Apple compiler tool
        chain handles this transparently but it can cause problems
        for programs that are being built with an SDK and searching
        for specific libraries.  Callers of find_library_file need to
        keep in mind that the base filename of the returned SDK library
        file might have a different extension from that of the library
        file installed on the running system, for example:
          /Applications/Xcode.app/Contents/Developer/Platforms/
              MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
              usr/lib/libedit.tbd
        vs
          /usr/lib/libedit.dylib
        CFLAGSz-isysroot\s*(\S+)r3   z/System/z/usr/z/usr/local/r   N)r   r   researchr   r   
startswithr   r   rc   group)rz   cflagsmatch
apply_roots       r   _library_rootzUnixCCompiler._library_rootH  s    * )(33	.77 LH$  z** SNN7++QCNN=4Q4Q0Q 	 9CKrw||EKKNNCG444Kr   c                      fdd                                 D             }t           j        |          }d t          j        ||          D             }t          t          j        j        |          }t          |d          S )a/  
        Second-guess the linker with not much hard
        data to go on: GCC seems to prefer the shared library, so
        assume that *all* Unix C compilers do,
        ignoring even GCC's "-static" option.

        >>> compiler = UnixCCompiler()
        >>> compiler._library_root = lambda dir: dir
        >>> monkeypatch = getfixture('monkeypatch')
        >>> monkeypatch.setattr(os.path, 'exists', lambda d: 'existing' in d)
        >>> dirs = ('/foo/bar/missing', '/foo/bar/existing')
        >>> compiler.find_library_file(dirs, 'abc').replace('\\', '/')
        '/foo/bar/existing/libabc.dylib'
        >>> compiler.find_library_file(reversed(dirs), 'abc').replace('\\', '/')
        '/foo/bar/existing/libabc.dylib'
        >>> monkeypatch.setattr(os.path, 'exists',
        ...     lambda d: 'existing' in d and '.a' in d)
        >>> compiler.find_library_file(dirs, 'abc').replace('\\', '/')
        '/foo/bar/existing/libabc.a'
        >>> compiler.find_library_file(reversed(dirs), 'abc').replace('\\', '/')
        '/foo/bar/existing/libabc.a'
        c              3   F   K   | ]}                     |           V  dS ))lib_typeN)rU   ).0ra   r   r>   s     r   	<genexpr>z2UnixCCompiler.find_library_file.<locals>.<genexpr>  sJ       
 
 !!#!55
 
 
 
 
 
r   zdylib xcode_stub shared staticc              3   \   K   | ]'\  }}t           j                            ||          V  (d S )N)r   r   rc   )r   rootlib_names      r   r   z2UnixCCompiler.find_library_file.<locals>.<genexpr>  sJ       
 
h GLLx((
 
 
 
 
 
r   N)
r   mapr   	itertoolsproductfilterr   r   existsnext)r>   dirsr   rX   	lib_namesrootssearchedfounds   ` `     r   find_library_filezUnixCCompiler.find_library_filek  s    .
 
 
 
 
8>>@@
 
 
	
 D&--
 
"+"3E9"E"E
 
 

 rw~x00 E4   r   )NNNNN)Nr   N)
NNNNNr   NNNN)r   )__name__
__module____qualname__compiler_typeexecutablesr   r   src_extensionsobj_extensionstatic_lib_extensionshared_lib_extensiondylib_lib_extensionxcode_stub_lib_extensionstatic_lib_formatshared_lib_formatdylib_lib_formatxcode_stub_lib_formatexe_extensionrI   rP   r\   rv   r{   r   r   r   staticmethodr   r   ry   r   r   r&   r&   i   s       M FvI&f5M	 	K |BQB8##!)
H ?>>NM "%?HHH),<,
|x
 #$ #$ #$ #$J$ $ $ NRC C C C: !9C 9C 9C 9C~  6 6 6
&" &" &"P    L  L \ LD&! &! &! &! &! &!r   r&   )__doc__r   r   r   r   r    r   dep_utilr   	ccompilerr   r   r   errorsr	   r
   r   r   _logr   _macos_compatr   r   r   r$   r&   ry   r   r   <module>r      s6    
			 



 				                  I I I I I I I I I I I I I I I I I I I I I I       ) ) ) ) ) )$$ $ $$$ $ $  8h! h! h! h! h!I h! h! h! h! h!r   