1.19. Final source code for basic compilation

Finally, our source code for basic compilation looks like this. We will refer this in Basic build with CMake and Basic build with Premake

1.19.1. The Makefile

Makefile
 1TARGETS=greeting_en greeting_fr greeting_es
 2CDEPS=$(foreach target,$(TARGETS), $(target).d)
 3
 4all: $(TARGETS)
 5
 6$(TARGETS):%:%.o
 7
 8$(TARGETS): main.c Makefile
 9	gcc $< $@.o  $(CFLAGS) -o $@
10
11%.o: %.c Makefile
12	gcc -MMD -c -o $@ $< $(CFLAGS)
13
14clean:
15	-@rm $(TARGETS)
16	-@rm *.d *.o
17
18run:
19	$(foreach target,$(TARGETS), ./$(target);)
20
21-include $(CDEPS)
22
23.PHONY: all clean run

1.19.2. Common Header File

greeting.h
#ifndef GREETING_H
#define GREETING_H

void greeting(void);

#endif /* GREETING_H */

1.19.3. Source Files

greeting_es.c
#include <stdio.h>
#include "greeting.h"

void greeting() {
    printf ("Hola Mundo!\n");
}
greeting_en.c
#include <stdio.h>
#include "greeting.h"

void greeting() {
    printf ("Hello World!\n");
}
greeting_fr.c
#include <stdio.h>
#include "greeting.h"

void greeting() {
    printf ("Bonjour le monde!\n");
}