"dj***@excite.it" wrote:
Someone can explain me what are makefiles useful for? Couldn't i write
shell script instead of makefiles? (*.sh in unix; *.cmd in win32)
Moreover i really doesn't understand what dependencies are useful
for? Except when i need to compile different files with different
compile options, i doesn't need to declare explicitly dependecies.
Infact the compiler already find dependecies looking for header files
included into the sources.
Can you explain me circumstances in which dependecies are useful?
In short:
Whenever your project consists of more then 1 source file. In practice
this means: always
Consider your project consists of 4 files:
a.cpp, b.cpp, c.cpp, inc.h
Now a.cpp includes inc.h, so does b.cpp
But c.cpp does not include inc.h
So whenever inc.h changes, what needs to be done?
a.cpp needs to be recompiled
b.cpp needs to be recompiled
but for c.cpp the linker can simply use the object
file generated in a previous compiler run for c.cpp. No
recompile is necessary, since nothing in inc.h can influence
anything in c.cpp
And that is the job of the makefile to describe this:
when inc.h changes, recompile a.cpp, b.cpp and link
the object files a.o, b.o, c.o to form the new, updated
final executable.
With shell scripts you don't get that flexibility to just recompile
what is needed to be compiled. You can only recompile everything.
And that can make a difference: Eg. I currently do a recompile of
everything in the program system I am involved in. The system consists
of roughly more then 1500 files with lots of dependencies. I started
the 'compile all' at 16:05. Current time is 18:16. The rebuild is
nearly through ......
--
Karl Heinz Buchegger
kb******@gascad.at