I create an ugly Makefile, it worked beyond my expectations. When main.o is not built successfully, the executable is built every time I make. In my opinion, after the main.o target command is executed, make will compare the timestamp of the main.o file with the main file. There is no main.o file at this time, so the main file should be the latest. Why is the command of the main target executed. In my case main is always present after the first build and it is rebuilt each time make is executed, Although the content is the same.
When I add a main.o file that is older than main by shell, I change the main.c file and use the make command to update only main1.o, but not main, indicating that make compares main and main.o timestamp.
Is there a problem with my understanding? Is it my misunderstanding of the execution process of make.
main: main.o
gcc -o main1 main1.o
echo generate
main.o: main.c
gcc -c main.c -o main1.o
I don't have enough reputation so I've inserted an image link below
main
but the rule buildsmain1
. The image is different from your text but it has the targetmain.o
and the rule buildsmain1.o
. I don't see how you can ever get a clean build with this Makefile.