This is my Makefile:
# the issue seems to be the "." in the filename, since
# if NAME = test7 the desired result is achieved!
# although, when I check the [4.9 Special Built-in Target Names][1]
# section of the GNU make command, there is nothing mentioned
# about this?
NAME = .test7
$(NAME):
@echo Making $(NAME)...
@touch $(NAME)
@echo Done.
hello:
@echo Hello :\)
all: $(NAME)
@:
clean fclean:
rm -r $(NAME)
re: fclean all
@:
.PHONY: all clean fclean re
If I just simply run make for the 1st time, or any amount of times thereafter, the below output is shown:
Hello :)
Even thought the 1st rule is $(NAME), it is being ignored, because the value of it starts with a "." as in NAME = .test7 ?
Is this expected behaviour?
I have found the 4.9 Special Built-in Target Names section of the GNU make documentation and nothing is said about such?
If, however, I will have NAME = test7 (withouth the "." in the beginning), I will get the expected result, at 1st run:
Making .test7...
Done.
And after any other number of tries, just running make, the correct, output is shown as below:
make: '.test7' is up to date.
Any suggestions? To perhaps, fix this .test7 target to act like in the case of just NAME = test7 ?
THE SOLUTION TO THE ABOVE SEEMS TO BE:
Makefile:
NAME = .test7
.DEFAULT_GOAL := $(NAME)
$(NAME):
@echo Making $(NAME)...
@touch $(NAME)
@echo Done.
hello:
@echo Hello :\)
all: $(NAME)
clean fclean:
rm -r $(NAME)
re: fclean all
@:
.PHONY: all clean fclean re default_target
make by itself on the 1st run will output:
Making .test7...
Done.
While on subsequent runs will output:
make: '.test7' is up to date.
And make all will now output:
make: Nothing to be done for 'all'.
Thank you for all who have commented! :)
This is expected. See the manual:
By default, the goal is the first target in the makefile (not counting targets that start with a period).
(emphasis added).
You can specify a particular target using various methods as described in the manual.