The case against Makefiles

You don’t need a Makefile. Whatever your use-case, there is a better tool.

Makefiles are archaic technology, living on by force of inertia and notalgia. The syntax is opaque and the error messages are unhelpful. It’s time to move on.

As far as I can see, there are two remaining use cases for Makefiles in the wild:

  • building C and C++ code;

  • running arbitrary tasks that have dependencies between each other.

Makefiles are no longer the best solution for either of these use cases,

Use-case 1: Building C and C++ code

Makefiles are the original build system. The make program was born in 1976 at Bell Labs, out of a frustration with existing build scripts (piles of sh). The concepts it pionneered (e.g. the build graph) are still the basis of modern build systems, but the ergonomics of build systems have improved a lot since then.

Aside: Build scripts, makefiles, and other build systems

Let’s step back into 1976, and write a build script for our program like they would have in the pioneer days.

#!/bin/sh

CFLAGS="-Wall"

# Compile the individual source files to object files
cc $CFLAGS -c -o main.o main.c
cc $CFLAGS -c -o lib.o lib.c

# Link the object files into an executable
cc -o app main.o lib.o

Forget to add a cc command to build a source file? Now you’re linking with an old version of the file that you compiled by hand.

Using modern bash features, we could improve the script quite a bit.

#!/bin/bash

CFLAGS="-Wall"
SRCS = "main.c lib.c"
OBJS = ${SRCS/.c/.o}

for file in $SRCS; do
    cc $CFLAGS -c -o ${file/.c/.o} $file
done

cc -o app $OBJS

Using a bash variable expansion to replace .c with .o allows us to use re-use the list of sources in both the compile commands and the linker command. For a small example program, this approach works, but it doesn’t scale well: we rebuild all the sources each time we run, regardless of whether they need to be rebuilt or not.

Enter Makefiles.

CFLAGS = -Wall
SRCS = main.c lib.c
OBJS = $(SRCS:.c=.o)

app: $(OBJS)
    $(CC) -o $@ $(OBJS)

%.o: %.c
    $(CC) $(CFLAGS) -c -o $@ $<

The similarities are quite obvious. The most significant difference between the script and the makfile is what they describe. The script is an imperative procedure: it lays out the steps that need to be accomplished to build the final binary, and executes them all in sequence, every time. The makefile describes the dependencies between inputs and outputs. This allows the makefile to skip steps that are redundant because the input has not changed.

The cost of this change is syntax. The build script is relatively easy to read but the makefile is full of magic tokens. What are $@, and $<? To an experienced practitioner, they are obvious. For me, they require a trip to google each time (or if I actually remember, a trip into The Sum of All Knowledge, my knowledgebase in Obsidian).

Compare this with an equivalent CMake script

cmake_minimum_required(VERSION 3.10)
project(app C)

add_executable(app main.c lib.c)

Or a meson.build file

project('simple', 'c')
executable('myexe', ['main.c', 'lib.c'])

Without knowing anything about CMake or meson, the goal of the scripts is quite clear. The knowledge of how to actually build an executable or a library is hidden which is a shame, but the intent is clear.

Make’s mistake

The fundamental mistake of Make is that it describes the edges of the build graph, not the nodes. It describes the operations required to transform one file into another, but never describes the goal of the transformation.

%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<

To build a file, we say that there exists a node %.c and a node %.o, and that to go from %.c to %.o, it is necessary to apply $(CC) $(CFLAGS) -c -o $@ $< to %.c. A no point does this say anything about what we are trying to achieve.

In CMake, to build an executable, we use add_executable(app main.c lib.c). This describes the end goal, not the transformation. This is not to say that CMake is the perfect build-system, far from that, but it is at least easier to follow.

Build-systems that describe intent, and not transformations, have one property that most Makefiles in the wild lack: they work reliably when run in parallel. Most makefiles I have had the misfortune of encountering fail when run in parallel. To build reliably, build scripts become

make -j$(nproc) all || make -j$(nproc) all || make -j$(nproc) all

This is definitely a skill issue. But expecting the average C programmer inside the average boring company to be able to write a functioning makefile is wildly optimistic. I barely trust them to write C code that compiles.

Re-inventing the wheel with make

Make aficionados love to tell new victims how great their makefiles are: they are invariably better than whatever sub-par build system they have begrudgingly accepted to use at their workplace.

However, if my experience is representative, their makefiles still suffer from the edges-not-nodes issue discussed above, but more problematically: they have accumulated just as much complexity as other build systems, whilst having written none of the documentation that would be required to explain their bespoke build system to others.

Need to add a new library target? Need to add a custom target for code-generation, doxygen, a formatter, a linter, … ? jump on a call and ask them to walk you though it.

And after all that, you still end up rm -rf build/ at every other build because you don’t trust the damn thing …

And because it doesn’t actually work when run in parallel, the compile times are agonising …

More Make vs CMake/Meson

For the sake of exposition, in the previous sections, I took some shortcuts which were amply dissected by commenters on reddit. I initially considered them completely orthogonal to the argument that I was making: that make is un-ergonomic, but enough readers complained that I feel the need to address them.

Implicit Rules in Makefiles

The make sample could be shortened by using the implicit rules that make ships with. Make knows how to compile a .c into .o, making that line entirely redundant. The list of implicit rules is so bewilderingly long, that it is often recommended to disable them.

