Thread: Make files

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    40

    Make files

    Hi,

    I am trying to build a make file then when we type make it cleans up all the object files and the .exe file and compile everytime even though I didnot modify anything. But mine doesnot work.

    Code:
    .
    PHONY :clean
    
     CC = gcc
    test: test.o
    	gcc test.o -o test
    	
    test.o:test.c
    	gcc -c test.c 
    
    	clean:
    	rm test.exe test.o

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    1.) Make sure there is no whitespace before CC = gcc and clean:.
    2.) I think it's .PHONY : clean

    Also, you'll need to type make clean (or make -f makefile_name clean if your makefile isn't named "Makefile") Note that makefile clean will only clean, not compile... usually you do:
    Code:
    $ make clean
    $ make
    If you're wanting to clean every time, perhaps a short script? Otherwise, I wouldn't know how, or why, since cleaning all the dependants each time sort of defeats the purpose of a makefile... it becomes a mindless batch file.

    Here's my hopefully correct version:
    Code:
    CC = gcc
    
    .PHONY : clean all
    all : test
    
    test: test.o
    	gcc test.o -o test
    	
    test.o: test.c
    	gcc -c test.c 
    
    clean:
    	rm test.exe test.o
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    There's a default rule that compiles .c files into .o files, so you don't need this:
    Code:
    test.o: test.c
    	gcc -c test.c
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Makefile producing a list of files.
    By leonm54 in forum Tech Board
    Replies: 1
    Last Post: 07-23-2007, 09:54 AM
  2. trying to make a KenGen ( for a game tool )
    By lonewolfy in forum C# Programming
    Replies: 4
    Last Post: 03-28-2007, 08:23 AM
  3. make variables visible on multiple files
    By jagerhans in forum C++ Programming
    Replies: 4
    Last Post: 08-28-2004, 06:32 PM
  4. "Cannot make pipe"
    By crepincdotcom in forum C Programming
    Replies: 5
    Last Post: 08-16-2004, 12:43 PM
  5. Help with Header/Make files
    By Unregistered in forum C Programming
    Replies: 0
    Last Post: 04-10-2002, 10:57 PM