Thread: Quick Makefile Question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    53
    So if prog.o is older than prog.c then it will compile the source with this makefile, else it will skip it ?

    Code:
    #Makefile
    #############
    
    default: clean compile
    
    compile: prog.cpp
                g++ -o prog prog.cpp
    
    clean:
                rm -f *.o prog a.out core*

  2. #2
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    Quote Originally Posted by cisokay
    So if prog.o is older than prog.c then it will compile the source with this makefile, else it will skip it ?

    Code:
    #Makefile
    #############
    
    default: clean compile
    
    compile: prog.cpp
                g++ -o prog prog.cpp
    
    clean:
                rm -f *.o prog a.out core*
    A simple make statement is like this:
    Code:
    target: dependancies
        command
    if any of the dependancies is newer than target, command is run. Note that the command must have a tab char before.

    Your make will always compile prog. You're stating that compile depends on prog.cpp. When that command is run no file named compile exists, so the command is always run, whenever make is run.
    Also you're not stating that prog depends on prog.cpp. re-read my previous post.

    and finally since I seriously doubt that there'll ever be any file called compile declare compile like this
    .PHONY compile
    In other words, compile will always be a word passed through the command line like clean
    To sum up we have
    Code:
    prog: prog.cpp
        g++ prog.cpp -o prog
    
    .PHONY clean compile
    
    compile: prog
    
    clean:
        rm -f *.o prog a.out core*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. quick question (adding characters)
    By Cactus in forum C Programming
    Replies: 2
    Last Post: 09-24-2005, 03:54 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM