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
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
TARGETS=greeting_en greeting_fr greeting_es
CDEPS=$(foreach target,$(TARGETS), $(target).d)

all: $(TARGETS)

$(TARGETS):%:%.o

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

%.o: %.c Makefile
	gcc -MMD -c -o $@ $< $(CFLAGS)

clean:
	-@rm $(TARGETS)
	-@rm *.d *.o

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

-include $(CDEPS)

.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");
}