-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
83 lines (62 loc) · 2.01 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Executables
TARGET = larasnake
T_TARGET = testAll
# Compiler
CC = gcc
# Compiling flags
CFLAGS = -Wall -I. `sdl-config --libs` -lSDL_image -lSDL_ttf -lSDL_mixer -g
# Linker
LINKER = gcc -o
# Linking flags
LFLAGS = -I. -lm `sdl-config --libs` -lSDL_image -lSDL_ttf -lSDL_mixer -g
# Project directories
SRCDIR = src
OBJDIR = build
BINDIR = bin
# Get files for tests compiling
T_DIR = tests
T_SOURCES := $(wildcard $(T_DIR)/*.c)
T_OBJECTS := $(T_SOURCES:$(T_DIR)/%.c=$(OBJDIR)/%.o)
# Get files to compile the project
SOURCES := $(wildcard $(SRCDIR)/*.c)
INCLUDES := $(wildcard $(SRCDIR)/*.h)
OBJECTS := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
# Get all objects without the main.o
OBJBASIC = $(filter-out build/main.o, $(OBJECTS))
# Shortcut to rm files
rm = rm -f
####################################################################
# Every compiling links availables
all: $(BINDIR)/$(TARGET)
test: $(BINDIR)/$(T_TARGET)
####################################################################
# Compiles the project
$(BINDIR)/$(TARGET): $(OBJECTS)
@test -d $(BINDIR) || mkdir -p $(BINDIR)
@$(LINKER) $@ $(OBJECTS) $(LFLAGS)
@echo "Linking complete!"
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
@test -d $(OBJDIR) || mkdir -p $(OBJDIR)
@$(CC) -c $< -o $@ $(CFLAGS)
@echo "Compiled "$<" successfully!"
#####################################################################
# Compiles the test
$(BINDIR)/$(T_TARGET): $(OBJBASIC) $(T_OBJECTS)
@test -d $(BINDIR) || mkdir -p $(BINDIR)
@$(LINKER) $@ $(OBJBASIC) $(T_OBJECTS) $(LFLAGS) -l cmocka
@echo "Linking complete!"
$(T_OBJECTS): $(OBJDIR)/%.o : $(T_DIR)/%.c
@test -d $() || mkdir -p $(OBJDIR)
@$(CC) -c $< -o $@ $(CFLAGS) -l cmocka
@echo "Compiled "$<" successfully!"
#####################################################################
# Allow to clean and remove
.PHONEY: clean
clean:
@$(rm) $(OBJDIR)/*.o
@echo "Cleanup complete!"
.PHONEY: remove
remove: clean
@$(rm) $(BINDIR)/$(TARGET)
@$(rm) $(BINDIR)/testAll
@echo "Executable removed!"