
    VhI                     z    d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZ d dlmZ ddZd	 Zd
 Zedk(  r e        yy)    )absolute_importdivisionprint_functionu   
module: make
short_description: Run targets in a Makefile
requirements:
  - make
author: Linus Unnebäck (@LinusU) <linus@folkdatorn.se>
description:
  - Run targets in a Makefile.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  chdir:
    description:
      - Change to this directory before running make.
    type: path
    required: true
  file:
    description:
      - Use a custom Makefile.
    type: path
  jobs:
    description:
      - Set the number of make jobs to run concurrently.
      - Typically if set, this would be the number of processors and/or threads available to the machine.
      - This is not supported by all make implementations.
    type: int
    version_added: 2.0.0
  make:
    description:
      - Use a specific make binary.
    type: path
    version_added: '0.2.0'
  params:
    description:
      - Any extra parameters to pass to make.
      - If the value is empty, only the key will be used. For example, V(FOO:) will produce V(FOO), not V(FOO=).
    type: dict
  target:
    description:
      - The target to run.
      - Typically this would be something like V(install), V(test), or V(all).
      - O(target) and O(targets) are mutually exclusive.
    type: str
  targets:
    description:
      - The list of targets to run.
      - Typically this would be something like V(install), V(test), or V(all).
      - O(target) and O(targets) are mutually exclusive.
    type: list
    elements: str
    version_added: 7.2.0
a  
- name: Build the default target
  community.general.make:
    chdir: /home/ubuntu/cool-project

- name: Run 'install' target as root
  community.general.make:
    chdir: /home/ubuntu/cool-project
    target: install
  become: true

- name: Build 'all' target with extra arguments
  community.general.make:
    chdir: /home/ubuntu/cool-project
    target: all
    params:
      NUM_THREADS: 4
      BACKEND: lapack

- name: Build 'all' target with a custom Makefile
  community.general.make:
    chdir: /home/ubuntu/cool-project
    target: all
    file: /some-project/Makefile

- name: build arm64 kernel on FreeBSD, with 16 parallel jobs
  community.general.make:
    chdir: /usr/src
    jobs: 16
    target: buildkernel
    params:
      # This adds -DWITH_FDT to the command line:
      -DWITH_FDT:
      # The following adds TARGET=arm64 TARGET_ARCH=aarch64 to the command line:
      TARGET: arm64
      TARGET_ARCH: aarch64
a  
chdir:
  description:
    - The value of the module parameter O(chdir).
  type: str
  returned: success
command:
  description:
    - The command built and executed by the module.
  type: str
  returned: success
  version_added: 6.5.0
file:
  description:
    - The value of the module parameter O(file).
  type: str
  returned: success
jobs:
  description:
    - The value of the module parameter O(jobs).
  type: int
  returned: success
params:
  description:
    - The value of the module parameter O(params).
  type: dict
  returned: success
target:
  description:
    - The value of the module parameter O(target).
  type: str
  returned: success
targets:
  description:
    - The value of the module parameter O(targets).
  type: str
  returned: success
  version_added: 7.2.0
)	iteritems)shlex_quote)AnsibleModulec                 z    |j                  | ||j                  d         \  }}}|t        |      t        |      fS )z
    Run a command using the module, return
    the result code and std{err,out} content.

    :param command: list of command arguments
    :param module: Ansible make module instance
    :return: return code, stdout content, stderr content
    chdir)check_rccwd)run_commandparamssanitize_output)commandmoduler   rcouterrs         j/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/make.pyr   r      sB     %%gfmmT[F\%]LBSs#_S%999    c                 *    | y| j                  d      S )z
    Sanitize the output string before we
    pass it to module.fail_json. Defaults
    the string to empty if it is None, else
    strips trailing newlines.

    :param output: output to sanitize
    :return: sanitized output
     z
)rstrip)outputs    r   r   r      s     ~}}V$$r   c                  P   t        t        t        d      t        dd      t        d      t        dd      t        d      t        d      t        d	      
      dgd      } | j                  d   }|(| j                  dd      }|s| j                  dd      }| j                  d   >t	        | j                  d         D cg c]  \  }}||dt        |      z   ndz    }}}ng }|g}| j                  d   +t        | j                  d         }|j                  d|g       | j                  d    |j                  d| j                  d   g       | j                  d   r|j                  | j                  d          n-| j                  d   r|j                  | j                  d          |j                  |       t        |dgz   | d      \  }}}	| j                  r|dk7  }
n|dk(  rd}
nt        || d      \  }}}	d}
| j                  |
d||	| j                  d   | j                  d   | j                  d   | j                  d   | j                  d   | j                  d   dj                  |D cg c]  }t        |       c}             y c c}}w c c}w ) Nstr)typelist)r   elementsdictpathT)r   requiredint)targettargetsr   r
   filemakejobs)r$   r%   )argument_specmutually_exclusivesupports_check_moder'   gmakeF)r"   r   =r   r(   z-jr&   z-fr$   r%   z-q)r   r   r
    )changedfailedstdoutstderrr$   r%   r   r
   r&   r(   r   )r   r    r   get_bin_pathr   r   extendappendr   
check_mode	exit_jsonjoinr   )r   	make_pathkvmake_parametersbase_commandr(   r   r   r   r/   parts               r   mainr?      s   U#fu5V$FT26"6"5!
 22 F f%I ''%'@	++FT+BI}}X*U^_e_l_lmu_vUwxTQPQ1!-s1vRHxx ;L}}V(6==()T4L)}}V(T6==#89: }}XFMM(34	y	!FMM)45 ( |tf4fuMLBS 77 G '|VdKLBSG }}X&i(}}X&mmG$]]6"]]6"E+d+EF  W yl Fs   J>J# __main__N)T)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.sixr   ansible.module_utils.six.movesr   ansible.module_utils.basicr   r   r   r?   __name__ r   r   <module>rK      s[    A @8t$L&
P / 6 4
:% Od zF r   