qbai
qbai

Reputation: 123

what the following makefile means?

Here is Makefile as following, I want to ask what step1 and 2 will do seperately? thanks

DIRS = modules utils library

BUILDDIRS = $(DIRS:%=build-%)                           step1

all: $(BUILDDIRS)

$(BUILDDIRS):
        $(MAKE) -C $(@:build-%=%)                        step2

Upvotes: 1

Views: 73

Answers (1)

Kaz
Kaz

Reputation: 58627

This looks like a dispatching Makefile. Its job is to expose the build targets build-modules, build-utils and build-library. If it is not given any target, it builds the all target which depends on all of these. We can also think about, for instance, make build-utils being directly invoked.

Each build-<whatever> corresponds to a <whatever> dir without the build- prefix.

For instance to update the target build-utils, the action is to recursively invoke make with -C utils step2 as the arguments: change to the utils directory and look for a Makefile there, invoking its step2 target.

This Makefile has a flaw: the targets all and the build-<dir> targets are all phony, but there is no .PHONY: declaration for them. This means that make will probe the filesystem, looking for files named all, and build-modules, etc. If you create files with these names, such as by touch build-modules or touch all, the Makefile will then malfunction.

Upvotes: 1

Related Questions