U
    {±Ëh†  ã                   @   s„  d Z dZddlZddlZejdk r>ddlmZ G dd„ dƒZnddlZd3d	d
„Ze 	d¡Z
edƒZedƒZedƒZedƒZeekrˆdZnej edd… ¡d Zedej dd¡ƒZedƒd ej dd¡ Zedej de¡ƒZedƒZedƒZedƒZe d¡Zdd„ Zdd„ Zdd„ Zd4dd „Zd!d"„ Zd#d$„ Zd5d&d'„Z d6d(d)„Z!d7d+d,„Z"d-d.„ Z#d/d0„ Z$e%d1kr€e$ej&d2d… ƒ dS )8zÑ
Compile a Python script into an executable that embeds CPython.
Requires CPython to be built as a shared library ('libpythonX.Y').

Basic usage:

    python -m Cython.Build.BuildExecutable [ARGS] somefile.py
Té    N)é   é	   )Ú	sysconfigc                   @   s"   e Zd Zedd„ ƒZeejƒZdS )r   c                 C   s   | dkst ‚t ¡ S )NÚinclude)ÚAssertionErrorÚ
_sysconfigÚget_python_inc)Úname© r
   ú@/tmp/pip-unpacked-wheel-fhl22ezh/Cython/Build/BuildExecutable.pyÚget_path   s    zsysconfig.get_pathN)Ú__name__Ú
__module__Ú__qualname__Ústaticmethodr   r   Úget_config_varr
   r
   r
   r   r      s   
r   Ú c                 C   s   t  | ¡p|S ©N)r   r   )r	   Údefaultr
   r
   r   r      s    r   r   ÚLIBDIRÚLIBPLÚLIBRARYÚ	LDLIBRARYr   ÚCCÚCFLAGSú ÚLINKCCÚLINKFORSHAREDÚLIBSÚSYSLIBSÚEXEc                 G   s$   t r |r| | } tj | d ¡ d S )NÚ
)ÚDEBUGÚsysÚstderrÚwrite)ÚmsgÚargsr
   r
   r   Ú_debug6   s    r(   c                   C   s|   t dtƒ t dtƒ t dtƒ t dtƒ t dtƒ t dtƒ t dtƒ t dtƒ t d	t	ƒ t d
t
ƒ t dtƒ t dtƒ d S )Nz
INCDIR: %szLIBDIR1: %szLIBDIR2: %sz	PYLIB: %szPYLIB_DYN: %szCC: %sz
CFLAGS: %sz
LINKCC: %szLINKFORSHARED: %szLIBS: %szSYSLIBS: %szEXE_EXT: %s)r(   ÚINCDIRÚLIBDIR1ÚLIBDIR2ÚPYLIBÚ	PYLIB_DYNr   r   r   r   r   r   ÚEXE_EXTr
   r
   r
   r   Údump_config=   s    










r/   c                 C   sr   g }d }t | ƒD ]N\}}| d¡r.| |¡ n,|dkrB| |¡ n|}| |d d … }  qh|}qtdƒ‚||| fS )Nú-)z-Xz--directiveé   zno input file provided)Ú	enumerateÚ
startswithÚappendÚ
ValueError)r'   Úcy_argsZlast_argÚiÚargÚ
input_filer
   r
   r   Ú_parse_argsL   s    
r:   c                 C   sN   |rd  | ¡} t| ƒ ntd  | ¡ƒ dd l}|j| |d}|rJt |¡ d S )Nr   r   ©Úshell)Újoinr(   Ú
subprocessÚcallr#   Úexit)Úcmdr<   r>   Ú
returncoder
   r
   r   Úruncmd_   s    

rC   c                 C   s\   t td| t | d dt dt gtr,dt p8tj tt	¡g t
 ¡  t ¡  t ¡  ƒ d S )Nú-oú.oz-Lz-l)rC   r   r.   r*   r+   r-   ÚosÚpathr=   r,   r   Úsplitr   r   ©Úbasenamer
   r
   r   Úclinkm   s     ÿþþþrK   c                 C   s,   t tdd| d | d dt gt ¡  ƒ d S )Nz-crD   rE   z.cz-I)rC   r   r)   r   rH   rI   r
   r
   r   Úccompiles   s    rL   r
   c                 C   sd   ddl m}m}m} | t|p dƒd| g ¡\}}td|j| ƒ | ||¡}|j	dkr`t
 d¡ d S )Né   )ÚVersionÚCmdLineÚMainr
   z--embedzUsing Cython %s to compile %sr   r1   )ZCompilerrN   rO   rP   Úparse_command_lineÚlistr(   ÚversionÚcompileZ
num_errorsr#   r@   )r9   ÚoptionsrN   rO   rP   ÚsourcesÚresultr
   r
   r   Ú	cycompilew   s    
rX   c                 C   s"   t tj | ¡gt|ƒ dd d S )NFr;   )rC   rF   rG   ÚabspathrR   )Úprogram_namer'   r
   r
   r   Ú	exec_file€   s    r[   Fc                 C   sœ   t j | ¡d }|t }|s<t j |¡t j | ¡kr<tdƒ‚|s~t j |¡r~t j | ¡r~t j | ¡t j |¡kr~td|ƒ |S t	| |ƒ t
|ƒ t|ƒ |S )zi
    Build an executable program from a Cython module.

    Returns the name of the executable file.
    r   z?Input and output file names are the same, refusing to overwritez'File is up to date, not regenerating %s)rF   rG   Úsplitextr.   rY   r5   ÚexistsÚgetmtimer(   rX   rL   rK   )r9   Zcompiler_argsÚforcerJ   Zexe_filer
   r
   r   Úbuild„   s    ÿ

r`   c                 C   s   t | ƒ\}} t|| ƒ dS )z•
    Build an executable program from a Cython module and run it.

    Arguments after the module name will be passed verbatimly to the program.
    N)Ú_buildr[   )r'   rZ   r
   r
   r   Úbuild_and_run˜   s    rb   c                 C   s    t | ƒ\}}} t||ƒ}|| fS r   )r:   r`   )r'   r9   r6   rZ   r
   r
   r   ra   ¢   s    
ra   Ú__main__r1   )r   )T)r
   )r
   )r
   F)'Ú__doc__r"   r#   rF   Úversion_infoÚ	distutilsr   r   r   r   r)   r*   r+   r,   r-   rG   r\   ÚenvironÚgetr   r   r   r   r   r   r.   r(   r/   r:   rC   rK   rL   rX   r[   r`   rb   ra   r   Úargvr
   r
   r
   r   Ú<module>   sH   







	



