> For the complete documentation index, see [llms.txt](https://notes.eliasnorrby.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.eliasnorrby.com/make/running-make-in-subdirectories.md).

# Running make in a set of subdirectories

```
.
├── Makefile
├── scripts
│   └── Makefile
└── tasks
    └── Makefile
```

All Makefiles have `all`, `test` and `lint` targets.

```
SUBDIRS = scripts tekton
TOPTARGETS = all lint test

$(TOPTARGETS): $(SUBDIRS)

$(SUBDIRS):
  $(MAKE) -C $@ $(MAKECMDGOALS)

.PHONY: $(SUBDIRS) $(TOPTARGETS)
```

`$@` is an automatic variable that contains the target name (one of `SUBDIRS` in this case).

Source: [stackoverflow](https://stackoverflow.com/a/17845120)
