
(°hV  ã               @   sr   d  Z  d d l Z d d l m Z d d l Td d l m Z d d l m Z d d „  Z	 Gd	 d
 „  d
 e ƒ Z
 d S)z´distutils.command.build_clib

Implements the Distutils 'build_clib' command, to build a C/C++ library
that is included in the module distribution and needed by an extension
module.é    N)ÚCommand)Ú*)Úcustomize_compiler)Úlogc              C   s   d d l  m }  |  ƒ  d  S)Nr   )Úshow_compilers)Údistutils.ccompilerr   )r   © r   úN/tmp/pip-build-kmztzv_d/setuptools/setuptools/_distutils/command/build_clib.pyr      s    r   c               @   s    e  Z d  Z d Z d" d# d$ d% d& g Z d d g Z d d d e f g Z d d „  Z d d „  Z	 d d „  Z
 d d „  Z d d „  Z d d „  Z d  d! „  Z d S)'Ú
build_clibz/build C/C++ libraries used by Python extensionsúbuild-clib=Úbú%directory to build C/C++ libraries toúbuild-temp=Útú,directory to put temporary build by-productsÚdebugÚgú"compile with debugging informationÚforceÚfú2forcibly build everything (ignore file timestamps)ú	compiler=Úcúspecify the compiler typezhelp-compilerNzlist available compilersc             C   sU   d  |  _  d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d |  _ d  |  _ d  S)Nr   )	r
   Ú
build_tempÚ	librariesÚinclude_dirsÚdefineÚundefr   r   Úcompiler)Úselfr   r   r	   Úinitialize_options4   s    								zbuild_clib.initialize_optionsc             C   s–   |  j  d d d d	 d
 d ƒ |  j j |  _ |  j rD |  j |  j ƒ |  j d  k rh |  j j pb g  |  _ t |  j t ƒ r’ |  j j t j	 ƒ |  _ d  S)NÚbuildr   r
   r   r   r   )ú
build_tempz
build_clib)r#   r#   )úcompilerr$   )údebugr%   )úforcer&   )
Úset_undefined_optionsÚdistributionr   Úcheck_library_listr   Ú
isinstanceÚstrÚsplitÚosÚpathsep)r    r   r   r	   Úfinalize_optionsD   s    		zbuild_clib.finalize_optionsc             C   sö   |  j  s d  Sd d l m } | d |  j d |  j d |  j ƒ |  _ t |  j ƒ |  j d  k	 rs |  j j |  j ƒ |  j	 d  k	 r¯ x* |  j	 D] \ } } |  j j
 | | ƒ qŒ W|  j d  k	 râ x! |  j D] } |  j j | ƒ qÈ W|  j |  j  ƒ d  S)Nr   )Únew_compilerr   Údry_runr   )r   r   r0   r   r1   r   r   r   Zset_include_dirsr   Zdefine_macror   Zundefine_macroÚbuild_libraries)r    r0   ÚnameÚvalueÚmacror   r   r	   Úrun^   s     		zbuild_clib.runc             C   sÞ   t  | t ƒ s t d ƒ ‚ x¼ | D]´ } t  | t ƒ rV t | ƒ d k rV t d ƒ ‚ | \ } } t  | t ƒ s} t d ƒ ‚ d | k s§ t j d k r» t j | k r» t d | d ƒ ‚ t  | t ƒ s" t d ƒ ‚ q" Wd	 S)
a`  Ensure that the list of libraries is valid.

        `library` is presumably provided as a command option 'libraries'.
        This method checks that it is a list of 2-tuples, where the tuples
        are (library_name, build_info_dict).

        Raise DistutilsSetupError if the structure is invalid anywhere;
        just returns otherwise.
        z+'libraries' option must be a list of tuplesé   z*each element of 'libraries' must a 2-tuplezNfirst element of each tuple in 'libraries' must be a string (the library name)ú/z;bad library name '%s': may not contain directory separatorsr   zMsecond element of each tuple in 'libraries' must be a dictionary (build info)N)	r*   ÚlistÚDistutilsSetupErrorÚtupleÚlenr+   r-   ÚsepÚdict)r    r   Úlibr3   Ú
build_infor   r   r	   r)   v   s"    
	"		*zbuild_clib.check_library_listc             C   s>   |  j  s d  Sg  } x$ |  j  D] \ } } | j | ƒ q W| S)N)r   Úappend)r    Z	lib_namesÚlib_namer@   r   r   r	   Úget_library_namesš   s    	zbuild_clib.get_library_namesc             C   s‚   |  j  |  j ƒ g  } xe |  j D]Z \ } } | j d ƒ } | d  k s] t | t t f ƒ rm t d | ƒ ‚ | j | ƒ q  W| S)NÚsourceszfin 'libraries' option (library '%s'), 'sources' must be present and must be a list of source filenames)r)   r   Úgetr*   r9   r;   r:   Úextend)r    Ú	filenamesrB   r@   rD   r   r   r	   Úget_source_files¦   s    "
zbuild_clib.get_source_filesc             C   së   xä | D]Ü \ } } | j  d ƒ } | d  k sD t | t t f ƒ rT t d | ƒ ‚ t | ƒ } t j d | ƒ | j  d ƒ } | j  d ƒ } |  j j | d |  j	 d | d | d |  j
 ƒ} |  j j | | d |  j d |  j
 ƒq Wd  S)NrD   zfin 'libraries' option (library '%s'), 'sources' must be present and must be a list of source filenameszbuilding '%s' libraryÚmacrosr   Ú
output_dirr   )rE   r*   r9   r;   r:   r   Úinfor   Úcompiler   r   Zcreate_static_libr
   )r    r   rB   r@   rD   rI   r   Zobjectsr   r   r	   r2   µ   s$    "
		zbuild_clib.build_libraries)r   r   r   )r   r   r   )zdebugr   r   )zforcer   r   )r   r   r   )Ú__name__Ú
__module__Ú__qualname__ÚdescriptionÚuser_optionsÚboolean_optionsr   Úhelp_optionsr!   r/   r6   r)   rC   rH   r2   r   r   r   r	   r
      s*        	$r
   )Ú__doc__r-   Údistutils.corer   Zdistutils.errorsÚdistutils.sysconfigr   Ú	distutilsr   r   r
   r   r   r   r	   Ú<module>   s   
