0

I was walking through this tutorial, where I had to create this make file:

 CFLAGS=-wall  -g

 clean:
   rm  -f  ex1

When I type this command:

$ make clean

I get the following error:

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

I made sure that I'm using TABS. Why am I getting this error? How can I solve it?

Simplicity
  • 47,404
  • 98
  • 256
  • 385
  • What is the name of your _makefile_? – Sourav Ghosh Jul 29 '15 at 15:27
  • It is a TextEdit (on MAC OS X) file called "make" – Simplicity Jul 29 '15 at 15:30
  • 2
    I think you need then `make -f clean` – Sourav Ghosh Jul 29 '15 at 15:31
  • if you created your file with TextEdit, chances are that it saved with an extension. Have you removed the extension from the file? Also, nameless answer is pretty accurate as well. Follow the identation rules – gibertoni Jul 29 '15 at 15:35
  • 3
    Make sure you follow your tutorial, it says "Save this file as Makefile in your current directory. Make automatically assumes there's a file called Makefile and will just run it. " – nos Jul 29 '15 at 15:36
  • 1
    Don't use `make` as the filename. Use `Makefile` as the tutorial says. If you want to use a non-standard name then you need to use `make -f make` or whatever other name you chose. – Etan Reisner Jul 29 '15 at 15:38
  • Thanks for your replies. Took your replies into account, I now get the following error: "Makefile:4: *** missing separator. Stop." – Simplicity Jul 29 '15 at 15:38
  • **That** error is about spaces instead of tabs on the recipe lines. – Etan Reisner Jul 29 '15 at 15:40
  • 1
    Yes, I think it worked now. Thanks everyone for your kind replies. – Simplicity Jul 29 '15 at 15:42
  • @Simplicity any reason you never accepted an answer on this question: http://stackoverflow.com/questions/6939864/what-is-the-difference-between-section-and-div – basher Jul 29 '15 at 16:28

3 Answers3

1

The issue here, as indicated by a few comments on the post is that you named your file make instead of the traditional Makefile (or alternate names GNUMakefile and makefile that GNU make supports).

See What Name to Give Your Makefile in the GNU make manual.

If you want to use an alternate name (like make) then you need to tell make to use that file with the -f flag (also mentioned in that section of the manual).

make -f make

The missing separator error is caused by incorrect indentation in the makefile. Spaces instead of tabs on recipe lines, etc.

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
-1

I'm guessing your indentation is borked. Make is very, very specific in how files should be indented.

Your file should look like this:

CFLAGS=-wall -g

clean:
        rm -f ex1

Notice how clean is all the way left in the file (has no whitespace in front of it), and how there are two tabs (represented here by 8 spaces because I have no way of representing tabs on SO...)

basically, Make is an ancient program that has very, VERY particular rules as to how things are done. Be careful and follow the indent rules as closely as you possibly can.

nameless912
  • 367
  • 1
  • 12
  • No. Target names can have whitespace in front of them. The recipe lines can't though. They need *only* a tab (and only one tab though more is fine). And a tab *is* eight spaces. – Etan Reisner Jul 29 '15 at 15:35
  • For the TABS under "clean". I used two TABS before "rm", but still having the same issue. Thanks – Simplicity Jul 29 '15 at 15:35
-2

I was under the impression that targets should not have whitespace in front of them.

Also, Make treats the first target as the default target (what we traditionally call 'all'), so if 'clean' is your only target, it will get treated as the default.

Merchako
  • 789
  • 1
  • 8
  • 19
  • 2
    In my original code, I didn't have a space before the target. It seems the space showed in my question. I removed the space from the question. – Simplicity Jul 29 '15 at 15:33
  • No. Target names can have whitespace in front of them. The recipe lines can't though. They need *only* a tab. – Etan Reisner Jul 29 '15 at 15:35