-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
132 lines (113 loc) · 4.5 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
################################################################################
#| Project: RicoTech
#| Date: 2018-02-05
#| Author: Dan Bechard
################################################################################
# Directories
SRC_DIR := src
INC_DIR := src/chet src/dlb src/rico src/tools
OBJ_DIR := obj
LIB_DIR := lib
DLL_DIR := lib
BIN_DIR := bin
RES_DIR := res
SRC_FILES := chet/chet.c
#LIBS = -lmingw32 -lSDL2main -lSDL2 -lopengl32 -mwindows # Use this with MinGW libs
LIBS = -lSDL2main -lSDL2 -lopengl32 -lopenal32 # Use this with MSVC libs
LIB_DIRS := $(LIB_DIR:%=-L%)
LIBS := $(LIB_DIRS) $(LIBS)
BIN_EXE := $(BIN_DIR)/chet.exe
RES_SUBDIRS := audio font mesh packs shader texture
INCLUDE_DIRS := $(INC_DIR:%=-I%)
SOURCES := $(SRC_FILES:%=$(SRC_DIR)/%)
OBJECTS := $(subst $(SRC_DIR)/,$(OBJ_DIR)/,$(SOURCES:.c=.o))
DEPS := $(OBJECTS:.o=.d)
RESOURCE_DIRS := $(RES_SUBDIRS:%=$(BIN_DIR)/%)
RESOURCES := $(wildcard $(RES_DIR)/chunks/*.bin)
RESOURCES += $(wildcard $(RES_DIR)/font/*.bff)
RESOURCES += $(wildcard $(RES_DIR)/shader/*.glsl)
RESOURCES += $(wildcard $(RES_DIR)/mesh/*.obj)
RESOURCES += $(wildcard $(RES_DIR)/texture/*.tga)
RESOURCES += $(wildcard $(RES_DIR)/packs/*.pak)
RESOURCES += $(wildcard $(RES_DIR)/audio/*.ric)
BIN_RESOURCES := $(subst $(RES_DIR)/,$(BIN_DIR)/,$(RESOURCES))
DLLS := $(wildcard $(DLL_DIR)/*.dll)
BIN_DLLS := $(subst $(DLL_DIR)/,$(BIN_DIR)/,$(DLLS))
# Compiler & flags
# Optimization flags:
# -O0 Disabled
# -Og Debug
# -O2 Release
# -O3 Extreme (Careful, might make EXE bigger or invoke undefined behavior!)
SHARED_FLAGS = -std=c99 -g -MMD -O0 -Wall -Wextra -Werror -Wno-unused-function #-Wno-missing-field-initializers -Wno-missing-braces -Wno-deprecated-declarations #-Wno-error=incompatible-pointer-types
GCC_FLAGS = -fmax-errors=3
GCC_FLAGS_LINUX = -fsanitize=address -fno-omit-frame-pointer
CLANG_FLAGS = -ferror-limit=3 -fcolor-diagnostics -Wno-macro-redefined
CC = gcc #-v
CFLAGS = $(GCC_FLAGS) $(SHARED_FLAGS)
LDFLAGS = # None
default: prebuild build postbuild
prebuild:
$(info =========================================================)
$(info # ______ _______ _ #)
$(info # | __ \ O |__ __| | | #)
$(info # | |__| |_ ___ ___ | | ___ ___| |__ #)
$(info # | _ /| |/ __/ _ \ | |/ _ \/ __| `_ \ #)
${info # | | \ \| | |_| (_) || | __/ |__| | | | #}
$(info # |_| \_\_|\___\___/ |_|\___|\___|_| |_| #)
$(info # #)
$(info # Copyright 2018 Dan Bechard #)
$(info =========================================================)
compile-banner:
$(info )
$(info ---- Compile [build-compile] ---------------------------------------)
link-banner:
$(info )
$(info ---- Link [build-link] ---------------------------------------------)
copyres-banner:
$(info )
$(info ---- Copy resources [postbuild-copyres] ----------------------------)
build-compile: compile-banner
build-link: link-banner $(BIN_EXE)
build: make-build-dirs build-compile build-link
postbuild-copyres: copyres-banner $(BIN_DLLS)
postbuild: postbuild-copyres
################################################################################
# Link executable
$(BIN_EXE): $(OBJECTS)
$(info [EXE] $@)
$(foreach O,$^,$(info + [OBJ] ${O}))
@$(CC) -o $@ $^ $(LIBS)
# Compile C files into OBJ files and generate dependencies
$(OBJECTS): $(SOURCES)
$(info [OBJ] $@)
$(foreach S,$^,$(info + [SRC] ${S}))
@$(CC) $(CFLAGS) $(INCLUDE_DIRS) -o $@ -c $<
make-build-dirs:
@mkdir -p $(BIN_DIR) $(OBJ_DIR) $(OBJ_DIR)/chet
# Copy dlls
$(BIN_DIR)/%: $(DLL_DIR)/%
$(info [DLL] $^ -> $@)
@cp $^ $@
# Include generated dependency files
-include $(DEPS)
# Delete all generated files
.PHONY: clean
clean:
$(info )
$(info ---- Clean [clean] -------------------------------------------------)
$(info [DEL] $(BIN_EXE))
-@rm $(BIN_EXE)
$(info [DEL] $(OBJ_DIR)/*)
-@rm -r $(OBJ_DIR)/*
################################################################################
# Miscellaneous notes
################################################################################
#| $@ File name of target
#| $< Name of first prerequisite
#| $^ Name of all prerequisites, with spaces between them
#| $? Name of all prerequisites which have changed
#| % Wildcard, can be neighbored by prefix, suffix, or both
################################################################################
# Note: To use this, run e.g. `make print-SOURCES`
print-% : ; @echo $* = $($*)