What are makefiles useful for?

Discussion in 'C++' started by djake@excite.it, Nov 12, 2004.

  1. Guest

    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
     
    , Nov 12, 2004
    #1
    1. Advertising

  2. 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)


    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
     
    Victor Bazarov, Nov 12, 2004
    #2
    1. Advertising

  3. "" 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
     
    Karl Heinz Buchegger, Nov 12, 2004
    #3
  4. Default User Guest

    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)


    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
     
    Default User, Nov 12, 2004
    #4
  5. 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?


    I used Google

    http://www.google.com/

    to search for

    +"make tutorial"

    and I found lots of stuff.
     
    E. Robert Tisdale, Nov 12, 2004
    #5
  6. () wrote in
    news::

    > 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.
     
    Cristiano Sadun, Nov 15, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sasquatch

    Makefiles for JAVA

    sasquatch, Nov 8, 2003, in forum: Java
    Replies:
    5
    Views:
    767
    Dale King
    Nov 12, 2003
  2. Harris L

    Ant vs Makefiles

    Harris L, Nov 26, 2004, in forum: Java
    Replies:
    20
    Views:
    10,876
    Jacob
    Dec 2, 2004
  3. dharmesh Gupta

    Making of Makefiles

    dharmesh Gupta, Aug 26, 2003, in forum: C++
    Replies:
    2
    Views:
    355
    Kevin Goodsell
    Aug 26, 2003
  4. Janne Naukkarinen
    Replies:
    1
    Views:
    380
    Jack Klein
    Jan 15, 2004
  5. db
    Replies:
    2
    Views:
    453
Loading...

Share This Page