Opscraft
CI/CD & build tooling

Makefile

Must-know7 lessons · 25 min · 3 tests ·

make was built in 1976 to recompile C programs, and it's still everywhere because it solves a timeless problem: a named list of tasks, with dependencies between them, that only redoes work that's out of date. DevOps teams use a Makefile as the single front door to a repository — make test, make docker-build, make deploy ENV=staging — so the same commands work on a laptop, in Jenkins, and in GitHub Actions. Interviewers ask about it to see whether you understand dependency graphs, can debug the classic gotchas, and can design a clean developer interface.

Stage 2 · Core tools

Know these first

After this topic you can

  • Read and write Makefiles with targets and dependencies
  • Use make as a simple task runner for a project
  • Avoid common tab and variable pitfalls

Lessons

  1. 1How make thinks: targets, prerequisites, recipes 3 min read
    • The rule
    • The decision algorithm
    • Running make
  2. 2Phony targets: the DevOps reality 3 min read
    • Why .PHONY exists
    • Mixing real-file and phony targets
    • Order-only prerequisites
    • Diagnosing "always runs" vs "never runs"
  3. 3Variables in depth 5 min read
    • Defining and referencing
    • The assignment flavours
    • Where values come from, and precedence
    • Exporting to recipe shells
    • Automatic variables
    • Pattern rules
    • Useful functions
  4. 4How recipes execute 4 min read
    • One shell per line
    • Shell and error behaviour
    • Prefixes
    • $ in recipes
    • Recursive make
    • Parallel builds
    • include
  5. 5Designing a DevOps Makefile 4 min read
    • A production-quality example
    • Monorepos
  6. 6Make in CI and team workflows 3 min read
    • Same commands everywhere
    • "Works locally, fails in CI"
    • Windows developers
    • Alternatives
  7. 7Interview questions and model answers 3 min read
    • "Why does make test say 'up to date' and not run my tests?"
    • "What's the difference between = and :=?"
    • "Why doesn't cd work across recipe lines?"
    • "Parallel make -j breaks the build but serial works. Why?"
    • "How would you design a Makefile for a team's service?"
    • "Why use $(MAKE) instead of make in recipes?"
    • "Makefile or bash script?"