devoured elysium
devoured elysium

Reputation: 105217

Trouble when trying to define a make file to delete a file

I've definde a makefile with the following contents:

mainmake: main.c
    gcc -o main main.c

clean:
    rm -f main

When running

make mainmake

it compiles main.c as expected with no problems, at all.

When I try to run

make clean

all I get is a

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

What might be the problem?

Upvotes: 0

Views: 111

Answers (2)

thiton
thiton

Reputation: 36059

The Makefile works fine for me with GNU make 3.81 when the tabs are right. While @gregj correctly suggested that clean should be phony, the phonyness of a target shouldn't influence its remaking when no file named "clean" exists.

I assume that you got some tabs wrong. Check that tabs (not 8 spaces!) are in front of the gcc and rm lines, and add an empty line at the end in case your editor is broken and doesn't insert a newline at the end of the file.

Upvotes: 0

Greg Jandl
Greg Jandl

Reputation: 850

Add the following before the definition of the 'clean' target:

.PHONY: clean

Upvotes: 1

Related Questions