1

I'm working through Learn C The Hard Way and in Ex2 Extra Credit they ask you to create an all: ex1 target that will build ex1 with just the command make.

This is the code I've created:

CFLAGS=-Wall -g

all: ex1

clean:
        rm -f ex1

It works.
When I run just make from the command line it makes the ex1 file. And when I run make clean it removes the file.

What I don't understand is why:

all: ex1

isn't:

all:
    make ex1

Where is it getting the make command from? The command line I guess, but then why does make clean run rm -f ex1 and not make rm -f ex1 and fail. It seems inconsistent to me. Can somebody explain what's going on?

Idos
  • 15,053
  • 14
  • 60
  • 75
LA Hattersley
  • 249
  • 3
  • 12

1 Answers1

3

The name all is not fixed, it's just a conventional name. all: target denotes that if you invoke it, make will build all what's needed to make a complete build.
So in essence, you could have written make ex1, but if you, lets say, had 100 files (ex1, ex2, ex3...) you wouldn't want to type 100 lines, right?

all is usually also a .PHONY target.

Community
  • 1
  • 1
Idos
  • 15,053
  • 14
  • 60
  • 75