This repository has been archived by the owner on Nov 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
82 lines (66 loc) · 1.75 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
# Nomes padrão dos executáveis.
game_bin = bow-and-arrow
editor_bin = editor
# Diretórios.
src_dir = src
include_dir = include
lib_dir = libs
obj_dir = obj
# Configurações globais.
CFLAGS += -I$(include_dir) -lm -std=c99
# Configurações exclusivas dos sistemas operacionais.
WINDOWS ?= 0
ifeq ($(WINDOWS), 0)
# Linux.
default_cc = c99
CFLAGS += -lncursesw -lX11
obj_dir := $(obj_dir)/linux
game_bin := $(game_bin)-linux
editor_bin := $(editor_bin)-linux
else
# Windows.
default_cc = x86_64-w64-mingw32-gcc
CFLAGS += -L.
CFLAGS += -lpdcurses
CFLAGS += -I$(lib_dir)
obj_dir := $(obj_dir)/windows
game_bin := $(game_bin)-windows.exe
editor_bin := $(editor_bin)-windows.exe
endif
# Arquivos individuais (do jogo.)
SOURCES = $(wildcard $(src_dir)/*.c)
HEADERS = $(wildcard $(include_dir)/*.h)
OBJS = $(patsubst $(src_dir)/%.c,$(obj_dir)/%.o,$(SOURCES))
# Configurações do alvo (debug, release.)
DEBUG ?= 0
RELEASE ?= 0
ifeq ($(DEBUG), 1)
CFLAGS += -ggdb -O0
else ifeq ($(RELEASE), 1)
CFLAGS += -D'NDEBUG' -g0 -O3
endif
# Usa os parâmetros padrão ou definidos pelo usuário.
ifeq ($(origin CC),default)
CC = $(default_cc)
endif
GAME ?= $(game_bin)
PAINT ?= $(editor_bin)
# Limpa e compila o jogo e o editor.
all: clean jogo editor
# Limpa.
clean:
find $(obj_dir) -type f -exec rm {} \;
rm -f $(GAME)
rm -f $(PAINT)
# Compila o jogo.
jogo: $(GAME)
$(GAME): $(OBJS)
$(CC) -o $@ $^ $(CFLAGS)
$(OBJS): $(obj_dir)/%.o: $(src_dir)/%.c $(HEADERS)
$(CC) -o $@ -c $< $(CFLAGS)
# Compila o editor.
editor: $(PAINT)
$(PAINT): $(obj_dir)/Editor.o $(obj_dir)/Grafico.o $(obj_dir)/TerminalIO.o $(obj_dir)/Timer.o
$(CC) -o $@ $^ $(CFLAGS)
$(obj_dir)/Editor.o: $(src_dir)/editor/Editor.c $(HEADERS)
$(CC) -o $@ -c $< $(CFLAGS)