make -C (Directory) Command Reference
Build in another directory without a fragile cd in your pipeline.
make -C DIR changes into DIR before reading its Makefile. It is the clean way to drive a subproject build from a parent pipeline step.
What it does
make -C DIR is equivalent to cd DIR && make, but make handles the directory change itself and reports it in the log (Entering/Leaving directory). Multiple -C options are applied cumulatively.
Common flags and usage
- -C DIR: change to DIR before reading the Makefile
- Combine with a target: make -C build install
- Combine with -j: make -C src -j"$(nproc)"
- Common with generated build dirs (CMake/Ninja output)
Example
shell
- name: Build subproject
run: make -C services/api -j"$(nproc)" buildIn CI
Prefer make -C over a bare cd in a run step: it keeps the working directory of later steps intact and logs which directory each recipe ran in, which simplifies debugging multi-project pipelines.
Key takeaways
- make -C DIR runs make in DIR without changing the step working directory.
- It logs Entering/Leaving directory, aiding multi-project debugging.
- Combine with a target and -j for subproject parallel builds.
Related guides
make Command ReferenceReference for make in CI/CD: how make reads a Makefile, builds the default or a named target, and which envir…
make -j (Parallel Builds) Command ReferenceReference for make -j in CI/CD: run recipes in parallel, size jobs to runner cores and memory, and avoid the…
make Targets Command ReferenceReference for make targets in CI/CD: what a target is, how to run several in one invocation, and how to disco…