From 50425a49eca2e518f25f99df1df01d1cf28bd54e Mon Sep 17 00:00:00 2001
From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com>
Date: Wed, 12 Jul 2023 22:23:58 +0200
Subject: [PATCH] [PR #6882/0ae8f9d6 backport][stable-7] make: allow multiple
 targets to be specified (#6918)

make: allow multiple targets to be specified (#6882)

* make: allow multiple targets to be specified

* add changelog frag

* Update changelogs/fragments/6882-make-multiple-targets.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* change to extra param

* adjust changelog frag

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 0ae8f9d631608cbc0e403810a98fbae0f38cbd2a)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
---
 .../fragments/6882-make-multiple-targets.yml  |  2 ++
 plugins/modules/make.py                       | 27 ++++++++++++++++---
 2 files changed, 25 insertions(+), 4 deletions(-)
 create mode 100644 changelogs/fragments/6882-make-multiple-targets.yml

diff --git a/changelogs/fragments/6882-make-multiple-targets.yml b/changelogs/fragments/6882-make-multiple-targets.yml
new file mode 100644
index 0000000000..f870659f89
--- /dev/null
+++ b/changelogs/fragments/6882-make-multiple-targets.yml
@@ -0,0 +1,2 @@
+minor_changes:
+  - make - add new ``targets`` parameter allowing multiple targets to be used with ``make`` (https://github.com/ansible-collections/community.general/pull/6882, https://github.com/ansible-collections/community.general/issues/4919).
diff --git a/plugins/modules/make.py b/plugins/modules/make.py
index 1bc62925f5..665457fd6d 100644
--- a/plugins/modules/make.py
+++ b/plugins/modules/make.py
@@ -54,7 +54,16 @@ options:
     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
 '''
 
 EXAMPLES = r'''
@@ -115,6 +124,12 @@ target:
     - 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
 '''
 
 from ansible.module_utils.six import iteritems
@@ -155,12 +170,14 @@ def main():
     module = AnsibleModule(
         argument_spec=dict(
             target=dict(type='str'),
+            targets=dict(type='list', elements='str'),
             params=dict(type='dict'),
             chdir=dict(type='path', required=True),
             file=dict(type='path'),
             make=dict(type='path'),
             jobs=dict(type='int'),
         ),
+        mutually_exclusive=[('target', 'targets')],
         supports_check_mode=True,
     )
 
@@ -172,7 +189,6 @@ def main():
         if not make_path:
             # Fall back to system make
             make_path = module.get_bin_path('make', required=True)
-    make_target = module.params['target']
     if module.params['params'] is not None:
         make_parameters = [k + '=' + str(v) for k, v in iteritems(module.params['params'])]
     else:
@@ -188,7 +204,10 @@ def main():
         base_command.extend(["-f", module.params['file']])
 
     # add make target
-    base_command.append(make_target)
+    if module.params['target']:
+        base_command.append(module.params['target'])
+    elif module.params['targets']:
+        base_command.extend(module.params['targets'])
 
     # add makefile parameters
     base_command.extend(make_parameters)
@@ -206,8 +225,7 @@ def main():
             changed = False
         else:
             # The target isn't up to date, so we need to run it
-            rc, out, err = run_command(base_command, module,
-                                       check_rc=True)
+            rc, out, err = run_command(base_command, module, check_rc=True)
             changed = True
 
     # We don't report the return code, as if this module failed
@@ -221,6 +239,7 @@ def main():
         stdout=out,
         stderr=err,
         target=module.params['target'],
+        targets=module.params['targets'],
         params=module.params['params'],
         chdir=module.params['chdir'],
         file=module.params['file'],