> For the complete documentation index, see [llms.txt](https://wong-coupon.gitbook.io/flutter/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wong-coupon.gitbook.io/flutter/easy-code/make.md).

# Make

When a Flutter project gets bigger, we need to run many terminal commands every day.

I use **Make** to group many commands into one short command.\
This saves time and also saves memory when working.

## What is Make?

**Make** is a tool that runs tasks from a file named `Makefile`.

Official links:

* [GNU Make](https://www.gnu.org/software/make/)
* [GNU Make Manual](https://www.gnu.org/software/make/manual/)

## Install Make

On macOS:

```bash
brew install make
```

## Add Make to a Flutter Project

### Step 1: Create `Makefile` in project root

```makefile
FVM := fvm
FVM_CACHE_PATH := $(CURDIR)/.fvm_cache
FVM_ENV := FVM_CACHE_PATH=$(FVM_CACHE_PATH) FLUTTER_SUPPRESS_ANALYTICS=true DART_SUPPRESS_ANALYTICS=true

.PHONY: init
init:
	@echo "Using FVM cache at $(FVM_CACHE_PATH)"
	$(FVM_ENV) $(FVM) install 3.27.4
	$(FVM_ENV) $(FVM) use 3.27.4 --force
	$(FVM_ENV) $(FVM) flutter pub get
```

### Step 2: Run

```bash
make init
```

Without Make, most people run it manually like this:

```bash
fvm install 3.27.4
fvm use 3.27.4 --force
fvm flutter pub get
```

With `make init`, we keep one short command and a fixed order.

This gives three big benefits:

* Less confusion when running setup.
* Easier to remember than many long commands.
* Easier to teach new teammates because everyone runs the same command.

## Real Examples from My Makefile

Below are examples I am using now.\
The important point: **many lines become one short command**.

### Example 1: Full setup for new teammate

Manual way:

```bash
fvm install 3.27.4
fvm use 3.27.4 --force
fvm flutter pub get
chmod -R 777 .githooks
chmod -R 777 scripts
git config core.ignorecase false
git config core.hooksPath .githooks
```

The Make target:

```makefile
setup-project:
	@echo "Setting up project with FVM 3.27.4 and git hooks"
	$(FVM_ENV) $(FVM) install 3.27.4
	$(FVM_ENV) $(FVM) use 3.27.4 --force
	$(FVM_ENV) $(FVM) flutter pub get
	chmod -R 777 .githooks
	chmod -R 777 scripts
	git config core.ignorecase false
	git config core.hooksPath .githooks
```

Make way:

```bash
make setup-project
```

Result: from 7 lines to 1 line, with fixed order and less confusion.

### Example 2: Get dependencies for many packages

Manual way (long and easy to miss one package):

```bash
cd packages/ancestor_cores/dart_core && fvm flutter pub get
cd packages/ancestor_cores/device_core && fvm flutter pub get
cd packages/ancestor_cores/fire_core && fvm flutter pub get
...
cd packages/zeus_ui_core && fvm flutter pub get
fvm flutter pub get
```

The Make target:

```makefile
get:
	@find ./packages/ancestor_cores/dart_core -name "pubspec.yaml" -execdir env $(FVM_ENV) $(FVM) flutter pub get \;
	@find ./packages/ancestor_cores/device_core -name "pubspec.yaml" -execdir env $(FVM_ENV) $(FVM) flutter pub get \;
	...
	@find ./packages/zeus_ui_core -name "pubspec.yaml" -execdir env $(FVM_ENV) $(FVM) flutter pub get \;
	@$(FVM_ENV) $(FVM) flutter pub get
```

Make way:

```bash
make get
```

Result: from many repeated lines to 1 line, easier to remember and teach.

### Example 3: Push flow

Manual way:

```bash
fvm flutter analyze
git add .
git commit -m "message"
git push
cd packages
git add .
git commit -m "message"
git push
```

The Make target groups analyze, commit, upstream check, and push flow.

Make way:

```bash
make push
```

Result: from many steps to 1 short target.

## Why Make Is Efficient

* Less typing every day.
* Less chance to forget steps.
* Easier for team members to run the same workflow.
* Easier to maintain command flow in one file.

## Conclusion

Make helps me reduce repeated terminal work in Flutter projects.\
It also reduces memory load: from remembering many long commands to remembering a few short targets.

> **Important:** With AI, you can freely create your own Make targets to fit your workflow.

[Buy Me a Coffee](https://buymeacoffee.com/ducmng12g) | [Support Me on Ko-fi](https://ko-fi.com/I2I81AEJG8)
