1.14. Makefile — With CFLAGS

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
TARGETS=greeting_en greeting_fr greeting_es

all: $(TARGETS)
CFLAGS := -Wall

$(TARGETS):
	@gcc main.c $@.c $(CFLAGS) -o $@

clean:
	-@rm $(TARGETS)

run:
	@$(foreach target,$(TARGETS), ./$(target);)

To compile that file with GCC, the command would be.

make all

To execute the binary generated from the source file, the command would be as shown below.

make run

If everything went fine, the output would be:

Hello World!
Bonjour le monde!
Hola Mundo!