-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
99 lines (78 loc) · 2.59 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
TARGET =
CC = g++
CPPFLAGS = -std=c++20 -Wall -Wextra -pedantic
IFLAGS =
LDFLAGS = -lSDL2 -lSDL2_ttf
ASAN_FLAGS =
GCOV_FLAGS =
SRC_DIR = src
OBJ_DIR = obj
MKDIR_OBJ =
ifeq ($(OS), Windows_NT)
TARGET = PixUfo.exe
LDFLAGS += -lmingw32 -mwindows -lSDL2main
MKDIR_OBJ = if not exist $(OBJ_DIR) mkdir $(OBJ_DIR)
else ifeq ($(shell uname), Darwin)
TARGET = PixUfo
ASAN_FLAGS = -fsanitize=address -fsanitize=undefined \
-fsanitize-undefined-trap-on-error -fstack-protector-all
GCOV_FLAGS = -ftest-coverage -fprofile-arcs
# Output of sdl2-config --cflags.
IFLAGS += -I /opt/homebrew/include/SDL2 -D_THREAD_SAFE
LDFLAGS += -L /opt/homebrew/lib /opt/homebrew/lib/libSDL2.a -lm -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-weak_framework,CoreHaptics -Wl,-weak_framework,GameController -Wl,-framework,ForceFeedback -lobjc -Wl,-framework,CoreVideo -Wl,-framework,Cocoa -Wl,-framework,Carbon -Wl,-framework,IOKit -Wl,-weak_framework,QuartzCore -Wl,-weak_framework,Metal
MKDIR_OBJ = mkdir -p $(OBJ_DIR)
else ifeq ($(shell uname), Linux)
TARGET = PixUfo
GCOV_FLAGS = -ftest-coverage -fprofile-arcs
ASAN_FLAGS = -fsanitize=address -fsanitize=undefined -fsanitize=leak \
-fsanitize-undefined-trap-on-error -fstack-protector-all
MKDIR_OBJ = mkdir -p $(OBJ_DIR)
endif
# All in the ./obj depending on the ./src.
OBJS = $(patsubst $(SRC_DIR)/%.cc, $(OBJ_DIR)/%.o, \
$(wildcard $(SRC_DIR)/*.cc))
# Compilation of object files depends on source files wnich depends on headers.
# "$@" - alias to name on the left of ':', "$^" - on the right.
# "$<" is a first item in the dependencies list.
# "-c" generates the object file.
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cc $(SRC_DIR)/%.h
$(MKDIR_OBJ)
$(CC) -c -o $@ $< \
$(IFLAGS) \
$(CPPFLAGS)
@echo ' '
bundle_contents = PixUfo.app/Contents
# Builds the binary by linking object files.
$(TARGET): $(OBJS)
$(CC) -o $@ $^ \
$(CPPFLAGS) \
$(LDFLAGS)
.PHONY: bundle
bundle: CPPFLAGS += -DMACOS_BUNDLE
bundle: $(TARGET)
mkdir -p $(bundle_contents)/MacOS
mkdir -p $(bundle_contents)/Resources
cp Info.plist $(bundle_contents)/Info.plist
echo "APPL????" > $(bundle_contents)/PkgInfo
cp $(TARGET) $(bundle_contents)/MacOS/
cp -r "res" $(bundle_contents)/Resources/
# $(INSTALL_PROGRAM) $< $(bundle_contents)/MacOS/
.PHONY: debug
debug: CPPFLAGS += -DDEBUG $(GCOV_FLAGS)
debug: LDFLAGS += $(ASAN_FLAGS)
debug: $(TARGET)
.PHONY: lint
lint:
cpplint src/*
.PHONY: clean
ifeq ($(OS), Windows_NT)
clean:
del $(TARGET)
rmdir /S /Q $(OBJ_DIR)
else ifeq ($(shell uname), Darwin)
clean:
$(RM) -r $(TARGET) $(TARGET).app $(OBJ_DIR)
else
clean:
$(RM) -r $(TARGET) $(OBJ_DIR)
endif