27

I am running Ubuntu 10.04. Whenever I run make clean, I get this:

make: *** No rule to make target `clean'. Stop.

Here is my makefile:

CC = gcc
CFLAGS = -g -pedantic -O0 -std=gnu99 -m32 -Wall
PROGRAMS = digitreversal
all : $(PROGRAMS)
digitreversal : digitreversal.o
       $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
.PHONY: clean
clean:
       @rm -f $(PROGRAMS) *.o core

Any ideas why its not working?

EDIT: It seems like doing:

make -f Makefile.txt clean

works. Now: is there any setting to change so I don't have to do the -f Makefile.txt every time?

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
jasonbogd
  • 2,451
  • 4
  • 31
  • 42
  • 5
    Make sure you are using the right `makefile`. It may so happen that the above is named `Makefile` and you also have a `makefile` which does not have `clean` target and when you invoke `make clean`, make by defaults uses `makefile` and not `Makefile`. – codaddict Nov 15 '10 at 07:11
  • 4
    just rename your `Makefile.txt` to `Makefile` without an extension in the name. – Jens Gustedt Nov 15 '10 at 15:39
  • 2
    I had the same issue on my mac. For some reason the `MakeFile` was not found by the make command. renaming to `makefile` solved the problem. it is absurd though! – Foad S. Farimani Feb 13 '18 at 10:15

5 Answers5

26

It seems your makefile's name is not 'Makefile' or 'makefile'. In case it is different say 'abc' try running 'make -f abc clean'

TheBigAmbiguous
  • 303
  • 2
  • 4
  • 10
Siddique
  • 364
  • 2
  • 4
7

I suppose you have figured it out by now. The answer is hidden in your first mail itself.

The make command by default looks for makefile, Makefile, and GNUMakefile as the input file and you are having Makefile.txt in your folder. Just remove the file extension (.txt) and it should work.

sth
  • 222,467
  • 53
  • 283
  • 367
2

Check that the file is called GNUMakefile, makefile or Makefile.

If it is called anything else (and you don't want to rename it) then try:

make -f othermakefilename clean

Spaceghost
  • 6,835
  • 3
  • 28
  • 42
1

You have fallen victim to the most common of errors in Makefiles. You always need to put a Tab at the beginning of each command. You've put spaces before the $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) and @rm -f $(PROGRAMS) *.o core lines. If you replace them with a Tab, you'll be fine.

However, this error doesn't lead to a "No rule to make target ..." error. That probably means your issue lies beyond your Makefile. Have you checked this is the correct Makefile, as in the one you want to be specifying your commands? Try explicitly passing it as a parameter to make, make -f Makefile and let us know what happens.

Michael Foukarakis
  • 39,737
  • 6
  • 87
  • 123
1

This works for me. Are you sure you're indenting with tabs?

CC = gcc
CFLAGS = -g -pedantic -O0 -std=gnu99 -m32 -Wall
PROGRAMS = digitreversal
all : $(PROGRAMS)
digitreversal : digitreversal.o
    [tab]$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

.PHONY: clean
clean:
    [tab]@rm -f $(PROGRAMS) *.o core
Simone
  • 11,655
  • 1
  • 30
  • 43