0
votes

I have this makefile in a directory with a set of .cpp, each one representing a single program with some header-only dependences. All files are in the same directory.

To compile for example the program a, I do make a. The make's implicit rules will compile successfully a from a.cpp, but make must also remake the target when their header-only dependencies change.

However, once a program compiles, the following makefile doesn't rebuild anything if I do, for example, touch utils.hpp and then retry compilation. What's going on?

src := $(shell find . -maxdepth 1 -name "*.cpp")
exe := $(src:.cpp=)

# In case I want to build every program, w/o a cmd-line target.
all: $(exe)

%: utils.hpp test.hpp

My make version is GNU Make 4.1.

1

1 Answers

1
votes

Your last resort rule cannot be used to express the kind of dependencies you want. It is considered only if make needs to build something and knows no other rule to do it. Instead you should express this dependencies on your executable list:

$(exe): utils.hpp test.hpp