How to Dynamically Inject New Make Targets in Your CI Pipeline

May 27,2025

vlogize

2016-11-23T10:23:24Z

Learn how to inject new Make targets at runtime after cloning repositories in your CI setup, ensuring a smooth build process with dynamic target inclusion.
---
This video is based on the question https://stackoverflow.com/q/69124785/ asked by the user 'Alex Kuzmin' ( https://stackoverflow.com/u/16691082/ ) and on the answer https://stackoverflow.com/a/69137219/ provided by the user 'MadScientist' ( https://stackoverflow.com/u/939557/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions.

Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: How can I inject new Make targets in runtime after clonning a new repository?

Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/licensing
The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/by-sa/4.0/ ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/by-sa/4.0/ ) license.

If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com.
---
Injecting New Make Targets in Your CI Pipeline

Continuous Integration (CI) systems are essential for simplifying and automating the build process in software development. However, one common challenge developers face is how to inject new Make targets dynamically after cloning additional repositories. In this guide, we will explore this problem and provide you with a clear, structured solution.

Identifying the Problem

You have a CI setup where:

You start by checking out a repository (let's call it fooRepo) that contains a Makefile with several defined targets.

You then clone another repository (barRepo), which contains additional Makefiles with new targets that you want to run as part of your CI pipeline.

Your expected CI pipeline looks something like this:

[[See Video to Reveal this Text or Code Snippet]]

However, running this pipeline may lead to an error indicating that the newly cloned target (bar-init) isn’t found, even after attempting to include it using an includes.txt file.

Understanding the Solution

The Core Issue: Individual Make Invocation Contexts

Every time you run the make command, it creates a new setup context. Consequently, when you run two separate commands, such as make -f includes.txt followed by make bar-init, the context of the first command is not carried over to the second. This means that even if you've included the barRepo target, make won't remember it for the next command.

Recommended Solution: Single Invocation with Multiple Targets

Instead of running two separate commands, you can achieve your goal by combining them into a single invocation. Here’s how you can do that:

Create your includes.txt file correctly to include the new Makefile from barRepo. Your includes.txt should contain:

[[See Video to Reveal this Text or Code Snippet]]

Use a single command to run both the included targets and your desired target:

[[See Video to Reveal this Text or Code Snippet]]

By doing this, you ensure that make processes the includes and targets in one go, maintaining the context needed to execute bar-init successfully.

Revised CI Pipeline Example

Here’s how your revised CI pipeline should now look:

[[See Video to Reveal this Text or Code Snippet]]

Conclusion

Injecting new Make targets in real-time as part of your CI pipeline can seem tricky, but by understanding how make handles invocations and ensuring you run your commands in a single context, you can smoothly incorporate additional functionality into your builds.

Now, with this straightforward solution, you should be able to expand your Make capabilities dynamically as your projects grow!

By following the steps above, you can streamline your CI processes and make them more efficient. Happy coding!

How can I inject new Make targets in runtime after clonning a new repository?makefilegnu make