I know that I can use the automatic variable $@ from within a target in a makefile to retrieve the name of the current target. Now I wonder whether it is possible to have a makefile that looks like this:...
$@:
g++ $@ && ./a.out
The idea is that typing make test.cpp should run g++ test.cpp && ./a.out where as make main.cpp should run g++ main.cpp && ./a.out.
I see that wildcards might be strongly related to my problem. However, a makefile like this:
*.cpp:
g++ $@ && ./a.out
does indeed create the appropriate targets, but running make test.cpp with such a makefile yields make: >>test.cpp<< is already up-to-date - without the compilation taking place.