1.16. Running Make multiple times — After editing a file

We expect that when we modify some .c, .h file, and we run the make file again, the make tool should re-compile required files. Let’s try to do the same. (But, we will fail in this part of the book. We have not set depdencies correctly yet.)

1.16.1. 1st Run

When we run Make for the first time, as below:

make all

The output would be as below:

gcc main.c greeting_en.c -Wall -o greeting_en
gcc main.c greeting_fr.c -Wall -o greeting_fr
gcc main.c greeting_es.c -Wall -o greeting_es

1.16.2. 2nd Run

Just touch few files.

touch greeting_en.c

Let’s compile again:

make all

The output would be something that we did not expect, no re-complation:

make: Nothing to be done for 'all'.

What happend? The target greeting_en exists, so make tool does not feel it needs to do something more.

 1TARGETS=greeting_en greeting_fr greeting_es
 2
 3all: $(TARGETS)
 4CFLAGS := -Wall
 5
 6$(TARGETS):
 7	gcc main.c $@.c $(CFLAGS) -o $@
 8
 9clean:
10	-@rm $(TARGETS)
11
12run:
13	$(foreach target,$(TARGETS), ./$(target);)