Reputation: 51
I created a makefile and I want to know in which order the makefile will execute the commands. Is the there any method I can use to know?
fao: main.o high.o low.o utils.o
gcc -o foo main.o high.o low.a utils.o
main.o: main.c high.h utils.h
gcc -c -o main.o main.c high.h utils.h
high.o: high.c law.h utils.h
gcc -c -o high.o high.c low.h utils.h
low.o: law.c utils.h
gcc -c -o low.o low.c utlls.h
utils.o: utils.c utils.h
gcc -c -o utils.o utils.c utils.h
clean:
-rm -f fao main.o high.o low.o utils.o
I am trying to understand the behaviour of makefile. Tell me if I am right. If I have got all the *.c
files and the *.h
files but no *.o
files, in which order will the makefile execute the commands?
If, for example, I edit utils.h
and I execute make
again, what will happen then? And in which order will the make program execute the commands this time?
Upvotes: 0
Views: 350
Reputation: 50110
1 why do you care? Make will make in an order that obeys your dependencies
2 dont understand the question
3 if you edit utils.h all things dependent on utils.h will be remade. And then all things that depends on the remade things will be remade. In your case pretty much everything will be remade.
Note that you should not include .h files in the gcc command lines. ie this is wrong (and fix -o for you too)
gcc -c -0 main.o main.c high.h utils.h
should be just
gcc -c -o main.o main.c
You are also missing tab at the start of the gcc lines
If you want to see what make will do try make -n
and make -d
see https://linux.die.net/man/1/make
Upvotes: 2