I would argue that using the implicit rules makes the makefile harder to parse for the casual reader, junior developers or even interns discovering the build system for the first time, and the cost of including them is negligible.

Tracking header dependencies

The makefile does not track header dependencies. If a header included by the source files changes, the makefile will not rebuild the target. To track dependencies, the compiler needs to be instructed to write the dependencies of the source files to a file that make can include. It’s just a matter of adding -MMD -MP (or one of the many other pre-processor options) to the build command, and including the resulting dependency files.

Both CMake and Meson will do that automatically.

Tracking changes to the build script

If a build rule in the Makefile changes, the output will not be rebuilt. This often means that when iterating on a makefile, a full rebuild is required to test changes. CMake, when using ninja, or meson (which also uses ninja) avoid this problem because the ninja log tracks the build command used for each output in the dependency tree.

Other concerns

Makefiles start with a close-to-blank slate, and require you to implement your own solutions for problems that are tangential to the problem at hand. Want a makefile that can create directories on Linux and Windows, good luck! What about a cross-compiling build in which you first need to build a tool for the build machine? Or enabling sanitisers on the build? Or enabling coverage on the build?

These are all solvable problems, but I don’t want to have to solve them. I want a build system where these problems are already solved in a standard way, that will be clear to any newcomer to the project.

Use case 2: Running tasks

The concept of a dependency graph generalises well to many other problems, not just compiling code.

Using a makefile to express that the publish-docker rule depends on the build-docker rule seems natural. Sure you have to mark the rule .PHONY to tell make that the outputs are not actual files … but it works.

.PHONY: publish-docker
publish-docker: build-docker
    docker image push my-image:latest

.PHONY: build-docker
build-docker:
    docker image build -t my-image docker/my-image

Sure, it took you a couple of tries because you forgot to change your editor settings to use tabs for indentation instead of spaces, but it works.

We can parametrise it so that we can re-use the rule to build other images too.

.PHONY: publish-docker
publish-docker-foo: build-docker-bar
    $(MAKE) publish-docker IMAGE=foo

.PHONY: publish-docker-bar
publish-docker-bar: build-docker-foo
    $(MAKE) publish-docker IMAGE=bar

.PHONY: build-docker
build-docker-foo:
    $(MAKE) build-docker IMAGE=foo

.PHONY: build-docker-bar
build-docker-bar:
    $(MAKE) build-docker IMAGE=bar

build-docker:
    docker image build -t $(IMAGE) docker/$(IMAGE)

.PHONY: publish-docker
publish-docker: build-docker
    docker image push my-image:latest

And, if we add that self documenting makefile trick with sed, we even doc-comments for the makefile. Awesome!

And, if we add IMAGE ?= $(error IMAGE unset) to make sure that the IMAGE parameter is set, we get a reasonably good error message!

Make is inherently flexible, somebody out there will always have a solution to your problem. You just have to remember to copy them into every new project you do.

This is the problem with make. Out-of-the-box it does very little. It can evolve into an arbitrarily complex build system (e.g. the Linux kernel menuconfig), but doing that requires evolving it into a new dialect of make, different from any other dialect of make, and alien to anybody but the creator.

Alternatively, you could use a tool that has these features built-in, and documentation of those features. Something that doesn’t think in files, but in actual tasks.

My personal go-to is just. The equivalent justfile is

set default-list := true

# Build image foo
[group("Docker: foo")]
build-docker-foo: (_build-docker "my-foo-image")

# Publish image foo
[group("Docker: foo")]
publish-docker-foo: (_publish-docker "my-foo-image")

[group("Docker: bar")]
build-docker-bar: (_build-docker "my-bar-image")

[group("Docker: bar")]
publish-docker-bar: (_publish-docker "my-bar-image")

_publish-docker IMAGE_NAME:
    docker image push {{ IMAGE_NAME }}

_build-docker IMAGE_NAME:
    docker image build -t {{ IMAGE_NAME }} docker/{{ IMAGE_NAME }}

It’s marginally shorter, but it gives us a lot more out-of-the-box.

$ just
Available recipes:
[Docker: bar]
build-docker-bar
publish-docker-bar

[Docker: foo]
build-docker-foo   # Build image foo
publish-docker-foo # Publish image foo

Out-of-the-box we also get:

  • help output, listing all the rules (with their doc-comment), excluding private rules (starting with _);

  • grouping of rules in the help output;

  • checking of the arguments (calling _build-docker without IMAGE_NAME is an error);

And a plethora of other features that gradually come in handy.

It’s just a better tool. There are plenty of others out there that might fit your aesthetic better, just don’t use make for this.

Revision History

2026-11 Clarify 'the-case-against-makefiles' some more

Address some of the criticisms from posting to /r/programming on reddit [0].

[0]: https://www.reddit.com/r/programming/comments/1xl5irk/the_case_against_makefiles/

2026-11 Whitespace fixes (tabs to spaces)
2026-10 Clarify 'the-case-against-makefiles'

Try to clarify the argument in response to the _gentle_ critiques from the gentlemen of reddit [0].

https://www.reddit.com/r/cpp/comments/1xiz5ce/the_case_against_makefiles/

2026-10 Add 'the-case-against-makefiles'