Establishing 'make clean' with GNU make

This is a discussion on Establishing 'make clean' with GNU make within the C Programming forums, part of the General Programming Boards category; I've been reading up on how to get GNU make to 'make clean' no matter what, with no success. I ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    129

    Establishing 'make clean' with GNU make

    I've been reading up on how to get GNU make to 'make clean' no matter what, with no success. I have the following fragment in both makefiles:
    Code:
    .PHONY: clean FORCE
    clean: FORCE
    	rm *.o outliner
    FORCE:
    make still gives the following error when I try to use these rules:
    Code:
    make: *** No rule to make target `clean'.  Stop.
    Help, please?

    By the way, I'm only using this when I specify a different interface (CLI or GUI) to the bash wrapper. A different macro must be passed to GCC for all sources so everything must be recompiled whether it changed or not. (Well, not all sources depend on the macro but I'm not sure I should change the makefiles to only send it to some.) If there's any better way to do this, please do tell.

    Thanks!

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,058
    here's my 2c
    Code:
    .PHONY: clean
    clean:
    	rm *.o outliner
    Last edited by itCbitC; 04-10-2009 at 09:54 AM.

  3. #3
    Registered User
    Join Date
    Aug 2008
    Posts
    129
    There's no practical difference between the two snippets; I actually used that one first, then found another technique that might help. Obviously, it didn't...

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Either of the posted bits should work. Are you by any chance having spaces instead of a tab on the line after clean:?

    And I expect you do not have a file called clean?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,058
    Using a dependency "FORCE" adds more lookups and typing effort. Check if there is a file named "clean" in the directory from which you are invoking "make clean".

  6. #6
    Registered User
    Join Date
    Aug 2008
    Posts
    129
    Mats: No, that's a tab right before the rm command.

    itC: Nope, I don't have a 'clean' file.

    Here's the current makefile, in case it helps:
    Code:
    # Makefile
    CC = gcc `pkg-config --cflags --libs gtk+-2.0` -D INTERFACE=0
    CFLAGS = -ggdb -ansi -lm
    OBJECTS = main.o interface.o outline.o ../Jesdisciple/filesystem.o ../Jesdisciple/list.o ../Jesdisciple/toolkit.o
    
    .PHONY:	clean
    clean:
    	rm *.o outliner
    
    outliner: $(OBJECTS)
    	$(CC) -o $@ $^ $(CFLAGS)
    
    main.o: main.c interface.h
    
    interface.o: interface.c interface.h
    interface.h: outline.h
    
    outline.o: outline.c outline.h
    outline.h: ../Jesdisciple/filesystem.h
    
    include ../Jesdisciple/Makefile

  7. #7
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by matsp View Post
    Are you by any chance having spaces instead of a tab on the line after clean:?
    I've gotten stung this way before. If you use syntax highlighting in vim, it recognizes makefiles and uses lines to indicate the issue (must be tabs!)
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    I think the snippet in the OP's post has a tab in it, though, not spaces.

    By the way, I'm only using this when I specify a different interface (CLI or GUI) to the bash wrapper. A different macro must be passed to GCC for all sources so everything must be recompiled whether it changed or not. (Well, not all sources depend on the macro but I'm not sure I should change the makefiles to only send it to some.) If there's any better way to do this, please do tell.
    One thing I suppose you could do is to put the .o files for the CLI into a different directory from the .o files for the GUI. That way, if you switch to compiling another interface, you'll have to recompile everything; but if you then switch back again, you'll hardly have to compile anything.

    That's the best solution I can think of if you don't want to make only certain files get recompiled when the interface changes (which would also be a good solution, though perhaps harder to implement).

    Could you post your entire Makefile so that we can examine it?
    [edit] I see you did just that while I was typing up this post.

    This might sound like a stupid question, but do all of your Makefiles have clean targets? Perhaps the Makefile that you're actually executing with "make" doesn't have a clean target . . . . [/edit]
    Last edited by dwks; 04-10-2009 at 10:37 AM.
    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.

  9. #9
    Registered User
    Join Date
    Aug 2008
    Posts
    129
    dwk, that's a good idea... For the bash file, it's a good bit simpler than the file-I/O solution I'd come up with, but the makefiles are the other end of the trade-off. I posted the working makefile above, so here's the new one, moved to the CLI subdirectory... (The GUI makefile is identical except the final 0 on the first line is a 1.)
    Code:
    # Makefile
    CC = gcc `pkg-config gtk+-2.0 --cflags --libs` -D INTERFACE=0
    CFLAGS = -ggdb -ansi -lm
    OBJECTS = main.o interface.o outline.o ../../Jesdisciple/filesystem.o ../../Jesdisciple/list.o ../../Jesdisciple/toolkit.o
    
    .PHONY: clean
    clean:
    	rm *.o outliner
    
    outliner: $(OBJECTS)
    	$(CC) -o $@ $^ $(CFLAGS)
    
    main.o: ../main.c ../interface.h
    
    interface.o: ../interface.c ../interface.h
    ../interface.h: ../outline.h
    
    outline.o: ../outline.c ../outline.h
    ../outline.h: ../../Jesdisciple/filesystem.h
    
    include ../../Jesdisciple/Makefile
    Here are the resulting errors:
    Code:
    gcc `pkg-config gtk+-2.0 --cflags --libs` -D INTERFACE=0 -o outliner main.o interface.o outline.o ../../Jesdisciple/filesystem.o ../../Jesdisciple/list.o ../../Jesdisciple/toolkit.o -ggdb -ansi -lm
    gcc: main.o: No such file or directory
    gcc: interface.o: No such file or directory
    gcc: outline.o: No such file or directory
    make: *** [outliner] Error 1
    Last edited by Jesdisciple; 04-10-2009 at 11:09 AM.

  10. #10
    Registered User
    Join Date
    Aug 2008
    Posts
    129
    Since the makefiles are being so screwy, I just put the rm command directly in the bash wrapper so I don't need to 'make clean'. I wonder if this behavior is part of the decay of my Ubuntu. Ever since I updated via the repositories rather than a Live CD, it's been doing strange things.

    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Win32 Common Controls in C++, how do i make and use them?
    By C+noob in forum Windows Programming
    Replies: 6
    Last Post: 01-09-2006, 11:53 AM
  2. "Cannot make pipe"
    By crepincdotcom in forum C Programming
    Replies: 5
    Last Post: 08-16-2004, 01:43 PM
  3. 'functions' in make?
    By mart_man00 in forum C Programming
    Replies: 1
    Last Post: 06-21-2003, 03:16 PM
  4. make clean
    By Jaguar in forum Linux Programming
    Replies: 5
    Last Post: 12-27-2002, 06:44 PM
  5. BSD make and GNU make problem
    By Skarr in forum Linux Programming
    Replies: 4
    Last Post: 09-10-2002, 01:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21