How to Access Environment Variables in a Makefile

How can we access environment variables inside our Makefile?

Suppose this is our project structure.

📂 project
 ┣ 📜 Makefile
 ┗ 📜 .env

Unfortunately, Makefile doesn’t automatically have access to the root .env file, which might look something like this.

# .env

That said, we can include the appropriate environment file in our Makefile.

# Makefile
include .env

The environment variables are then accessible using the $(VAR_NAME) syntax.