Recursive Make for Multi-Directory Projects

Coordinate multi-directory builds with phony targets and $(MAKE) recursion.

3|1|Updated Feb 8, 2026
One-click install
npx skills add https://github.com/therealbill/mynet --skill recursive-make-for-multi-directory-projects
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Recursive Make for Multi-Directory Projects
Source: https://github.com/therealbill/mynet/tree/main/gnu-make/skills/makefile-recursive-multi-directory
Command: npx skills add https://github.com/therealbill/mynet --skill recursive-make-for-multi-directory-projects

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Coordinating builds across multiple subdirectories in a Make-based project can be brittle when using shell loops, leading to serialized builds, hard-to-trace errors, and poor parallelism. This skill provides a structured approach to organizing per-subdirectory builds with phony targets and proper recursion.

Core Features & Use Cases

  • Phony targets for subdirectories: enables parallel builds with make -j and clear scheduling.
  • Proper recursion with $(MAKE): ensures flags like -t, -n, -q apply in sub-makes.
  • Dependency order & export options: allows declaring per-subdirectory dependencies and shared variables for consistent builds.
  • Guidance for common anti-patterns: explains why shell loops are problematic and provides the phony-target alternatives.
  • Use cases include multi-directory projects with frontend/backend/database, or scenarios with subdirectory-like subprojects.

Quick Start

Use phony targets for subdirectories and invoke $(MAKE) -C $@ in each target to enable parallel builds.

Frequently Asked Questions about Recursive Make for Multi-Directory Projects

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I parallelize a multi-directory Make build?

To parallelize a multi-directory Make build, replace shell loops with phony targets for each subdirectory and invoke $(MAKE) -C $@. This structure enables make -j to schedule and execute subdirectory builds concurrently.

Why should I use phony targets instead of shell loops for subdirectory builds?

Shell loops serialize multi-directory builds and cause hard-to-trace errors, whereas phony targets provide clear scheduling for parallel execution. Using phony targets allows make -j to properly manage dependencies and run subdirectory builds concurrently.

How do I pass variables and manage dependencies in recursive Make?

In recursive Make, manage dependencies by declaring per-subdirectory phony targets and ensure consistent variable propagation by exporting shared variables. This approach maintains build consistency across all sub-makes.

What is the benefit of using $(MAKE) for recursive subdirectory invocations?

Using $(MAKE) for recursive subdirectory invocations ensures that command-line flags like -t, -n, and -q apply correctly to sub-makes. It also guarantees proper parallel execution and environment variable inheritance.

Does this recursive Make approach work for projects with separate frontend and backend directories?

Yes, this recursive Make approach works for multi-directory projects with separate frontend and backend components. By declaring phony targets for each directory, you can coordinate consistent builds and manage dependencies across distinct subprojects.

What are common limitations or anti-patterns when building subdirectories with Make?

A major anti-pattern in building subdirectories with Make is using shell loops, which prevents parallel execution and obscures errors. To avoid these limitations, replace loops with phony targets and proper $(MAKE) recursion for robust builds.