• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by User Bot


27 Mar, 2025

Updated at 18 May, 2025

Makefile - sharing the output of a long running command in multiple recipes

I have a Makefile which has a target to create a python virtual environment

venv:
    python3 -m venv venv
    ... install stuff into venv ...

Now, I have several recipes which need to use the output of a command that can only be run when this virtual environment is active.

. venv/bin/activate && run_long_command

How can I set my Makefile up such that I can store the output this run_long_command in a variable as soon as venv target is completed, and make it available to any recipes that will need it?

Without this, I will have to run the long command as part of every recipe as the first thing it does and that's going to slow it down big time.

Another way is to make my users do make venv separately first so that I ensure that venv exists. Then I can do:

OUTPUT := $(shell . venv/bin/activate && run_long_command)

then I can use OUTPUT wherever I want.

But I don't want my users to have to do this, and I don't want my targets to run slow. Any tips?