3
h                 @   s  d Z ddlmZ dZddlZddlZejd3k rLddlmZ	 G dd	 d	e
ZnddlZd4ddZejdZedZedZedZedZeekrd
Znejjedd d Zedejjdd
Zedd ejjdd
 ZedejjdeZedZedZedZejdZdd Zdd Zdd Zd5d d!Z d"d# Z!d$d% Z"f fd&d'Z#f fd(d)Z$f d*fd+d,Z%d-d. Z&d/d0 Z'e(d1kre'ej)d2d  dS )6z
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
    )absolute_importTN   	   )	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j S )Ninclude)AssertionError
_sysconfigget_python_inc)name r   n/var/www/html/CrowdFlow/Picklecon/ble_analysis_env/lib/python3.6/site-packages/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 j| p|S )N)r   r   )r
   defaultr   r   r   r       s    r   r   LIBDIRLIBPLLIBRARY	LDLIBRARYCCCFLAGS LINKCCLINKFORSHAREDLIBSSYSLIBSEXEc             G   s$   t r |r| | } tjj| d  d S )N
)DEBUGsysstderrwrite)msgargsr   r   r   _debug7   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   st   g }d }x`t | D ]L\}}|jdr0|j| n*|dkrD|j| n|}| |d d  } P |}qW td||| fS )N--X--directive   zno input file provided)r1   r2   )	enumerate
startswithappend
ValueError)r'   cy_argsZlast_argiarg
input_filer   r   r   _parse_argsM   s    
r<   c             C   sN   |rdj | } t|  ntdj |  dd l}|j| |d}|rJtj| d S )Nr   r   )shell)joinr(   
subprocesscallr#   exit)cmdr=   r?   
returncoder   r   r   runcmd`   s    

rD   c             C   s\   t td| t | d dt dt gtr,dt p8tjjtt	g t
j  tj  tj   d S )Nz-oz.oz-Lz-l)rD   r   r.   r*   r+   r-   ospathr>   r,   r   splitr   r   )basenamer   r   r   clinkn   s    rI   c             C   s,   t tdd| d | d dt gtj   d S )Nz-cz-oz.oz.cz-I)rD   r   r)   r   rG   )rH   r   r   r   ccompilet   s    rJ   c             C   sd   ddl m}m}m} |jt|p f d| g \}}td|j|  |j||}|j	dkr`t
jd d S )N   )VersionCmdLineMainz--embedzUsing Cython %s to compile %sr   r3   )ZCompilerrL   rM   rN   parse_command_linelistr(   versioncompileZ
num_errorsr#   rA   )r;   optionsrL   rM   rN   sourcesresultr   r   r   	cycompilex   s    
rV   c             C   s"   t tjj| gt| dd d S )NF)r=   )rD   rE   rF   abspathrP   )program_namer'   r   r   r   	exec_file   s    rY   Fc             C   s   t jj| d }|t }| r>t jj|t jj| kr>td| rt jj|rt jj| rt jj| t jj|krt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)rE   rF   splitextr.   rW   r7   existsgetmtimer(   rV   rJ   rI   )r;   Zcompiler_argsforcerH   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)_buildrY   )r'   rX   r   r   r   build_and_run   s    r`   c             C   s    t | \}}} t||}|| fS )N)r<   r^   )r'   r;   r8   rX   r   r   r   r_      s    
r_   __main__r3   )r   r   )r   )T)*__doc__
__future__r   r"   r#   rE   version_info	distutilsr   r   objectr   r   r)   r*   r+   r,   r-   rF   rZ   environgetr   r   r   r   r   r   r.   r(   r/   r<   rD   rI   rJ   rV   rY   r^   r`   r_   r   argvr   r   r   r   <module>   sJ   





	

