I am currently working through a c++ textbook; I'd like to have separate folders for exercises in the book, and a single makefile in the root, so that in the root directory I can type
make directoryName
and it will compile all the sources in that directory, and output a binary into the root. Here is what I have so far:
FLAGS= -Wall -Wextra -Wfloat-equal
OUT=helloworld.out
%: $(wildcard $@/*.cpp)
g++ $@/$(wildcard *.cpp) -o $(OUT) $(FLAGS)
But when I try to run it, all I get is
pc-157-231:Section2$ make helloWorld
make: `helloWorld' is up to date.
Any help appreciated
Edit Note; the problem is not that I haven't changed the target file; I did...
Your problem is that automatic GNU make variables such as $@
only have a value within the body of the rule. From GNU make documentation.
[Automatic variables] cannot be accessed directly within the prerequisite list of a rule. A common mistake is attempting to use
$@
within the prerequisites list; this will not work. (source)
Additonally, you do not need the $(wildcard ...)
function in your rule (both in body and in prerequisite list), although it's not a mistake either:
Wildcard expansion happens automatically in rules. (source)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With