What are makefiles useful for?

D

djake

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?

Thanks
 
V

Victor Bazarov

Someone can explain me what are makefiles useful for? Couldn't i write
shell script instead of makefiles? (*.sh in unix; *.cmd in win32)

Makefiles are used to keep dependencies between different parts of the
project. You can do it all using shell script, of course.
Moreover i really doesn't understand what dependencies are useful
for?

They are useful if you don't want to keep track of what needs to be
rebuilt (recompiled/relinked/rearchived) when a file is updated. Also,
the importance of the dependencies is that they propagate.
Except when i need to compile different files with different
compile options, i doesn't need to declare explicitly dependecies.

Well, it's your right to think so.
Infact the compiler already find dependecies looking for header files
included into the sources.

Your compiler probably does. Many don't.
Can you explain me circumstances in which dependecies are useful?

See above.

One thing I have to mention, though. Your inquiry is OFF-TOPIC. Please
take the further discussion to comp.software-eng. Follow-ups set.

V
 
K

Karl Heinz Buchegger

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 ......
 
D

Default User

Someone can explain me what are makefiles useful for? Couldn't i write
shell script instead of makefiles? (*.sh in unix; *.cmd in win32)

That's because . . .
Moreover i really doesn't understand what dependencies are useful
for?


Do a bit of elementary research and stop posting off-topic stuff to
newsgroups.




Brian
 
E

E. Robert Tisdale

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?

I used Google

http://www.google.com/

to search for

+"make tutorial"

and I found lots of stuff.
 
C

Cristiano Sadun

(e-mail address removed) ([email protected]) wrote in
Someone can explain me what are makefiles useful for? Couldn't i write
shell script instead of makefiles? (*.sh in unix; *.cmd in win32)

Yes, but you'd end up writing the same script with different parameters
every time.

makefiles are just that script.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top