Here is my simple Makefile:
#create an exe file
run: link
gcc link.o -o run
#sketch link.o
link.o: main.o sum.o
ld -r main.o sum.o -o link.o
#sketch main.o
main.o: main.c
gcc -c main.c -o main.o
#sketch sum.o
sum.o: sum.c
gcc -c sum.c -o sum.o
#make clean recipie
clean:
rm *.o
rm run
This makefile may be something kind of immature or weak one.But my real concern is all about the process the target are being hit. Before telling actual question, let's first look its output.
gcc -c main.c -o main.o
gcc -c sum.c -o sum.o
ld -r main.o sum.o -o link.o
cc link.o -o link
gcc link.o -o run
My question is: is this because of link the dependency of run or because of link.o mention in command section of run, make command seeks for link.o and again it is because of main.o sum.o the dependencies of link.o it looks for mention dependencies or because of main.o sum.o in command section and then first command in target main.o is encountered and sum.o and link.o respectively? Is it because of file mentioned in dependencies or file mention on the command??